diff options
author | Michael Vogt <michael.vogt@ubuntu.com> | 2012-07-10 12:26:15 +0200 |
---|---|---|
committer | Michael Vogt <michael.vogt@ubuntu.com> | 2012-07-10 12:26:15 +0200 |
commit | a38a00b981de3031a51e76c8a2e220b59557c469 (patch) | |
tree | 2c56ffb4d73439e6053f1d3f0f3e64a4645fa304 /test/interactive-helper | |
parent | da3ebfe79d570c3aeb5f0a407cfec7996f44420c (diff) |
always send content-length via the new addDataHeaders() to ensure w3m/curl are happy too for 404 pages and to comply with the http 1.1 spec
Diffstat (limited to 'test/interactive-helper')
-rw-r--r-- | test/interactive-helper/aptwebserver.cc | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/test/interactive-helper/aptwebserver.cc b/test/interactive-helper/aptwebserver.cc index c7b815925..ebe04d2a3 100644 --- a/test/interactive-helper/aptwebserver.cc +++ b/test/interactive-helper/aptwebserver.cc @@ -78,6 +78,13 @@ void addFileHeaders(std::list<std::string> &headers, FileFd &data) { /*{{{*/ lastmodified.append(TimeRFC1123(data.ModificationTime())); headers.push_back(lastmodified); } /*}}}*/ + +void addDataHeaders(std::list<std::string> &headers, std::string &data) {/*{{{*/ + std::ostringstream contentlength; + contentlength << "Content-Length: " << data.size(); + headers.push_back(contentlength.str()); +} /*}}}*/ + bool sendHead(int client, int httpcode, std::list<std::string> &headers) { /*{{{*/ string response("HTTP/1.1 "); response.append(httpcodeToStr(httpcode)); @@ -124,14 +131,16 @@ bool sendData(int client, std::string &data) { /*{{{*/ void sendError(int client, int httpcode, string request, bool content) { /*{{{*/ std::list<std::string> headers; + string response; + if (content == true) { + response.append("<html><head><title>"); + response.append(httpcodeToStr(httpcode)).append("</title></head>"); + response.append("<body><h1>").append(httpcodeToStr(httpcode)).append("</h1"); + response.append("This error is a result of the request: <pre>"); + response.append(request).append("</pre></body></html>"); + addDataHeaders(headers, response); + } sendHead(client, httpcode, headers); - if (content == false) - return; - string response("<html><head><title>"); - response.append(httpcodeToStr(httpcode)).append("</title></head>"); - response.append("<body><h1>").append(httpcodeToStr(httpcode)).append("</h1"); - response.append("This error is a result of the request: <pre>"); - response.append(request).append("</pre></body></html>"); sendData(client, response); } /*}}}*/ @@ -219,8 +228,9 @@ int main(int argc, const char *argv[]) string filename = m->substr(5, filestart - 5); if (simulate_broken_server == true) { + string data("ni ni ni\n"); + addDataHeaders(headers, data); sendHead(client, 200, headers); - string data("ni ni ni"); sendData(client, data); } else if (RealFileExists(filename) == false) @@ -244,11 +254,11 @@ int main(int argc, const char *argv[]) } _error->DumpErrors(std::cerr); messages.clear(); - - std::clog << "CLOSE client " << client - << " on socket " << sock << std::endl; - close(client); } + + std::clog << "CLOSE client " << client + << " on socket " << sock << std::endl; + close(client); } return 0; } |