From 08f348cadf473bd668d3e2f2f1d644e4cc0f1e18 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 19 Nov 2012 18:32:05 +0000 Subject: [PATCH] Core: Http now better suited for handling >2gb content git-svn-id: svn://ultimatepp.org/upp/trunk@5565 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Http.cpp | 14 ++++---------- uppsrc/Core/Inet.h | 5 ++--- uppsrc/Core/src.tpp/HttpRequest$en-us.tpp | 10 ++++++---- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/uppsrc/Core/Http.cpp b/uppsrc/Core/Http.cpp index 93ac6ff4e..e56864639 100644 --- a/uppsrc/Core/Http.cpp +++ b/uppsrc/Core/Http.cpp @@ -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; diff --git a/uppsrc/Core/Inet.h b/uppsrc/Core/Inet.h index bf305089c..9f460bdac 100644 --- a/uppsrc/Core/Inet.h +++ b/uppsrc/Core/Inet.h @@ -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; } diff --git a/uppsrc/Core/src.tpp/HttpRequest$en-us.tpp b/uppsrc/Core/src.tpp/HttpRequest$en-us.tpp index 41ae9cd48..7b14fc75f 100644 --- a/uppsrc/Core/src.tpp/HttpRequest$en-us.tpp +++ b/uppsrc/Core/src.tpp/HttpRequest$en-us.tpp @@ -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;%% ] \ No newline at end of file +[s3;%% ]] \ No newline at end of file