hackney icon indicating copy to clipboard operation
hackney copied to clipboard

Transparent (content-encoding) compression

Open jimdigriz opened this issue 6 years ago • 7 comments

An initial stab at merging my wrapper into hackney its-self which addresses issue https://github.com/benoitc/hackney/issues/155

To use this, just pass compress as an option to hackney:{request,get,...}.

jimdigriz avatar Nov 16 '17 12:11 jimdigriz

Tests a failing because of a dialyzer warning:

_build/default/lib/hackney/src/hackney_http.erl
 111: Record construction #hparser{type::'auto',max_line_length::4096,max_empty_lines::10,empty_lines::0,state::'on_first_line',buffer::<<>>,method::<<>>,partial_headers::[],te::<<>>,ce::<<>>,connection::<<>>,ctype::<<>>,location::<<>>,body_state::'waiting',encoding::'undefined'} violates the declared type of field encoding::{atom(),_}
 523: Function parse_options/2 will never be called

I would suggest you to change type of encoding field to {atom(), any()} | undefined.

seriyps avatar Nov 28 '17 12:11 seriyps

Shouldn't the new compress option be inferred from the accept header instead of needing to be explicitly specified? Was it not done this way for backwards compatibility reasons?

fenollp avatar Nov 28 '17 17:11 fenollp

I used compress to avoid having to create a API call so then the application can tell what to put in its headers (today we support deflate/gzip simply as it brings in no dependencies). I suspect to a developer most of the time they think more "compress where possible" rather than "please only use deflate".

However, this is how I think of using hackney, if I need something else, I just hack the source and submit a PR, others I am willing to accept might prefer something else :)

jimdigriz avatar Nov 28 '17 17:11 jimdigriz

Works great for me. Thanks :)

fenollp avatar Nov 28 '17 18:11 fenollp

Finally found the time to improve the compress flag support; I moved the functionality from hackney_http into hackney_response which seems more appropriate as Content-Encoding is application layer feature rather than part of the transport.

I chose to not add guards to skip initialising zlib for clen=0/bad_int and HEAD requests as the user chooses those values and could also choose to not use compress too. This was just my preference, I am not wedded to it and happy to change that behaviour.

I went to try adding unit tests, but looking around it seems to be non-trivial to add gzip/deflate support to gunicorn so got stopped in my tracks. Any suggestions on what to do here?

jimdigriz avatar May 29 '20 20:05 jimdigriz

@jimdigriz i added the tests using the new test platform. will land with the next RC.

benoitc avatar Oct 28 '21 09:10 benoitc

@benoitc Any update on this?

jadeallenx avatar Feb 24 '22 16:02 jadeallenx