Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

httpserver.h
Go to the documentation of this file.
1 // Copyright (c) 2015 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_HTTPSERVER_H
6 #define BITCOIN_HTTPSERVER_H
7 
8 #include <string>
9 #include <stdint.h>
10 #include <functional>
11 
12 static const int DEFAULT_HTTP_THREADS=4;
13 static const int DEFAULT_HTTP_WORKQUEUE=16;
14 static const int DEFAULT_HTTP_SERVER_TIMEOUT=30;
15 
16 struct evhttp_request;
17 struct event_base;
18 class CService;
19 class HTTPRequest;
20 
24 bool InitHTTPServer();
29 bool StartHTTPServer();
31 void InterruptHTTPServer();
33 void StopHTTPServer();
34 
37 bool UpdateHTTPServerLogging(bool enable);
38 
40 typedef std::function<bool(HTTPRequest* req, const std::string &)> HTTPRequestHandler;
45 void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler);
47 void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch);
48 
52 struct event_base* EventBase();
53 
58 {
59 private:
60  struct evhttp_request* req;
61  bool replySent;
62 
63 public:
64  explicit HTTPRequest(struct evhttp_request* req);
65  ~HTTPRequest();
66 
69  GET,
73  };
74 
77  std::string GetURI();
78 
81  CService GetPeer();
82 
86 
91  std::pair<bool, std::string> GetHeader(const std::string& hdr);
92 
99  std::string ReadBody();
100 
106  void WriteHeader(const std::string& hdr, const std::string& value);
107 
116  void WriteReply(int nStatus, const std::string& strReply = "");
117 };
118 
122 {
123 public:
124  virtual void operator()() = 0;
125  virtual ~HTTPClosure() {}
126 };
127 
131 {
132 public:
137  HTTPEvent(struct event_base* base, bool deleteWhenTriggered, const std::function<void(void)>& handler);
138  ~HTTPEvent();
139 
143  void trigger(struct timeval* tv);
144 
146  std::function<void(void)> handler;
147 private:
148  struct event* ev;
149 };
150 
151 std::string urlDecode(const std::string &urlEncoded);
152 
153 #endif // BITCOIN_HTTPSERVER_H
bool(* handler)(HTTPRequest *req, const std::string &strReq)
Definition: rest.cpp:575
static const int DEFAULT_HTTP_SERVER_TIMEOUT
Definition: httpserver.h:14
HTTPRequest(struct evhttp_request *req)
Definition: httpserver.cpp:518
bool InitHTTPServer()
Initialize HTTP server.
Definition: httpserver.cpp:355
static const int DEFAULT_HTTP_WORKQUEUE
Definition: httpserver.h:13
std::pair< bool, std::string > GetHeader(const std::string &hdr)
Get the request header specified by hdr, or an empty string.
Definition: httpserver.cpp:532
Event class.
Definition: httpserver.h:130
const char * prefix
Definition: rest.cpp:574
std::string GetURI()
Get requested URI.
Definition: httpserver.cpp:619
struct evhttp_request * req
Definition: httpserver.h:60
void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
Unregister handler for prefix.
Definition: httpserver.cpp:651
void InterruptHTTPServer()
Interrupt HTTP server threads.
Definition: httpserver.cpp:443
RequestMethod GetRequestMethod()
Get request method.
Definition: httpserver.cpp:624
Event handler closure.
Definition: httpserver.h:121
struct event * ev
Definition: httpserver.h:148
void WriteReply(int nStatus, const std::string &strReply="")
Write HTTP reply.
Definition: httpserver.cpp:575
struct event_base * EventBase()
Return evhttp event base.
Definition: httpserver.cpp:487
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:143
virtual void operator()()=0
std::function< void(void)> handler
Definition: httpserver.h:146
CService GetPeer()
Get CService (address:ip) for the origin of the http request.
Definition: httpserver.cpp:605
void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
Register handler for prefix.
Definition: httpserver.cpp:645
virtual ~HTTPClosure()
Definition: httpserver.h:125
void WriteHeader(const std::string &hdr, const std::string &value)
Write output header.
Definition: httpserver.cpp:563
bool UpdateHTTPServerLogging(bool enable)
Change logging level for libevent.
Definition: httpserver.cpp:413
bool deleteWhenTriggered
Definition: httpserver.h:145
void trigger(struct timeval *tv)
Trigger the event.
Definition: httpserver.cpp:511
std::string urlDecode(const std::string &urlEncoded)
Definition: httpserver.cpp:665
HTTPEvent(struct event_base *base, bool deleteWhenTriggered, const std::function< void(void)> &handler)
Create a new event.
Definition: httpserver.cpp:501
std::function< bool(HTTPRequest *req, const std::string &)> HTTPRequestHandler
Handler for requests to a certain HTTP path.
Definition: httpserver.h:40
std::string ReadBody()
Read request body.
Definition: httpserver.cpp:543
bool StartHTTPServer()
Start HTTP server.
Definition: httpserver.cpp:430
In-flight HTTP request.
Definition: httpserver.h:57
void StopHTTPServer()
Stop HTTP server.
Definition: httpserver.cpp:454
bool replySent
Definition: httpserver.h:61
static const int DEFAULT_HTTP_THREADS
Definition: httpserver.h:12
Released under the MIT license