Changeset View
Changeset View
Standalone View
Standalone View
src/httpserver.h
// Copyright (c) 2015-2016 The Bitcoin Core developers | // Copyright (c) 2015-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_HTTPSERVER_H | #ifndef BITCOIN_HTTPSERVER_H | ||||
#define BITCOIN_HTTPSERVER_H | #define BITCOIN_HTTPSERVER_H | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <functional> | #include <functional> | ||||
#include <string> | #include <string> | ||||
#include "rpc/server.h" | |||||
static const int DEFAULT_HTTP_THREADS = 4; | static const int DEFAULT_HTTP_THREADS = 4; | ||||
static const int DEFAULT_HTTP_WORKQUEUE = 16; | static const int DEFAULT_HTTP_WORKQUEUE = 16; | ||||
static const int DEFAULT_HTTP_SERVER_TIMEOUT = 30; | static const int DEFAULT_HTTP_SERVER_TIMEOUT = 30; | ||||
struct evhttp_request; | struct evhttp_request; | ||||
struct event_base; | struct event_base; | ||||
class Config; | class Config; | ||||
class CService; | class CService; | ||||
class HTTPRequest; | class HTTPRequest; | ||||
struct HTTPCallbackArgs { | struct HTTPCallbackArgs { | ||||
Config *config; | Config *config; | ||||
RPCServer *rpcServer; | |||||
HTTPCallbackArgs(Config *configIn) : config(configIn) {} | HTTPCallbackArgs(Config *configIn) : config(configIn) {} | ||||
}; | }; | ||||
/** | /** | ||||
* Initialize HTTP server. | * Initialize HTTP server. | ||||
* Call this before RegisterHTTPHandler or EventBase(). | * Call this before RegisterHTTPHandler or EventBase(). | ||||
*/ | */ | ||||
bool InitHTTPServer(Config &config, HTTPCallbackArgs &httpCallbackArgs); | bool InitHTTPServer(Config &config, HTTPCallbackArgs &httpCallbackArgs); | ||||
/** Start HTTP server. | /** Start HTTP server. | ||||
* This is separate from InitHTTPServer to give users race-condition-free time | * This is separate from InitHTTPServer to give users race-condition-free time | ||||
* to register their handlers between InitHTTPServer and StartHTTPServer. | * to register their handlers between InitHTTPServer and StartHTTPServer. | ||||
*/ | */ | ||||
bool StartHTTPServer(); | bool StartHTTPServer(); | ||||
/** Interrupt HTTP server threads */ | /** Interrupt HTTP server threads */ | ||||
void InterruptHTTPServer(); | void InterruptHTTPServer(); | ||||
/** Stop HTTP server */ | /** Stop HTTP server */ | ||||
void StopHTTPServer(); | void StopHTTPServer(); | ||||
/** Handler for requests to a certain HTTP path */ | /** Handler for requests to a certain HTTP path */ | ||||
typedef std::function<bool(Config &config, HTTPRequest *req, | typedef std::function<bool(Config &config, RPCServer &rpcServer, | ||||
const std::string &)> | HTTPRequest *req, const std::string &)> | ||||
HTTPRequestHandler; | HTTPRequestHandler; | ||||
/** Register handler for prefix. | /** Register handler for prefix. | ||||
* If multiple handlers match a prefix, the first-registered one will | * If multiple handlers match a prefix, the first-registered one will | ||||
* be invoked. | * be invoked. | ||||
*/ | */ | ||||
void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, | void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, | ||||
const HTTPRequestHandler &handler); | const HTTPRequestHandler &handler); | ||||
/** Unregister handler for prefix */ | /** Unregister handler for prefix */ | ||||
▲ Show 20 Lines • Show All 103 Lines • Show Last 20 Lines |