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

View file

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

View file

@ -45,8 +45,10 @@ xHeaderSize]([@(0.0.255) int]_[*@3 m])&]
[s4;%% &] [s4;%% &]
[s5;:HttpRequest`:`:MaxContentSize`(int`): [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* M [s5;:HttpRequest`:`:MaxContentSize`(int`): [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* M
axContentSize]([@(0.0.255) int]_[*@3 m])&] axContentSize]([@(0.0.255) int]_[*@3 m])&]
[s2;%% Specifies the maximum size of response content (default is [s2;%% Specifies the maximum size of response content that can be
10000000). Returns `*this.&] 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;%% &] [s3;%% &]
[s4;%% &] [s4;%% &]
[s5;:HttpRequest`:`:MaxRedirect`(int`): [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* MaxR [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.&] [s2;%% Returns processed Location field of HTTP response header.&]
[s3;%% &] [s3;%% &]
[s4;%% &] [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 [s2;%% Returns the content length as specified in HTTP response header
or 0 if not specified or header not yet loaded.&] or 0 if not specified or header not yet loaded.&]
[s3;%% &] [s3;%% &]
@ -421,4 +423,4 @@ har]_`*[*@3 url])&]
ool]_[*@3 b]_`=_[@(0.0.255) true])&] ool]_[*@3 b]_`=_[@(0.0.255) true])&]
[s2;%% Activates/deactivates global logging for HttpRequests (default [s2;%% Activates/deactivates global logging for HttpRequests (default
is not active).&] is not active).&]
[s3;%% ] [s3;%% ]]