From 1dd9e4dcf43a62b7556ab7799e2c88899a25b50f Mon Sep 17 00:00:00 2001 From: Davis King Date: Mon, 13 Apr 2009 21:22:36 +0000 Subject: [PATCH] Added in Steven Van Ingelgem's patch to add an HTTP status string to the HTTP server. --HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402994 --- dlib/server/server_http_1.h | 10 ++++++++-- dlib/server/server_http_abstract.h | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/dlib/server/server_http_1.h b/dlib/server/server_http_1.h index c47885064..54f66ef7e 100644 --- a/dlib/server/server_http_1.h +++ b/dlib/server/server_http_1.h @@ -90,6 +90,7 @@ namespace dlib key_value_map cookies; key_value_map headers; unsigned short http_return; + std::string http_return_status; }; @@ -348,9 +349,14 @@ namespace dlib my_fault = false; key_value_map& new_cookies = outgoing.cookies; key_value_map& response_headers = outgoing.headers; + + // Set some defaults + outgoing.http_return = 200; + outgoing.http_return_status = "OK"; + // if there wasn't a problem with the input stream at some point // then lets trigger this request callback. - std::string result; + std::string result; if (in) result = on_request(incoming, outgoing); my_fault = true; @@ -387,7 +393,7 @@ namespace dlib response_headers["Content-Length"] = os.str(); } - out << "HTTP/1.0 " << outgoing.http_return << " OK\r\n"; + out << "HTTP/1.0 " << outgoing.http_return << " " << outgoing.http_return_status << "\r\n"; // Set any new headers for( typename key_value_map::const_iterator ci = response_headers.begin(); ci != response_headers.end(); ++ci ) diff --git a/dlib/server/server_http_abstract.h b/dlib/server/server_http_abstract.h index dbdf2a5c0..5b93ae734 100644 --- a/dlib/server/server_http_abstract.h +++ b/dlib/server/server_http_abstract.h @@ -112,6 +112,7 @@ namespace dlib key_value_map cookies; key_value_map headers; unsigned short http_return; + std::string http_return_status; }; private: @@ -151,6 +152,7 @@ namespace dlib - outgoing.cookies.size() == 0 - outgoing.headers.size() == 0 - outgoing.http_return == 200 + - outgoing.http_return_status == "OK" ensures - This function returns the HTML page to be displayed as the response to this request. - this function will not call clear() @@ -160,7 +162,8 @@ namespace dlib - #outgoing.headers == a set of additional headers you wish to appear in the HTTP response to this request. (This may be empty, the minimum needed headers will be added automatically if you don't set them) - - outgoing.http_return may be set to override the default HTTP return code of 200 + - outgoing.http_return and outgoing.http_return_status may be set to override the + default HTTP return code of 200 OK throws - does not throw any exceptions !*/