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 Show resolved Hide resolved
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.

LGTM

@ctcpip
Copy link
Member

ctcpip commented Jan 18, 2025

we shouldn't hardcode tbis behavior. x-no-compression is not a standard http header. the readme already has an example of how to do this within application code

Copy link
Member

@ctcpip ctcpip left a comment

Choose a reason for hiding this comment

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

see above comment

@wesleytodd
Copy link
Member

For those looking for the doc referenced above:

https://github.com/expressjs/compression?tab=readme-ov-file#filter-1


How do we feel about adding an option for this? While I agree we should not hard code this non-standard behavior, it is quite common for libraries and proxies to implement handling for commonly used non-standard headers. This one feels to me like a reasonable one to support in that way.

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.

4 participants