@@ -305,6 +305,9 @@ parse_header(Line, St) ->
305
305
<<" transfer-encoding" >> ->
306
306
TE = hackney_bstr :to_lower (hackney_bstr :trim (Value )),
307
307
St # hparser {te = TE };
308
+ <<" content-encoding" >> ->
309
+ CE = hackney_bstr :to_lower (hackney_bstr :trim (Value )),
310
+ St # hparser {ce = CE };
308
311
<<" connection" >> ->
309
312
Connection = hackney_bstr :to_lower (hackney_bstr :trim (Value )),
310
313
St # hparser {connection = Connection };
@@ -330,9 +333,31 @@ parse_trailers(St, Acc) ->
330
333
_ -> error
331
334
end .
332
335
333
- parse_body (# hparser {body_state = waiting , method = <<" HEAD" >>, buffer = Buffer }) ->
334
- {done , Buffer };
335
- parse_body (St = # hparser {body_state = waiting , te = TE , clen = Length , buffer = Buffer }) ->
336
+ parse_body (# hparser {body_state = waiting , method = Method , buffer = Buffer , clen = Length }) when Method == <<" HEAD" >>; Length =:= 0 ->
337
+ {done , Buffer };
338
+ parse_body (St = # hparser {body_state = waiting , ce = CE }) when CE == <<" gzip" >>; CE == <<" deflate" >> ->
339
+ MaxWBITS = 15 , % zconf.h
340
+ WB = MaxWBITS + if CE == <<" gzip" >> -> 16 ; true -> 0 end , % http://www.zlib.net/manual.html#Advanced
341
+ Z = zlib :open (),
342
+ ok = zlib :inflateInit (Z , WB ),
343
+ parse_body2 (St # hparser {encoding = {zlib ,Z }});
344
+ parse_body (St = # hparser {encoding = {zlib ,Z }}) ->
345
+ case parse_body2 (St ) of
346
+ {ok , Chunk , St2 } ->
347
+ Chunk2 = iolist_to_binary (zlib :inflate (Z , Chunk )),
348
+ {ok , Chunk2 , St2 };
349
+ {done , Rest } ->
350
+ Rest2 = iolist_to_binary (zlib :inflate (Z , Rest )),
351
+ ok = zlib :inflateEnd (Z ),
352
+ ok = zlib :close (Z ),
353
+ {done , Rest2 };
354
+ Else ->
355
+ Else
356
+ end ;
357
+ parse_body (St ) ->
358
+ parse_body2 (St ).
359
+
360
+ parse_body2 (St = # hparser {body_state = waiting , te = TE , clen = Length , buffer = Buffer }) ->
336
361
case {TE , Length } of
337
362
{<<" chunked" >>, _ } ->
338
363
parse_body (St # hparser {body_state =
@@ -346,14 +371,13 @@ parse_body(St=#hparser{body_state=waiting, te=TE, clen=Length, buffer=Buffer}) -
346
371
St # hparser {body_state = {stream , fun te_identity /2 , {0 , Length }, fun ce_identity /1 }}
347
372
)
348
373
end ;
349
- parse_body (# hparser {body_state = done , buffer = Buffer }) ->
374
+ parse_body2 (# hparser {body_state = done , buffer = Buffer }) ->
350
375
{done , Buffer };
351
- parse_body (St = # hparser {buffer = Buffer , body_state = {stream , _ , _ , _ }}) when byte_size (Buffer ) > 0 ->
376
+ parse_body2 (St = # hparser {buffer = Buffer , body_state = {stream , _ , _ , _ }}) when byte_size (Buffer ) > 0 ->
352
377
transfer_decode (Buffer , St # hparser {buffer = <<>>});
353
- parse_body (St ) ->
378
+ parse_body2 (St ) ->
354
379
{more , St , <<>>}.
355
380
356
-
357
381
-spec transfer_decode (binary (), # hparser {})
358
382
-> {ok , binary (), # hparser {}} | {done , binary ()} | {error , atom ()}.
359
383
transfer_decode (Data , St = # hparser {
@@ -518,6 +542,8 @@ get_property(method, #hparser{method=Method}) ->
518
542
Method ;
519
543
get_property (transfer_encoding , # hparser {te = TE }) ->
520
544
TE ;
545
+ get_property (content_encoding , # hparser {ce = CE }) ->
546
+ CE ;
521
547
get_property (content_length , # hparser {clen = CLen }) ->
522
548
CLen ;
523
549
get_property (connection , # hparser {connection = Connection }) ->
0 commit comments