mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 04:10:24 +00:00
Use cow_deflate in cowboy_decompress_h
The function inflate/3 was moved there to make it usable from within Cowlib itself.
This commit is contained in:
parent
9d385fa909
commit
e00131824a
1 changed files with 2 additions and 20 deletions
|
@ -68,7 +68,8 @@ data(StreamID, IsFin, Data, State=#state{next=Next0, enabled=false, read_body_bu
|
|||
fold(Commands, State#state{next=Next, read_body_is_fin=IsFin});
|
||||
data(StreamID, IsFin, Data, State0=#state{next=Next0, ratio_limit=RatioLimit,
|
||||
inflate=Z, is_reading=true, read_body_buffer=Buffer}) ->
|
||||
case inflate(Z, RatioLimit, buffer_to_iovec([Data|Buffer])) of
|
||||
Limit = iolist_size(Data) * RatioLimit,
|
||||
case cow_deflate:inflate(Z, buffer_to_iovec([Data|Buffer]), Limit) of
|
||||
{error, ErrorType} ->
|
||||
zlib:close(Z),
|
||||
Status = case ErrorType of
|
||||
|
@ -236,22 +237,3 @@ do_build_accept_encoding([{ContentCoding, Q}|Tail], Acc0) ->
|
|||
do_build_accept_encoding(Tail, Acc);
|
||||
do_build_accept_encoding([], Acc) ->
|
||||
Acc.
|
||||
|
||||
inflate(Z, RatioLimit, Data) ->
|
||||
try
|
||||
{Status, Output} = zlib:safeInflate(Z, Data),
|
||||
Size = iolist_size(Output),
|
||||
do_inflate(Z, Size, iolist_size(Data) * RatioLimit, Status, [Output])
|
||||
catch
|
||||
error:data_error ->
|
||||
{error, data_error}
|
||||
end.
|
||||
|
||||
do_inflate(_, Size, Limit, _, _) when Size > Limit ->
|
||||
{error, size_error};
|
||||
do_inflate(Z, Size0, Limit, continue, Acc) ->
|
||||
{Status, Output} = zlib:safeInflate(Z, []),
|
||||
Size = Size0 + iolist_size(Output),
|
||||
do_inflate(Z, Size, Limit, Status, [Output | Acc]);
|
||||
do_inflate(_, _, _, finished, Acc) ->
|
||||
{ok, iolist_to_binary(lists:reverse(Acc))}.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue