Commit 1dd9e4dc authored by Davis King's avatar Davis King

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
parent 28c356d7
...@@ -90,6 +90,7 @@ namespace dlib ...@@ -90,6 +90,7 @@ namespace dlib
key_value_map cookies; key_value_map cookies;
key_value_map headers; key_value_map headers;
unsigned short http_return; unsigned short http_return;
std::string http_return_status;
}; };
...@@ -348,9 +349,14 @@ namespace dlib ...@@ -348,9 +349,14 @@ namespace dlib
my_fault = false; my_fault = false;
key_value_map& new_cookies = outgoing.cookies; key_value_map& new_cookies = outgoing.cookies;
key_value_map& response_headers = outgoing.headers; 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 // if there wasn't a problem with the input stream at some point
// then lets trigger this request callback. // then lets trigger this request callback.
std::string result; std::string result;
if (in) if (in)
result = on_request(incoming, outgoing); result = on_request(incoming, outgoing);
my_fault = true; my_fault = true;
...@@ -387,7 +393,7 @@ namespace dlib ...@@ -387,7 +393,7 @@ namespace dlib
response_headers["Content-Length"] = os.str(); 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 // Set any new headers
for( typename key_value_map::const_iterator ci = response_headers.begin(); ci != response_headers.end(); ++ci ) for( typename key_value_map::const_iterator ci = response_headers.begin(); ci != response_headers.end(); ++ci )
......
...@@ -112,6 +112,7 @@ namespace dlib ...@@ -112,6 +112,7 @@ namespace dlib
key_value_map cookies; key_value_map cookies;
key_value_map headers; key_value_map headers;
unsigned short http_return; unsigned short http_return;
std::string http_return_status;
}; };
private: private:
...@@ -151,6 +152,7 @@ namespace dlib ...@@ -151,6 +152,7 @@ namespace dlib
- outgoing.cookies.size() == 0 - outgoing.cookies.size() == 0
- outgoing.headers.size() == 0 - outgoing.headers.size() == 0
- outgoing.http_return == 200 - outgoing.http_return == 200
- outgoing.http_return_status == "OK"
ensures ensures
- This function returns the HTML page to be displayed as the response to this request. - This function returns the HTML page to be displayed as the response to this request.
- this function will not call clear() - this function will not call clear()
...@@ -160,7 +162,8 @@ namespace dlib ...@@ -160,7 +162,8 @@ namespace dlib
- #outgoing.headers == a set of additional headers you wish to appear in the - #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 HTTP response to this request. (This may be empty, the minimum needed headers
will be added automatically if you don't set them) 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 throws
- does not throw any exceptions - does not throw any exceptions
!*/ !*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment