Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: don't compress on x-no-compression header #208

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bjohansebas
Copy link
Member

@bjohansebas bjohansebas commented Dec 5, 2024

We should observe when X-No-Compression is sent in the request.

Copy link
Member

@IamLizu IamLizu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function shouldCompress (req, res) {
  var type = res.getHeader('Content-Type')
  var noCompressionHeader = res.getHeader('x-no-compression')

  if (noCompressionHeader) {
    debug('%s not compressed', type)
    return false
  }

  if (type === undefined || !compressible(type)) {
    debug('%s not compressible', type)
    return false
  }

  return true
}

PS: I don't know why but I am not seeing the commit suggestion feature right now, so I have given the code in comment.

index.js Outdated
@@ -256,12 +256,18 @@ function chunkLength (chunk, encoding) {

function shouldCompress (req, res) {
var type = res.getHeader('Content-Type')
var noCompressionHeader = res.getHeader('x-no-compression')

if (type === undefined || !compressible(type)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compressible is being called even if added noCompressionHeader is present. noCompressionHeader should be checked first.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants