From 4556bd63521947ff4acbe53809e3865cd7c4eb3d Mon Sep 17 00:00:00 2001 From: cxl Date: Wed, 25 May 2016 16:29:27 +0000 Subject: [PATCH] Core: HTTP chunked transfer fixed git-svn-id: svn://ultimatepp.org/upp/trunk@9880 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Http.cpp | 26 +++++++++++++++++++++++++- uppsrc/Core/Inet.h | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/uppsrc/Core/Http.cpp b/uppsrc/Core/Http.cpp index bf4b5b4a8..9e4a7a75c 100644 --- a/uppsrc/Core/Http.cpp +++ b/uppsrc/Core/Http.cpp @@ -65,6 +65,7 @@ void HttpRequest::Init() poststream = NULL; postlen = Null; has_content_length = false; + chunked_encoding = false; } HttpRequest::HttpRequest() @@ -738,6 +739,7 @@ void HttpRequest::StartBody() else if(header["transfer-encoding"] == "chunked") { count = 0; + chunked_encoding = true; StartPhase(CHUNK_HEADER); } else @@ -769,10 +771,12 @@ void HttpRequest::Out(const void *ptr, int size) WhenContent(ptr, size); } + bool HttpRequest::ReadingBody() { LLOG("HTTP reading body " << count); - String s = TcpSocket::Get(has_content_length ? (int)min((int64)chunk, count) : chunk); + String s = TcpSocket::Get(has_content_length || chunked_encoding ? (int)min((int64)chunk, count) + : chunk); if(s.GetCount()) { #ifndef ENDZIP if(gzip) @@ -787,6 +791,26 @@ bool HttpRequest::ReadingBody() } return !IsEof(); } +/* +bool HttpRequest::ReadingBody() +{ + LLOG("HTTP reading body " << count); + String s = TcpSocket::Get((int)min((int64)chunk, count)); + if(s.GetCount() == 0) + return !IsEof() && count; +#ifndef ENDZIP + if(gzip) + z.Put(~s, s.GetCount()); + else +#endif + Out(~s, s.GetCount()); + if(count > 0) { + count -= s.GetCount(); + return !IsEof() && count > 0; + } + return !IsEof(); +} +*/ void HttpRequest::CopyCookies() { diff --git a/uppsrc/Core/Inet.h b/uppsrc/Core/Inet.h index f4eb714ef..56d0ab609 100644 --- a/uppsrc/Core/Inet.h +++ b/uppsrc/Core/Inet.h @@ -353,6 +353,7 @@ class HttpRequest : public TcpSocket { String error; String body; bool has_content_length; + bool chunked_encoding; enum { DEFAULT_HTTP_PORT = 80,