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

Brotli: Don't accept brotli if library can't be loaded. #444

Merged
merged 3 commits into from
Feb 20, 2019

Conversation

ikreymer
Copy link
Member

@ikreymer ikreymer commented Feb 19, 2019

Description

If import brotli fails, print warning and remove br from Accept-Encoding
Otherwise, can fail silently when trying to record/replay brotli content.

Motivation and Context

See #434

Screenshots (if appropriate):

Types of changes

  • Replay fix (fixes a replay specific issue)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added or updated tests to cover my changes.
  • All new and existing tests passed.

and also remove 'br' from any Accept-Encoding to avoid recording with brotli, addresses #434
@ikreymer ikreymer requested a review from N0taN3rd February 19, 2019 23:54
Copy link
Contributor

@N0taN3rd N0taN3rd left a comment

Choose a reason for hiding this comment

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

Other than the small bare exception nit this PR LGTM 👍

try: # pragma: no cover
import brotli
has_brotli = True
except: # pragma: no cover
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be good practice to start using named exceptions when possible.

Here it would be except ImportError in order to be clearer about why we expect an exception and to be pythonic :)

Copy link
Member Author

Choose a reason for hiding this comment

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

In general, yes, but here want to catch any Exception as that means brotli is not properly installed. Added Exception

@codecov
Copy link

codecov bot commented Feb 20, 2019

Codecov Report

Merging #444 into develop will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #444      +/-   ##
===========================================
+ Coverage    87.83%   87.84%   +<.01%     
===========================================
  Files           59       59              
  Lines         7236     7239       +3     
  Branches      1288     1290       +2     
===========================================
+ Hits          6356     6359       +3     
  Misses         585      585              
  Partials       295      295
Impacted Files Coverage Δ
pywb/rewrite/rewriteinputreq.py 78.12% <100%> (+0.7%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 000ed89...f2df7ed. Read the comment docs.

@ikreymer ikreymer merged commit 32c1e6c into develop Feb 20, 2019
@ikreymer ikreymer deleted the brotli-warn-remove-accept branch February 20, 2019 01:19
N0taN3rd added a commit to N0taN3rd/warcio that referenced this pull request Feb 20, 2019
…be gain performance increases (https://docs.python.org/3/faq/programming.html#id37)

Changed the caught exception in try_brotli_init from ImportError to Exception due to finding causing pywb PR #444 (webrecorder/pywb#444)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants