@@ -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,33 @@ 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 {body_state = waiting }) ->
345
+ parse_body2 (St );
346
+ parse_body (St = # hparser {encoding = {zlib ,Z }}) ->
347
+ case parse_body2 (St ) of
348
+ {ok , Chunk , St2 } ->
349
+ Chunk2 = iolist_to_binary (zlib :inflate (Z , Chunk )),
350
+ {ok , Chunk2 , St2 };
351
+ {done , Rest } ->
352
+ Rest2 = iolist_to_binary (zlib :inflate (Z , Rest )),
353
+ ok = zlib :inflateEnd (Z ),
354
+ ok = zlib :close (Z ),
355
+ {done , Rest2 };
356
+ Else ->
357
+ Else
358
+ end ;
359
+ parse_body (St ) ->
360
+ parse_body2 (St ).
361
+
362
+ parse_body2 (St = # hparser {body_state = waiting , te = TE , clen = Length , buffer = Buffer }) ->
336
363
case {TE , Length } of
337
364
{<<" chunked" >>, _ } ->
338
365
parse_body (St # hparser {body_state =
@@ -346,14 +373,13 @@ parse_body(St=#hparser{body_state=waiting, te=TE, clen=Length, buffer=Buffer}) -
346
373
St # hparser {body_state = {stream , fun te_identity /2 , {0 , Length }, fun ce_identity /1 }}
347
374
)
348
375
end ;
349
- parse_body (# hparser {body_state = done , buffer = Buffer }) ->
376
+ parse_body2 (# hparser {body_state = done , buffer = Buffer }) ->
350
377
{done , Buffer };
351
- parse_body (St = # hparser {buffer = Buffer , body_state = {stream , _ , _ , _ }}) when byte_size (Buffer ) > 0 ->
378
+ parse_body2 (St = # hparser {buffer = Buffer , body_state = {stream , _ , _ , _ }}) when byte_size (Buffer ) > 0 ->
352
379
transfer_decode (Buffer , St # hparser {buffer = <<>>});
353
- parse_body (St ) ->
380
+ parse_body2 (St ) ->
354
381
{more , St , <<>>}.
355
382
356
-
357
383
-spec transfer_decode (binary (), # hparser {})
358
384
-> {ok , binary (), # hparser {}} | {done , binary ()} | {error , atom ()}.
359
385
transfer_decode (Data , St = # hparser {
@@ -518,6 +544,8 @@ get_property(method, #hparser{method=Method}) ->
518
544
Method ;
519
545
get_property (transfer_encoding , # hparser {te = TE }) ->
520
546
TE ;
547
+ get_property (content_encoding , # hparser {ce = CE }) ->
548
+ CE ;
521
549
get_property (content_length , # hparser {clen = CLen }) ->
522
550
CLen ;
523
551
get_property (connection , # hparser {connection = Connection }) ->
0 commit comments