Core: Http now better suited for handling >2gb content

git-svn-id: svn://ultimatepp.org/upp/trunk@5565 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2012-11-19 18:32:05 +00:00
parent 9430b4d36c
commit 08f348cadf
3 changed files with 12 additions and 17 deletions

View file

@ -523,7 +523,7 @@ void HttpRequest::StartRequest()
bool HttpRequest::SendingData()
{
for(;;) {
int n = min(2048, data.GetLength() - count);
int n = min(2048, data.GetLength() - (int)count);
n = TcpSocket::Put(~data + count, n);
if(n == 0)
break;
@ -591,7 +591,7 @@ String HttpRequest::GetRedirectUrl()
return h;
}
int HttpRequest::GetContentLength()
int64 HttpRequest::GetContentLength()
{
int64 n = header.GetContentLength();
return n < INT_MAX ? (int)n : 0;
@ -616,9 +616,6 @@ void HttpRequest::StartBody()
count = GetContentLength();
if(count > 0)
body.Reserve(count);
if(method == METHOD_HEAD)
phase = FINISHED;
else
@ -629,7 +626,6 @@ void HttpRequest::StartBody()
else
StartPhase(BODY);
body.Clear();
bodylen = 0;
gzip = GetHeader("content-encoding") == "gzip";
if(gzip) {
gzip = true;
@ -648,14 +644,12 @@ void HttpRequest::Out(const void *ptr, int size)
LLOG("HTTP Out " << size);
if(z.IsError())
HttpError("gzip format error");
int64 l = bodylen + size;
if(l > max_content_size) {
if(body.GetCount() + size > max_content_size) {
HttpError("content length exceeded " + AsString(max_content_size));
phase = FAILED;
return;
}
WhenContent(ptr, size);
bodylen += size;
}
bool HttpRequest::ReadingBody()
@ -663,7 +657,7 @@ bool HttpRequest::ReadingBody()
LLOG("HTTP reading body " << count);
int n = chunk;
if(count > 0)
n = min(n, count);
n = (int)min((int64)n, count);
String s = TcpSocket::Get(n);
if(s.GetCount() == 0)
return !IsEof() && count;

View file

@ -295,7 +295,7 @@ private:
class HttpRequest : public TcpSocket {
int phase;
String data;
int count;
int64 count;
HttpHeader header;
@ -359,7 +359,6 @@ class HttpRequest : public TcpSocket {
int chunk;
IpAddrInfo addrinfo;
int bodylen;
bool gzip;
Zlib z;
@ -454,7 +453,7 @@ public:
String GetHeader(const char *id) { return header[id]; }
String operator[](const char *id) { return GetHeader(id); }
String GetRedirectUrl();
int GetContentLength();
int64 GetContentLength();
int GetStatusCode() const { return status_code; }
String GetReasonPhrase() const { return reason_phrase; }

View file

@ -45,8 +45,10 @@ xHeaderSize]([@(0.0.255) int]_[*@3 m])&]
[s4;%% &]
[s5;:HttpRequest`:`:MaxContentSize`(int`): [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* M
axContentSize]([@(0.0.255) int]_[*@3 m])&]
[s2;%% Specifies the maximum size of response content (default is
10000000). Returns `*this.&]
[s2;%% Specifies the maximum size of response content that can be
stored in HttpRequest to be retrieved by GetContent method (default
is 10000000). Note that this limit does no apply when content
data are processed using WhenContent callback. Returns `*this.&]
[s3;%% &]
[s4;%% &]
[s5;:HttpRequest`:`:MaxRedirect`(int`): [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* MaxR
@ -328,7 +330,7 @@ onst]_[@(0.0.255) char]_`*[*@3 id])&]
[s2;%% Returns processed Location field of HTTP response header.&]
[s3;%% &]
[s4;%% &]
[s5;:HttpRequest`:`:GetContentLength`(`): [@(0.0.255) int]_[* GetContentLength]()&]
[s5;:HttpRequest`:`:GetContentLength`(`): [@(0.0.255) int64]_[* GetContentLength]()&]
[s2;%% Returns the content length as specified in HTTP response header
or 0 if not specified or header not yet loaded.&]
[s3;%% &]
@ -421,4 +423,4 @@ har]_`*[*@3 url])&]
ool]_[*@3 b]_`=_[@(0.0.255) true])&]
[s2;%% Activates/deactivates global logging for HttpRequests (default
is not active).&]
[s3;%% ]
[s3;%% ]]