From 1209bc5fd95fa4bd85abf43c4dcca2f841fb471f Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 20 Dec 2013 18:04:22 +0000 Subject: [PATCH] Core: Inet gzip header in reply support, Zlib fixed to support zero length git-svn-id: svn://ultimatepp.org/upp/trunk@6687 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Inet.h | 2 +- uppsrc/Core/InetUtil.cpp | 5 ++++- uppsrc/Core/src.tpp/Inet$en-us.tpp | 9 ++++++--- uppsrc/Core/z.cpp | 2 ++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/uppsrc/Core/Inet.h b/uppsrc/Core/Inet.h index 28580b8c5..f891df39c 100644 --- a/uppsrc/Core/Inet.h +++ b/uppsrc/Core/Inet.h @@ -520,4 +520,4 @@ public: bool HttpResponse(TcpSocket& socket, bool scgi, int code, const char *phrase, const char *content_type = NULL, const String& data = Null, - const char *server = NULL); + const char *server = NULL, bool gzip = false); diff --git a/uppsrc/Core/InetUtil.cpp b/uppsrc/Core/InetUtil.cpp index 06bec271e..64cdd1597 100644 --- a/uppsrc/Core/InetUtil.cpp +++ b/uppsrc/Core/InetUtil.cpp @@ -459,7 +459,8 @@ bool HttpHeader::Response(String& protocol, int& code, String& reason) const } bool HttpResponse(TcpSocket& socket, bool scgi, int code, const char *phrase, - const char *content_type, const String& data, const char *server) + const char *content_type, const String& data, const char *server, + bool gzip) { String r; r << (scgi ? "Status: " : "HTTP/1.1 ") << code << ' ' << phrase << "\r\n" @@ -470,6 +471,8 @@ bool HttpResponse(TcpSocket& socket, bool scgi, int code, const char *phrase, r << "Content-Length: " << data.GetCount() << "\r\n"; if(content_type) r << "Content-Type: " << content_type << "\r\n"; + if(gzip) + r << "Content-Encoding: gzip\r\n"; r << "\r\n"; if(!socket.PutAll(r)) return false; diff --git a/uppsrc/Core/src.tpp/Inet$en-us.tpp b/uppsrc/Core/src.tpp/Inet$en-us.tpp index d5cb1bfce..8b0cbaf91 100644 --- a/uppsrc/Core/src.tpp/Inet$en-us.tpp +++ b/uppsrc/Core/src.tpp/Inet$en-us.tpp @@ -71,12 +71,13 @@ r]_`*[*@3 s])&] < 31 as html entities and escapes character 31 as `"` `".&] [s3;%% &] [s4; &] -[s5;:HttpResponse`(TcpSocket`&`,bool`,int`,const char`*`,const char`*`,const String`&`,const char`*`): [@(0.0.255) b +[s5;:HttpResponse`(TcpSocket`&`,bool`,int`,const char`*`,const char`*`,const String`&`,const char`*`,bool`): [@(0.0.255) b ool]_[* HttpResponse]([_^TcpSocket^ TcpSocket][@(0.0.255) `&]_[*@3 socket], [@(0.0.255) bool]_[*@3 scgi], [@(0.0.255) int]_[*@3 code], [@(0.0.255) const]_[@(0.0.255) cha r]_`*[*@3 phrase], [@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 content`_type]_`=_NULL, [@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 data]_`=_Null, -[@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 server]_`=_NULL)&] +[@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 server]_`=_NULL, [@(0.0.255) bool]_[*@3 gzip]_`= +_[@(0.0.255) false])&] [s2;%% This function sends simple HTTP response over [%-*@3 socket]. If [%-*@3 scgi] is true, first line of response is formatted for SCGI (rest is the same for normal HTTP and SCGI). [%-*@3 code] @@ -85,7 +86,9 @@ sets the respective http header (if NULL, it is not send). If [%-*@3 data] is not empty, `"content`-length`" header is sent and [%-*@3 data] is sent after the header. [%-*@3 server] sets the `"server`" field of http header, if not present, it is set to `"U`+`+ based -server`".&] +server`". If [%-*@3 gzip] is true, function adds `"content`-encoding: +gzip`" header, but does NOT actually zip the content (that is +up to caller).&] [s3; &] [s0; &] [ {{10000@(113.42.0) [s0;%% [*@7;4 HttpHeader]]}}&] diff --git a/uppsrc/Core/z.cpp b/uppsrc/Core/z.cpp index 318aec44d..86a55987b 100644 --- a/uppsrc/Core/z.cpp +++ b/uppsrc/Core/z.cpp @@ -270,6 +270,8 @@ void Zlib::Init() mode = NONE; gzip = false; error = false; + z.next_in = (byte*)""; + z.avail_in = 0; } void Zlib::Clear()