Skip to content

feat: add default option - #191

Merged
bjohansebas merged 10 commits into
expressjs:masterfrom
bjohansebas:add-default-encoding
Dec 5, 2024
Merged

feat: add default option#191
bjohansebas merged 10 commits into
expressjs:masterfrom
bjohansebas:add-default-encoding

Conversation

@bjohansebas

@bjohansebasbjohansebas commented Sep 27, 2024

Copy link
Copy Markdown
Member

A new option is added to determine the default behavior when Accept-Encoding is not sent by the client, defaulting to identity.

closes#83

@bjohansebasbjohansebas mentioned this pull request Sep 27, 2024
@bjohansebas
bjohansebas marked this pull request as ready for review September 28, 2024 00:30
@bjohansebasbjohansebas changed the title [WIP]: feat: add default optionfeat: add default optionSep 28, 2024
@bjohansebas

Copy link
Copy Markdown
MemberAuthor

Hi @IamLizu, could you review this PR?

@IamLizu

Copy link
Copy Markdown
Member

Hey @bjohansebas 👋

Sure, I will read the relevant issues and then review this PR 👍

Comment threadindex.js
@bjohansebasbjohansebas self-assigned this Oct 15, 2024
@bjohansebas
bjohansebas marked this pull request as draft November 3, 2024 19:58
@bjohansebas
bjohansebas marked this pull request as ready for review November 3, 2024 20:05
@bjohansebasbjohansebas added this to the 1.8.0 milestone Nov 3, 2024

@IamLizuIamLizu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @bjohansebas 👋

I'm generally 👍 of the concept of introducing an enforcement mechanism, as discussed in #83.

However, would you mind renaming the variable defaultEnconfig to something that doesn't conflict with zlib.createGzip or zlib.createDeflate? It seems this conflict may have led to the addition of the following block:

if(opts.defaultEncoding){opts.defaultEncoding=undefined}

I suggest enforceEncoding, more on this below. Renaming the variable would help keep the code clean, and it’s important that we avoid such conflicts.

Thanks so much for your understanding and effort!

Comment threadindex.js Outdated
Comment threadindex.js Outdated
@bjohansebas

Copy link
Copy Markdown
MemberAuthor

@IamLizu Good catch

@IamLizuIamLizu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 👍

There's something I should address. As we know, content negotiation is handled by negotiator here, and it is indeed negotiator's responsibility to choose the best method.

Maybe we are interfering with negotiator's responsibilities?

cc: @expressjs/express-tc

@bjohansebas

Copy link
Copy Markdown
MemberAuthor

@UlisesGascon ping

Comment threadindex.js Outdated
Comment threadindex.js

// if no method is found, use the default encoding
if (encodingSupported.indexOf(enforceEncoding) !== -1 && !req.headers['accept-encoding']) {
method = enforceEncoding === '*' ? 'gzip' : enforceEncoding

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I dont see * referenced anywhere but here. Can you describe why this is necessary when you could drop this check and just have folks pass gzip directly for this?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

If * is not checked and changed, the deflate encoding would be applied as it’s the last one in the check (

compression/index.js

Lines 196 to 198 in 66c0cb7

stream=method==='gzip'
? zlib.createGzip(opts)
: zlib.createDeflate(opts)
), and deflate is not the encoding we want to be applied, it should be gzip when it’s *.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry but I don't follow your description? To me it looks like this value for the option (coming from the calling code) could just be dropped entirely.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I haven't found a way to eliminate this check.

@bjohansebas

Copy link
Copy Markdown
MemberAuthor

@wesleytodd Is there any change I need to make?

@bjohansebas
bjohansebas merged commit f4e596c into expressjs:masterDec 5, 2024
@bjohansebas
bjohansebas deleted the add-default-encoding branch December 5, 2024 15:28
@bjohansebasbjohansebas mentioned this pull request Jan 8, 2025

@wesleytoddwesleytodd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks to me like this was merged with a pending "change requested" review. Is that the case?

Comment threadindex.js

// if no method is found, use the default encoding
if (encodingSupported.indexOf(enforceEncoding) !== -1 && !req.headers['accept-encoding']) {
method = enforceEncoding === '*' ? 'gzip' : enforceEncoding

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry but I don't follow your description? To me it looks like this value for the option (coming from the calling code) could just be dropped entirely.

@bjohansebas

Copy link
Copy Markdown
MemberAuthor

Sorry for merging this with a change request, I now know I need to wait until the approval is there.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Force compression to client don't work

3 participants

@bjohansebas@IamLizu@wesleytodd