From 178bb3a1ceab88f29aa7d0ceb453e76de172fd27 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Sun, 6 Aug 2017 22:23:41 +0200 Subject: Add protools, used for getting content out of packages Only HTTP protocol implemented yet, but with gzip, deflate and bzip2 suport --- src/proxy.cc | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'src/proxy.cc') diff --git a/src/proxy.cc b/src/proxy.cc index 3909541..5eca4fb 100644 --- a/src/proxy.cc +++ b/src/proxy.cc @@ -822,27 +822,6 @@ bool ProxyImpl::base_event(BaseClient* client, uint8_t events, return true; } -inline char lower_ascii(char c) { - return (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c; -} - -bool lower_equal(char const* data, size_t start, size_t end, - std::string const& str) { - assert(start <= end); - if (str.size() != end - start) return false; - for (auto i = str.begin(); start < end; ++start, ++i) { - if (lower_ascii(*i) != lower_ascii(data[start])) return false; - } - return true; -} - -bool header_token_eq(std::string const& value, std::string const& token) { - if (value.empty()) return false; - auto pos = value.find(';'); - if (pos == std::string::npos) pos = value.size(); - return lower_equal(value.data(), 0, pos, token); -} - void ProxyImpl::client_remote_error(size_t index, uint16_t error) { auto& client = clients_[index]; if (client.remote_state > CONNECTED) { @@ -1014,8 +993,13 @@ void ProxyImpl::client_event(size_t index, int fd, uint8_t events) { bool setup_content(Http const* http, Content* content) { assert(content->type == CONTENT_NONE); - std::string te = http->first_header("transfer-encoding"); - if (te.empty() || header_token_eq(te, "identity")) { + auto iter = http->header_tokens("transfer-encoding"); + bool chunked = false; + while (iter->valid()) { + chunked = iter->token_equal("chunked"); + iter->next(); + } + if (!chunked) { std::string len = http->first_header("content-length"); if (len.empty()) { content->type = CONTENT_CLOSE; -- cgit v1.2.3-70-g09d2