]> git.saurik.com Git - apt.git/blobdiff - test/interactive-helper/aptwebserver.cc
test: Use a file to determine TEST_DEFAULT_GROUP
[apt.git] / test / interactive-helper / aptwebserver.cc
index 849323cc0960ab6ba22956ba2ebf3a5184edecef..950a17bc12557e917f4486fe000832e3fb20f0f4 100644 (file)
@@ -99,7 +99,7 @@ static void addFileHeaders(std::list<std::string> &headers, FileFd &data)/*{{{*/
    if (_config->FindB("aptwebserver::support::last-modified", true) == true)
    {
       std::string lastmodified("Last-Modified: ");
-      lastmodified.append(TimeRFC1123(data.ModificationTime()));
+      lastmodified.append(TimeRFC1123(data.ModificationTime(), false));
       headers.push_back(lastmodified);
    }
 }
@@ -122,13 +122,16 @@ static bool sendHead(int const client, int const httpcode, std::list<std::string
    _config->Set("APTWebserver::Last-Status-Code", httpcode);
 
    std::stringstream buffer;
+   auto const empties = _config->FindVector("aptwebserver::empty-response-header");
+   for (auto && e: empties)
+      buffer << e << ":" << std::endl;
    _config->Dump(buffer, "aptwebserver::response-header", "%t: %v%n", false);
    std::vector<std::string> addheaders = VectorizeString(buffer.str(), '\n');
    for (std::vector<std::string>::const_iterator h = addheaders.begin(); h != addheaders.end(); ++h)
       headers.push_back(*h);
 
    std::string date("Date: ");
-   date.append(TimeRFC1123(time(NULL)));
+   date.append(TimeRFC1123(time(NULL), false));
    headers.push_back(date);
 
    if (chunkedTransferEncoding(headers) == true)
@@ -209,8 +212,8 @@ static bool sendData(int const client, std::list<std::string> const &headers, st
 static void sendError(int const client, int const httpcode, std::string const &request,/*{{{*/
               bool const content, std::string const &error, std::list<std::string> &headers)
 {
-   std::string response("<html><head><title>");
-   response.append(httpcodeToStr(httpcode)).append("</title></head>");
+   std::string response("<!doctype html><html><head><title>");
+   response.append(httpcodeToStr(httpcode)).append("</title><meta charset=\"utf-8\" /></head>");
    response.append("<body><h1>").append(httpcodeToStr(httpcode)).append("</h1>");
    if (httpcode != 200)
       response.append("<p><em>Error</em>: ");
@@ -245,8 +248,8 @@ static void sendRedirect(int const client, int const httpcode, std::string const
                  std::string const &request, bool content)
 {
    std::list<std::string> headers;
-   std::string response("<html><head><title>");
-   response.append(httpcodeToStr(httpcode)).append("</title></head>");
+   std::string response("<!doctype html><html><head><title>");
+   response.append(httpcodeToStr(httpcode)).append("</title><meta charset=\"utf-8\" /></head>");
    response.append("<body><h1>").append(httpcodeToStr(httpcode)).append("</h1");
    response.append("<p>You should be redirected to <em>").append(uri).append("</em></p>");
    response.append("This page is a result of the request: <pre>");
@@ -332,7 +335,7 @@ static void sendDirectoryListing(int const client, std::string const &dir,/*{{{*
       return;
    }
 
-   listing << "<html><head><title>Index of " << dir << "</title>"
+   listing << "<!doctype html><html><head><title>Index of " << dir << "</title><meta charset=\"utf-8\" />"
           << "<style type=\"text/css\"><!-- td {padding: 0.02em 0.5em 0.02em 0.5em;}"
           << "tr:nth-child(even){background-color:#dfdfdf;}"
           << "h1, td:nth-child(3){text-align:center;}"
@@ -359,7 +362,7 @@ static void sendDirectoryListing(int const client, std::string const &dir,/*{{{*
                 << "<td><a href=\"" << namelist[i]->d_name << "\">" << namelist[i]->d_name << "</a></td>"
                 << "<td>" << SizeToStr(fs.st_size) << "B</td>";
       }
-      listing << "<td>" << TimeRFC1123(fs.st_mtime) << "</td></tr>" << std::endl;
+      listing << "<td>" << TimeRFC1123(fs.st_mtime, true) << "</td></tr>" << std::endl;
    }
    listing << "</table></body></html>" << std::endl;
 
@@ -652,7 +655,7 @@ static void * handleClient(void * voidclient)                               /*{{{*/
               redirect.erase(0,1);
            if (redirect != filename)
            {
-              sendRedirect(client, 301, redirect, *m, sendContent);
+              sendRedirect(client, _config->FindI("aptwebserver::redirect::httpcode", 301), redirect, *m, sendContent);
               continue;
            }
         }
@@ -714,6 +717,15 @@ static void * handleClient(void * voidclient)                              /*{{{*/
               condition.clear();
            if (condition.empty() == false && strncmp(condition.c_str(), "bytes=", 6) == 0)
            {
+              std::string ranges = ',' + _config->Find("aptwebserver::response-header::Accept-Ranges") + ',';
+              ranges.erase(std::remove(ranges.begin(), ranges.end(), ' '), ranges.end());
+              if (ranges.find(",bytes,") == std::string::npos)
+              {
+                 // we handle it as an error here because we are a test server - a real one should just ignore it
+                 sendError(client, 400, *m, sendContent, "Client does range requests we don't support", headers);
+                 continue;
+              }
+
               time_t cache;
               std::string ifrange;
               if (_config->FindB("aptwebserver::support::if-range", true) == true)
@@ -760,7 +772,7 @@ static void * handleClient(void * voidclient)                               /*{{{*/
                           headers.push_back(contentrange.str());
                        }
                        sendError(client, 416, *m, sendContent, "", headers);
-                       break;
+                       continue;
                     }
                  }
               }