summaryrefslogtreecommitdiff
path: root/test/interactive-helper/aptwebserver.cc
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2012-07-10 12:26:15 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2012-07-10 12:26:15 +0200
commita38a00b981de3031a51e76c8a2e220b59557c469 (patch)
tree2c56ffb4d73439e6053f1d3f0f3e64a4645fa304 /test/interactive-helper/aptwebserver.cc
parentda3ebfe79d570c3aeb5f0a407cfec7996f44420c (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/aptwebserver.cc')
-rw-r--r--test/interactive-helper/aptwebserver.cc34
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;
}