GithubHelp home page GithubHelp logo

Comments (6)

elithrar avatar elithrar commented on May 20, 2024

In addition:

  • Tests need to explicitly check that a *gzip.Writer retrieved from the pool is correctly Reset(). This is a potential security issue waiting to happen otherwise.
  • Use a base64 encoded PNG to test the "don't gzip" case - http://www.gorillatoolkit.org/static/images/gorilla-icon-64.png is a good candidate (drop the base64 bytes into a var, decode into bytes during the test)
  • Update the docs on CompressHandler to indicate the selective gzipping.

from handlers.

nwidger avatar nwidger commented on May 20, 2024

+1

from handlers.

elithrar avatar elithrar commented on May 20, 2024

#48 has likely made this much harder now due to the limitations around defining a global pool:

  • If we create a global pool of gzip writers (we must if we want a pool) then we can't pass the "current" level to the pool per-instance of middleware:
var gzipPool = sync.Pool{
    // Can't pass the level when we call New()
    New: func() interface{} {
        return gzip.NewWriter(nil)
    },
}
  • We could set a package global level, but that creates implicit behaviour (all CompressHandler instances would need to use it) and also causes race conditions when you have more than one CompressHandlerLevel middleware in play. Effectively a non-starter here.
  • The level field on *gzip.Writer isn't exported and therefore you can't modify it after you type-assert the writer out of the pool.

Is there a solution here that I'm missing? I think this PR had more value as changing gzip levels should be done with caution in a HTTP context, but a pooled gzip writer nets everyone a performance gain, but unfortunately that's how things have shaken out.

@kisielk - would appreciate your feedback/input here.

from handlers.

kisielk avatar kisielk commented on May 20, 2024

How about a separate pool for every compression level? There's only 11 of them and the size overhead for a pool is not that large.

from handlers.

bernardolm avatar bernardolm commented on May 20, 2024

👍

from handlers.

stale avatar stale commented on May 20, 2024

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.

from handlers.

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.