From: Michael Vogt <michael.vogt@ubuntu.com>
Date: Tue, 10 Jul 2012 10:26:15 +0000 (+0200)
Subject: always send content-length via the new addDataHeaders() to ensure w3m/curl are happy... 
X-Git-Tag: 0.9.13.exp1ubuntu1~51^2~5
X-Git-Url: https://git.saurik.com/apt.git/commitdiff_plain/a38a00b981de3031a51e76c8a2e220b59557c469

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
---

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;
 }