Skip to content

Commit

Permalink
http-client: fuzzyfind the content encoding
Browse files Browse the repository at this point in the history
* Fixes an issue with broken servers returning ', gzip' as their
  content-encoding
  • Loading branch information
Ryan Phillips committed Aug 29, 2012
1 parent 60dd49a commit 37306a5
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/modules-lua/noit/HttpClient.lua
Expand Up @@ -194,17 +194,31 @@ function HttpClient:get_body(read_limit)
local cefunc = ce_passthru
local ce = self.headers["content-encoding"]
if ce ~= nil then
local deflater
if ce == "gzip" then
local deflater
if ce == 'gzip' then
deflater = noit.gunzip()
elseif ce == 'deflate' then
deflater = noit.gunzip()
elseif ce:find(',') then
local tokens = noit.extras.split(ce, ",")
for _, token in pairs(tokens) do
if token:gsub("^%s*(.-)%s*$", "%1") == "gzip" then
deflater = noit.gunzip()
elseif ce == "deflate" then
break
elseif token:gsub("^%s*(.-)%s*$", "%1") == "deflate" then
deflater = noit.gunzip()
else
error("unknown content-encoding: " .. ce)
end
cefunc = function(str)
return deflater(str, read_limit)
break
end
end
end

if deflater == nil then
error("unknown content-encoding: " .. ce)
end

cefunc = function(str)
return deflater(str, read_limit)
end
end
local te = self.headers["transfer-encoding"]
local cl = self.headers["content-length"]
Expand Down

0 comments on commit 37306a5

Please sign in to comment.