+ int OnMessageComplete()
+ {
+ messagecomplete = true;
+ ServeData();
+ return 0;
+ }
+
+ public:
+ HttpServerSocket(int newfd, const std::string& IP, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server, unsigned int timeoutsec)
+ : BufferedSocket(newfd)
+ , Timer(timeoutsec)
+ , ip(IP)
+ , status_code(0)
+ , waitingcull(false)
+ , messagecomplete(false)
+ {
+ if ((!via->iohookprovs.empty()) && (via->iohookprovs.back()))
+ {
+ via->iohookprovs.back()->OnAccept(this, client, server);
+ // IOHook may have errored
+ if (!getError().empty())
+ {
+ AddToCull();
+ return;
+ }
+ }
+
+ parser.data = this;
+ http_parser_init(&parser, HTTP_REQUEST);
+ ServerInstance->Timers.AddTimer(this);
+ }
+
+ ~HttpServerSocket()
+ {
+ sockets.erase(this);
+ }
+
+ void OnError(BufferedSocketError) CXX11_OVERRIDE
+ {
+ AddToCull();
+ }
+
+ void SendHTTPError(unsigned int response)
+ {
+ HTTPHeaders empty;
+ std::string data = InspIRCd::Format(
+ "<html><head></head><body>Server error %u: %s<br>"
+ "<small>Powered by <a href='https://www.inspircd.org'>InspIRCd</a></small></body></html>", response, http_status_str((http_status)response));
+
+ Page(data, response, &empty);
+ }
+
+ void SendHeaders(unsigned long size, unsigned int response, HTTPHeaders &rheaders)
+ {
+ WriteData(InspIRCd::Format("HTTP/%u.%u %u %s\r\n", parser.http_major ? parser.http_major : 1, parser.http_major ? parser.http_minor : 1, response, http_status_str((http_status)response)));