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

@@ -47,6 +47,7 @@
//=============================================================================
#ifndef __yhttpd_yhook_h__
#define __yhttpd_yhook_h__
#include <unistd.h>
// C++
#include <string>
#include <list>
@@ -128,7 +129,9 @@ public:
HttpResponseType httpStatus; // http-status code for response
std::string ResponseMimeType; // mime-type for response
std::string NewURL; // new URL for Redirection
long ContentLength; // Length of Response Body
off_t ContentLength; // Length of Response Body
off_t RangeStart; // Start of range, used for sendfile only
off_t RangeEnd; // End of range, used for sendfile only
time_t LastModified; // Last Modified Time of Item to send / -1 dynamic content
std::string Sendfile; // Path & Name (local os style) of file to send
bool keep_alive;
@@ -141,7 +144,7 @@ public:
CStringList HookVarList; // Variables in Hook-Handling passing to other Hooks
THttp_Method Method; // HTTP Method (requested)
// constructor & deconstructor
CyhookHandler(){ContentLength = 0; keep_alive = 0; _outIndent = 0;status = HANDLED_NONE;Method = M_UNKNOWN;httpStatus = HTTP_NIL;outType = plain;};
CyhookHandler(){ContentLength = 0; RangeStart = 0; RangeEnd = -1; keep_alive = 0; _outIndent = 0;status = HANDLED_NONE;Method = M_UNKNOWN;httpStatus = HTTP_NIL;outType = plain;};
virtual ~CyhookHandler(){};
// hook slot handler
@@ -173,8 +176,8 @@ public:
void SetError(HttpResponseType responseType, THandleStatus _status)
{SetError(responseType); status = _status;}
// others
long GetContentLength()
{return (status==HANDLED_SENDFILE)?ContentLength : (long)yresult.length();}
off_t GetContentLength()
{return (status==HANDLED_SENDFILE)?ContentLength : (off_t)yresult.length();}
// output methods
std::string BuildHeader(bool cache = false);
void addResult(const std::string& result) {yresult += result;}