Dash Core  0.12.2.1
P2P Digital Currency
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 <boost/thread.hpp>
11 #include <boost/scoped_ptr.hpp>
12 #include <boost/function.hpp>
13 
14 static const int DEFAULT_HTTP_THREADS=4;
15 static const int DEFAULT_HTTP_WORKQUEUE=16;
16 static const int DEFAULT_HTTP_SERVER_TIMEOUT=30;
17 
18 struct evhttp_request;
19 struct event_base;
20 class CService;
21 class HTTPRequest;
22 
26 bool InitHTTPServer();
31 bool StartHTTPServer();
33 void InterruptHTTPServer();
35 void StopHTTPServer();
36 
38 typedef boost::function<void(HTTPRequest* req, const std::string &)> HTTPRequestHandler;
43 void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler);
45 void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch);
46 
50 struct event_base* EventBase();
51 
56 {
57 private:
58  struct evhttp_request* req;
59  bool replySent;
60 
61 public:
62  HTTPRequest(struct evhttp_request* req);
63  ~HTTPRequest();
64 
67  GET,
71  };
72 
75  std::string GetURI();
76 
79  CService GetPeer();
80 
84 
89  std::pair<bool, std::string> GetHeader(const std::string& hdr);
90 
97  std::string ReadBody();
98 
104  void WriteHeader(const std::string& hdr, const std::string& value);
105 
114  void WriteReply(int nStatus, const std::string& strReply = "");
115 };
116 
120 {
121 public:
122  virtual void operator()() = 0;
123  virtual ~HTTPClosure() {}
124 };
125 
129 {
130 public:
135  HTTPEvent(struct event_base* base, bool deleteWhenTriggered, const boost::function<void(void)>& handler);
136  ~HTTPEvent();
137 
141  void trigger(struct timeval* tv);
142 
144  boost::function<void(void)> handler;
145 private:
146  struct event* ev;
147 };
148 
149 #endif // BITCOIN_HTTPSERVER_H
bool(* handler)(HTTPRequest *req, const std::string &strReq)
Definition: rest.cpp:601
static const int DEFAULT_HTTP_SERVER_TIMEOUT
Definition: httpserver.h:16
bool InitHTTPServer()
Definition: httpserver.cpp:384
virtual ~HTTPClosure()
Definition: httpserver.h:123
static const int DEFAULT_HTTP_WORKQUEUE
Definition: httpserver.h:15
struct event_base * base
Definition: torcontrol.cpp:659
bool replySent
Definition: httpserver.h:59
HTTPEvent(struct event_base *base, bool deleteWhenTriggered, const boost::function< void(void)> &handler)
Definition: httpserver.cpp:537
const char * prefix
Definition: rest.cpp:600
std::string ReadBody()
Definition: httpserver.cpp:579
std::string GetURI()
Definition: httpserver.cpp:639
void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
Definition: httpserver.cpp:671
void trigger(struct timeval *tv)
Definition: httpserver.cpp:547
void InterruptHTTPServer()
Definition: httpserver.cpp:465
struct event_base * EventBase()
Definition: httpserver.cpp:523
void WriteReply(int nStatus, const std::string &strReply="")
Definition: httpserver.cpp:611
struct event * ev
Definition: httpserver.h:146
boost::function< void(void)> handler
Definition: httpserver.h:144
virtual void operator()()=0
std::pair< bool, std::string > GetHeader(const std::string &hdr)
Definition: httpserver.cpp:568
HTTPRequest(struct evhttp_request *req)
Definition: httpserver.cpp:554
void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
Definition: httpserver.cpp:665
CService GetPeer()
Definition: httpserver.cpp:625
RequestMethod GetRequestMethod()
Definition: httpserver.cpp:644
struct evhttp_request * req
Definition: httpserver.h:58
void WriteHeader(const std::string &hdr, const std::string &value)
Definition: httpserver.cpp:599
bool StartHTTPServer()
Definition: httpserver.cpp:453
void StopHTTPServer()
Definition: httpserver.cpp:480
boost::function< void(HTTPRequest *req, const std::string &)> HTTPRequestHandler
Definition: httpserver.h:38
bool deleteWhenTriggered
Definition: httpserver.h:143
static const int DEFAULT_HTTP_THREADS
Definition: httpserver.h:14