Skip to content

Conversation

@Tratcher
Copy link
Member

@Tratcher Tratcher commented Sep 27, 2021

Contributes to #36960

The compression provider is created so long as the client's request allows compression. The compression stream should only be created if the response content-type is compressible.

DisableBuffering for uncompressed responses was regressed by #28464. If you called DisableBuffering then the compression stream would still get created but none of the compression headers would be set so the client wouldn't decompress.

The fix is to only create the compression stream if ShouldCompressResponse is true.

This should be backported to 6.0.

@Tratcher Tratcher added this to the 7.0-preview1 milestone Sep 27, 2021
@Tratcher Tratcher self-assigned this Sep 27, 2021
@Tratcher
Copy link
Member Author

/backport to release/6.0

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

@Tratcher an error occurred while backporting to release/6.0, please check the run log for details!

Error: @Tratcher is not a repo collaborator, backporting is not allowed.

@Tratcher Tratcher enabled auto-merge (squash) September 27, 2021 23:03
@Tratcher Tratcher merged commit b122066 into dotnet:main Sep 27, 2021
@Tratcher Tratcher deleted the tratcher/main/compress branch September 27, 2021 23:27
InitializeCompressionHeaders();
var compressionProvider = InitializeCompressionHeaders();

if (_compressionProvider != null)
Copy link
Member

Choose a reason for hiding this comment

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

Does this leave a field that is never initialized now?

Copy link
Member Author

@Tratcher Tratcher Sep 28, 2021

Choose a reason for hiding this comment

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

This wasn't where it was initialized, only consumed. It's initialized over here:

if (!_providerCreated)
{
_providerCreated = true;
_compressionProvider = _provider.GetCompressionProvider(_context);
}
return _compressionProvider;

The _compressionProvider field exists because there are two code paths that might cause it to be created, OnWrite and DisableBuffering, and we don't want to create it twice.

Copy link
Member

Choose a reason for hiding this comment

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

But now the field is never assigned in OnWrite, so it will be created twice?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see - it ResolveCompressionProvider is called from InitialializeCompressionHeader, so it does end up being the same instance.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's assignment hasn't changed, that happens in ResolveCompressionProvider via:

  • OnWrite()
    • InitializeCompressionHeaders();
      • ResolveCompressionProvider();

The alternate code path is:

  • DisableBuffering()
    • ResolveCompressionProvider();

@amcasey amcasey added area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants