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);
}
}
_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)
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>: ");
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>");
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;}"
<< "<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;
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;
}
}
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)
headers.push_back(contentrange.str());
}
sendError(client, 416, *m, sendContent, "", headers);
- break;
+ continue;
}
}
}