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

Rename compress parameter #8928

Closed
Dreamsorcerer opened this issue Aug 28, 2024 · 6 comments · Fixed by #9108
Closed

Rename compress parameter #8928

Dreamsorcerer opened this issue Aug 28, 2024 · 6 comments · Fixed by #9108
Milestone

Comments

@Dreamsorcerer
Copy link
Member

The request() method has a compress parameter which forces compression even when the headers are not set, leading any normal server to not know the request is compressed.

This is a useless option for most people. If we can't remove the option, we should atleast rename it to something that stops people using it by mistake.

We've had many users report bugs due to this confusion.

@Dreamsorcerer Dreamsorcerer added this to the 4.0 milestone Aug 28, 2024
@wfatherley
Copy link
Contributor

Tracing the parameter starting at ClientSession._request, it's passed to ClientRequest:

req = self._request_class(

where it's stored as an attribute. It's then passed to the request object's writer here:

if self.compress:

Seems that this if-block might be the last point at which the parameter can be interpolated into a Content Encoding header. Because ClientSession and the corresponding objects it interacts with support other parameters that are essentially header values, it doesn't feel unreasonable to keep it around so long as it's not a headache for users. One thing that is worth discussing before implementing a fix is would the value of the parameter compress have precedence over a Content Encoding header if both were passed in?

@Dreamsorcerer
Copy link
Member Author

Hmm, maybe I misread it...
It does set a header at:

elif self.compress:
if not isinstance(self.compress, str):
self.compress = "deflate"
self.headers[hdrs.CONTENT_ENCODING] = self.compress

Any chance you could create an xfail test based on one of the bug reports?
See for example: #3413

@wfatherley
Copy link
Contributor

So there’s no worry on the edge case of setting the compress attribute after the call to __init__? I was going to suggest that the header-bound parameters reside in descriptor-based attributes, which could circumvent the ceremonial update_* methods…

I’ll have a look at that issue and see what I can come up with :)

@Dreamsorcerer
Copy link
Member Author

So there’s no worry on the edge case of setting the compress attribute after the call to __init__?

Hadn't really thought about that. Not sure why anyone would change it via attribute. But, if that's a problem, we can easily just use @property to call that method when it's changed (or just make it read-only in future).

@Dreamsorcerer
Copy link
Member Author

Dreamsorcerer commented Sep 9, 2024

Might already be a related test in #5478.

@Dreamsorcerer
Copy link
Member Author

Actually, if the test is corrected to use the correct method, then it seems to reproduce the problem when using the C parser. But, works fine with the Python parser...

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

Successfully merging a pull request may close this issue.

2 participants