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

Warn about br handling if brotlipy is not installed #4697

Open
Gallaecio opened this issue Jul 27, 2020 · 11 comments · May be fixed by #5480 or #6145
Open

Warn about br handling if brotlipy is not installed #4697

Gallaecio opened this issue Jul 27, 2020 · 11 comments · May be fixed by #5480 or #6145

Comments

@Gallaecio
Copy link
Member

Currently, the HTTP compression middleware sets the Accept-Encoding header to gzip,deflate or gzip,deflate,br depending on whether or not brotlipy is installed.

However, if the user manually sets the Accept-Encoding header to a value containing br, and does not have brotlipy installed, the server can send a response compressed with br and Scrapy will silently fail to decompress it, so the response content will not be readable.

I think we should improve a bit the handling of this scenario.

If the user sets br manually on the Accept-Encoding header, I think we should:

  • Log a warning if brotlipy is not installed.
  • Have the middleware cause an error if the server sends the response br-encoded, and brotlipy is not installed.
  • Log an information message the first time that the user sends a response with a manually-set Accept-Encoding header which is identical to the one that the HTTP compression middleware would define. It should not be a warning because the user does not need to do anything about it. It should only be displayed once because there is a chance the user is doing it on purpose (e.g. if the default headers define a different value but the user wishes to override that for some requests with the default value.

The 3rd bullet point may not be that useful, but I think the 1st and 2nd are.

@Gallaecio
Copy link
Member Author

That tool sounds very interesting!

Regarding this specific issue, it could be argued that it is indeed a good first issue. I’m unsure, though.

@Dushatar
Copy link

Dushatar commented Mar 3, 2021

Hello. Me and two others would like to take a look at this issue as part of a course we are taking @Gallaecio

Hopefully we can make some progress in the, not so long, time allocated to the assignment.

@Gallaecio
Copy link
Member Author

@Dushatar Please, have a go at it, and let us know if you need any help 🙂

@Dushatar
Copy link

Dushatar commented Mar 5, 2021

We did not have much time designated for this in the course, it was mostly just to get the feel for open source projects. We pushed some code that does what was requested (as we understood it), but I am not sure if the way we did it is as intended.

It (1) logs a warning if brotlipy is not installed and (2) raise a ImportError exception if a user is sent an br-encoded response while not having brotlipy installed.

@Gallaecio
Copy link
Member Author

It’s quite a good start, but it would need some adjustments to get merged. It should definitely make things easier for the next person that comes around.

@Anupam-USP
Copy link

I am very new, sorry to ask silly questions but after changing files on my machine how can I check if this is causing some errors or is it ok to push and later create a pr?

@Gallaecio
Copy link
Member Author

After changing files on my machine how can I check if this is causing some errors or is it ok to push and later create a pr?

You can run automated tests locally. But feel free to create a pull request and let the Continuous Integration system run tests automatically in multiple different environments. If your changes are not ready for a review yet, you can mark your pull request as a draft when creating it, and later mark it as ready for review.

@PluT00
Copy link

PluT00 commented May 4, 2022

Is this one still relevant? I'd like to work on it!

@Gallaecio
Copy link
Member Author

There is #5480 already, pending review. You could review it and give your thoughts.

@wRAR wRAR added this to the Scrapy 2.8 milestone Nov 23, 2022
@wRAR
Copy link
Member

wRAR commented Nov 23, 2022

Alternatively: #4698

@wRAR wRAR modified the milestones: Scrapy 2.8, Scrapy 2.9 Feb 2, 2023
@kmike kmike modified the milestones: Scrapy 2.9, Scrapy 2.10 Apr 27, 2023
@wRAR wRAR modified the milestones: Scrapy 2.10, Scrapy 2.11 Aug 7, 2023
ArianAsghari added a commit to ArianAsghari/scrapy that referenced this issue Sep 30, 2023
Solved version of issue scrapy#4697
@Ad12y
Copy link

Ad12y commented Apr 27, 2024

Is this still relevant? If yes, I would like to work on it!

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