From d7f21128558e140e68ceb51e63429e95130f9565 Mon Sep 17 00:00:00 2001 From: Lu Date: Thu, 16 Aug 2018 14:26:32 +0800 Subject: Closed #16 --- src/http1.cc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/http1.cc b/src/http1.cc index f40aecb..cce147c 100644 --- a/src/http1.cc +++ b/src/http1.cc @@ -110,13 +110,34 @@ public: /* 处理到Value时,Field不应为空 * Value可能分成片段,多次调用给出,在这里需要将他们拼合 */ + std::string __str_data = std::string(data, data + len); + /* Hack, 直接覆盖Accept-Encoding,用空格等长替换 */ if (strcasecmp(str_last_header_field_.c_str(), "Accept-Encoding") == 0) { memset((void *) data, 0x20, len); } + else + { + str_last_value_field_ += __str_data; + } + + /* Hack,对于Google.com,在Cookie中嵌有GZ=Z=1字段,表示浏览器支持GZIP,服务端将不遵守Accept-Encoding中的约定, + * 需要将Cookie中的这个字段抹去,避免服务端返回GZIP编码的应答 */ + static const std::string __gz_tag{"GZ=Z=1"}; + std::string::size_type __find_location; + + if ((strcasecmp(str_last_header_field_.c_str(), "Cookie") == 0) && + ((__find_location = __str_data.rfind(__gz_tag)) != std::string::npos)) + { + auto replace_location = __find_location + __gz_tag.length() - 1; + assert(replace_location <= len); + + char * __data = (char *)data; + __data[replace_location] = '0'; + } - str_last_value_field_ += std::string(data, data + len); + return; } void ConstructByHttpParserComplete() -- cgit v1.2.3