nttpd: allow sendfile() to cope with files >= 2GB; introduce range support

(This re-applies most of the patches I've reverted about two hours ago.)


Origin commit data
------------------
Commit: ff46970457
Author: martii <m4rtii@gmx.de>
Date: 2014-07-20 (Sun, 20 Jul 2014)
This commit is contained in:
martii
2014-07-20 19:00:16 +02:00
committed by [CST] Focus
parent 2c6a4d3885
commit d865e7d9a9
13 changed files with 92 additions and 50 deletions

View File

@@ -249,7 +249,7 @@ std::string CyhookHandler::BuildHeader(bool cache) {
}
// print Status-line
result = string_printf(HTTP_PROTOCOL " %d %s\r\nContent-Type: %s\r\n",httpStatus, responseString, ResponseMimeType.c_str());
log_level_printf(2, "Respose: HTTP/1.1 %d %s\r\nContent-Type: %s\r\n",
log_level_printf(2, "Response: HTTP/1.1 %d %s\r\nContent-Type: %s\r\n",
httpStatus, responseString, ResponseMimeType.c_str());
switch (httpStatus) {
@@ -287,15 +287,13 @@ std::string CyhookHandler::BuildHeader(bool cache) {
if(keep_alive)
result += "Connection: keep-alive\r\n";
else
result += "Connection: close\r\n";
#else
result += "Connection: close\r\n";
#endif
result += "Connection: close\r\n";
// gzipped ?
if (UrlData["fileext"] == "gz")
result += "Content-Encoding: gzip\r\n";
// content-len, last-modified
if (httpStatus == HTTP_NOT_MODIFIED || httpStatus == HTTP_NOT_FOUND)
if (httpStatus == HTTP_NOT_MODIFIED || httpStatus == HTTP_NOT_FOUND || httpStatus == HTTP_REQUEST_RANGE_NOT_SATISFIABLE)
result += "Content-Length: 0\r\n";
else if (GetContentLength() > 0) {
time_t mod_time = time(NULL);
@@ -303,9 +301,14 @@ std::string CyhookHandler::BuildHeader(bool cache) {
mod_time = LastModified;
strftime(timeStr, sizeof(timeStr), RFC1123FMT, gmtime(&mod_time));
result += string_printf(
"Last-Modified: %s\r\nContent-Length: %ld\r\n", timeStr,
GetContentLength());
result += string_printf("Last-Modified: %s\r\n", timeStr);
if (status == HANDLED_SENDFILE) {
result += string_printf("Accept-Ranges: bytes\r\n");
result += string_printf("Content-Length: %lld\r\n", RangeEnd - RangeStart + 1);
if (httpStatus == HTTP_PARTIAL_CONTENT)
result += string_printf("Content-Range: bytes %lld-%lld/%lld\r\n", RangeStart, RangeEnd, ContentLength);
} else
result += string_printf("Content-Length: %lld\r\n", GetContentLength());
}
result += "\r\n"; // End of Header
break;
@@ -320,6 +323,8 @@ std::string CyhookHandler::BuildHeader(bool cache) {
case HTTP_ACCEPTED:
case HTTP_NO_CONTENT:
case HTTP_NOT_FOUND:
case HTTP_PARTIAL_CONTENT:
case HTTP_REQUEST_RANGE_NOT_SATISFIABLE:
case HTTP_INTERNAL_SERVER_ERROR:
break;