Changeset View
Changeset View
Standalone View
Standalone View
src/httpserver.cpp
// 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. | ||||
#include "httpserver.h" | #include "httpserver.h" | ||||
#include "chainparamsbase.h" | #include "chainparamsbase.h" | ||||
#include "compat.h" | #include "compat.h" | ||||
#include "netbase.h" | #include "netbase.h" | ||||
#include "rpc/protocol.h" // For HTTP status codes | #include "rpc/protocol.h" // For HTTP status codes | ||||
#include "sync.h" | #include "sync.h" | ||||
#include "ui_interface.h" | #include "ui_interface.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include <cstdio> | |||||
#include <cstdlib> | |||||
#include <cstring> | |||||
#include <future> | |||||
#include <signal.h> | #include <signal.h> | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <event2/buffer.h> | #include <event2/buffer.h> | ||||
#include <event2/event.h> | #include <event2/event.h> | ||||
#include <event2/http.h> | #include <event2/http.h> | ||||
#include <event2/keyvalq_struct.h> | #include <event2/keyvalq_struct.h> | ||||
#include <event2/thread.h> | #include <event2/thread.h> | ||||
#include <event2/util.h> | #include <event2/util.h> | ||||
#ifdef EVENT__HAVE_NETINET_IN_H | #ifdef EVENT__HAVE_NETINET_IN_H | ||||
#include <netinet/in.h> | #include <netinet/in.h> | ||||
#ifdef _XOPEN_SOURCE_EXTENDED | #ifdef _XOPEN_SOURCE_EXTENDED | ||||
#include <arpa/inet.h> | #include <arpa/inet.h> | ||||
#endif | #endif | ||||
#endif | #endif | ||||
#include <cstdio> | |||||
#include <cstdlib> | |||||
#include <cstring> | |||||
#include <future> | |||||
/** Maximum size of http request (request line + headers) */ | /** Maximum size of http request (request line + headers) */ | ||||
static const size_t MAX_HEADERS_SIZE = 8192; | static const size_t MAX_HEADERS_SIZE = 8192; | ||||
/** HTTP request work item */ | /** HTTP request work item */ | ||||
class HTTPWorkItem : public HTTPClosure { | class HTTPWorkItem : public HTTPClosure { | ||||
public: | public: | ||||
HTTPWorkItem(Config &_config, std::unique_ptr<HTTPRequest> _req, | HTTPWorkItem(Config &_config, std::unique_ptr<HTTPRequest> _req, | ||||
const std::string &_path, const HTTPRequestHandler &_func) | const std::string &_path, const HTTPRequestHandler &_func) | ||||
: req(std::move(_req)), path(_path), func(_func), config(&_config) {} | : req(std::move(_req)), path(_path), func(_func), config(&_config) {} | ||||
void operator()() { func(*config, req.get(), path); } | void operator()() override { func(*config, req.get(), path); } | ||||
std::unique_ptr<HTTPRequest> req; | std::unique_ptr<HTTPRequest> req; | ||||
private: | private: | ||||
std::string path; | std::string path; | ||||
HTTPRequestHandler func; | HTTPRequestHandler func; | ||||
Config *config; | Config *config; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 604 Lines • Show Last 20 Lines |