diff options
author | Sadie Powell <sadie@witchery.services> | 2020-12-03 19:20:59 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2020-12-04 14:18:01 +0000 |
commit | 092f2b181848d4575f4317267866dade7312c542 (patch) | |
tree | 6a87e644887c813e40bfa565a3ba48c9ae62cddb | |
parent | fd8faa7e21994dee0a6d3d09abebb3004311408e (diff) |
Be more specific when a HTTP parser error happens.
-rw-r--r-- | src/modules/m_httpd.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp index 330e98c6a..b4e221e62 100644 --- a/src/modules/m_httpd.cpp +++ b/src/modules/m_httpd.cpp @@ -264,14 +264,14 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru Close(); } - void SendHTTPError(unsigned int response) + void SendHTTPError(unsigned int response, const char* errstr = NULL) { static HTTPHeaders empty; std::string data = InspIRCd::Format( "<html><head></head><body style='font-family: sans-serif; text-align: center'>" "<h1 style='font-size: 48pt'>Error %u</h1><h2 style='font-size: 24pt'>%s</h2><hr>" "<small>Powered by <a href='https://www.inspircd.org'>InspIRCd</a></small></body></html>", - response, http_status_str((http_status)response)); + response, errstr ? errstr : http_status_str((http_status)response)); Page(data, response, &empty); } @@ -303,8 +303,10 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru if (parser.upgrade || HTTP_PARSER_ERRNO(&parser)) return; http_parser_execute(&parser, &parser_settings, recvq.data(), recvq.size()); - if (parser.upgrade || HTTP_PARSER_ERRNO(&parser)) + if (parser.upgrade) SendHTTPError(status_code ? status_code : 400); + else if (HTTP_PARSER_ERRNO(&parser)) + SendHTTPError(status_code ? status_code : 400, http_errno_description((http_errno)parser.http_errno)); } void ServeData() |