diff options
| author | Lu <[email protected]> | 2018-07-26 19:40:24 +0800 |
|---|---|---|
| committer | Lu <[email protected]> | 2018-07-26 19:40:24 +0800 |
| commit | c7b8de6d2b85c705c50768d4cfef99b0cf594fba (patch) | |
| tree | 527512f4d5cab9b8ea148736d839cc7f30545ff3 /src | |
| parent | 3e75742fccb84f8c3f5054de1a7f0241f837b3a7 (diff) | |
#3 增加压缩编码降级功能,替换请求中的Accept-Encoding字段,使得服务器不返回压缩后的应答体。
Diffstat (limited to 'src')
| -rw-r--r-- | src/http1.cc | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/http1.cc b/src/http1.cc index cbde86a..b9a3401 100644 --- a/src/http1.cc +++ b/src/http1.cc @@ -109,6 +109,13 @@ public: { /* 处理到Value时,Field不应为空 * Value可能分成片段,多次调用给出,在这里需要将他们拼合 */ + + /* Hack, 直接覆盖Accept-Encoding,用空格等长替换 */ + if (strcasecmp(str_last_header_field_.c_str(), "Accept-Encoding") == 0) + { + memset((void *)data, 0x20, len); + } + str_last_value_field_ += std::string(data, data + len); } @@ -610,8 +617,9 @@ private: std::string last_header_field_{}; /* Headers For Debug */ - std::string content_type; - std::string content_length; + std::string content_type{}; + std::string content_length{}; + std::string content_encoding{}; /* Parser & Raw Content * 该原始内容,等价于本结构体的序列化后的结果,因此,输入的、未经解析的字节数据,不应该保留在这个位置 */ @@ -725,6 +733,12 @@ int Http1ResponseParserCallbacks::CallbackOnHeaderComplete(http_parser * parser) return false; }); + resp_ptr->headers_.ForEachValueOfHeader("Content-Encoding", [resp_ptr](const std::string & f, const std::string &v) + { + resp_ptr->content_encoding = v; + return false; + }); + return 0; } @@ -916,7 +930,7 @@ evbuffer_unique_ptr_t Http1Response::StolenEvBuf() std::string Http1Response::DumpToString() { - return {std::to_string(resp_code_) + " " + content_type + " " + content_length}; + return {std::to_string(resp_code_) + " " + content_type + " " + content_length + " " + content_encoding}; } int Http1Connection::on_connection_close(pxy_conn_ctx_t * conn_ctx, struct bufferevent * bev) @@ -991,7 +1005,7 @@ int Http1Connection::on_connection_read_response(pxy_conn_ctx_t * conn_ctx, pxy_ if (session == nullptr) { LOG(WARNING) << "Found standlone HTTP response, Ignore it."; - LOG(WARNING) << hexdump("upstream recieve buffer", upstream_evbuf); + LOG(WARNING) << hexdump("upstream recieve buffer", downstream_evbuf); return 0; } @@ -1175,4 +1189,5 @@ std::unique_ptr<HttpResponse> HttpResponseFactory(short major_version, short min return std::move(std::make_unique<Http1Response>(major_version, minor_version)); return nullptr; -}
\ No newline at end of file +} + |
