Giter VIP home page Giter VIP logo

Comments (10)

valyala avatar valyala commented on August 29, 2024

Currently the client doesn't set Accept-Encoding headers to gzip or deflate, so conforming server should never send compressed response with 'Content-Encoding' response header.

Transparent compression may be added to the client as opt-in setting in Client and HostClient. EnableCompression is a good name for this setting. You may create pull request for this feature.

Enabling transparent compression in fasthttp client by default is no go, since default compression implementation in Go is slooow ;)

from fasthttp.

szank avatar szank commented on August 29, 2024

My idea was to check for the 'Content-Encoding' header in the response, and decompress the body if the header was present.
I didn't indent do modify the request sending path, only receiving. We could enable this behaviour by default, and disable it by setting 'AutoDecompress' to false in the client/response, where the value from the response would take precedence.

Now, We could add a EnableCompression parameter also, to transparently compress the requests, but this is a story for another pull request.

In our use case, we use haproxy to compress the responses sent from the server ( We do set 'Content-Encoding' in the request header explicitly), and then check for the 'Content-Encoding' in the response.

from fasthttp.

valyala avatar valyala commented on August 29, 2024

Nice idea! I'll try implementing it on the next week.

from fasthttp.

valyala avatar valyala commented on August 29, 2024

@szank , I decided adding helper functions for body compression instead of transparent compression. This allows using response body compression only when needed.

See Response.BodyGunzip and Response.BodyInflate.

from fasthttp.

valyala avatar valyala commented on August 29, 2024

Added CompressHandler for transparent response compression on server side.

from fasthttp.

dibu28 avatar dibu28 commented on August 29, 2024

There is github.com/klauspost/compress a fully gzip compatible drop in replacement for go standard gzip/zip/zlib packages.
Claimed to be up to 3x faster for data compression.
Description and benchmarks by the author:
http://blog.klauspost.com/go-gzipdeflate-benchmarks/
http://blog.klauspost.com/gzip-performance-for-go-webservers/

pgzip Go parallel gzip compression/decompression. This is a fully gzip compatible drop in replacement for "compress/gzip". Faster for big files more than 1MB.

cgzip wraps zlib using cgo.

from fasthttp.

sschepens avatar sschepens commented on August 29, 2024

What about transparent decompression of incoming requests to server?

from fasthttp.

valyala avatar valyala commented on August 29, 2024

Just added Request.BodyGunzip helper.

Transparent compression / decompression won't be implemented in fasthttp, since this may be abused by specially crafted malicious requests / responses, which may eat a lot of CPU and memory resources. So fasthttp users must manually compress / decompress request / response bodies when needed.

from fasthttp.

valyala avatar valyala commented on August 29, 2024

I think this issue may be closed now. Feel free creating new issues for unresolved topics mentioned above.

from fasthttp.

sschepens avatar sschepens commented on August 29, 2024

Thanks! Isn't BodyInflate() missing?

from fasthttp.

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.