Coder Social home page Coder Social logo

Comments (6)

ashishnetworks avatar ashishnetworks commented on May 3, 2024 1

Thank you @jonathanong for your comments. I just retested the whole process once again and I realised that my code was already working. I was making mistakes in assuming that response should always be compressed. But what I realised now, after lots of research is that compression works only when the client sends a header with Accept-Encoding. If supported Accept-Encoding is gzip, the response will be compressed in gzip if it's deflate, the response shall be compressed in deflate form, and if it's not mentioned response shall be simple plain data. I was receiving plain text in curl because curl does not send Accept-Encoding in its default request, but when I sent curl request using curl -H 'Accept-Encoding: gzip' -D - http://localhost:3000 my response was coded into compressed form. So my code has been working for always. Thanks

Edit: And you were also right that if content-encoding is set, module will not run
so we don't have to explicitly set the content-encoding, it should be set by compression middleware depending on Accept-Encoding of the request

from compress.

jonathanong avatar jonathanong commented on May 3, 2024

don't set the content encoding urself.

from compress.

ashishnetworks avatar ashishnetworks commented on May 3, 2024

Thanks, @jonathanong for your time. Well, without setting content encoding myself, I stop getting errors. But I believe it's not getting compressed when I don't set content encoding. Because in such case when I hit the URL using curl I simply get the plain text saying 'Hello World'. If curl doesn't support decompression by default, how am I receiving a plain text then?
And if I don't set encoding myself, the question is, how is it supposed to know which encoding to use out of deflate and gzip?

from compress.

jonathanong avatar jonathanong commented on May 3, 2024

if content-encoding is set, i believe this module will not run.

can you make a PR with a failing test case?

from compress.

ashishnetworks avatar ashishnetworks commented on May 3, 2024

sorry for being a noob, but what's PR? do you mean sample programs?

from compress.

jonathanong avatar jonathanong commented on May 3, 2024

pull request

from compress.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.