-
Notifications
You must be signed in to change notification settings - Fork 0
[PD1-921] Handle compressed responses and cache #23
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f3b66bd
Handle compressed responses and cache
joshuanapoli 13bfdf9
Minor version bump
joshuanapoli 9cfb7cf
Add support for brotli compression
joshuanapoli eccdd39
Limit cache size
joshuanapoli 3c9360c
Use uv for Continous Integration
joshuanapoli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| name: Python License Check | ||
|
|
||
| on: | ||
| push: | ||
|
|
||
| jobs: | ||
| license-check: | ||
| runs-on: ubuntu-24.04 | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | ||
|
|
||
| - name: Check Python licenses | ||
| uses: CVector-Energy/pyproject-license-check@main | ||
| with: | ||
| app-id: ${{ vars.APP_ID }} | ||
| app-private-key: ${{ secrets.APP_PRIVATE_KEY }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| """In-memory HTTP cache for GET requests with Cache-Control and ETag support.""" | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Any, Optional | ||
|
|
||
|
|
||
| MAX_CACHE_ENTRIES = 100 | ||
|
|
||
|
|
||
| @dataclass | ||
| class CacheEntry: | ||
| """A cached HTTP response.""" | ||
|
|
||
| data: Any | ||
| etag: Optional[str] | ||
| max_age: int | ||
| stored_at: float | ||
|
|
||
| @property | ||
| def expires_at(self) -> float: | ||
| """Monotonic time when this entry expires.""" | ||
| return self.stored_at + self.max_age | ||
|
|
||
|
|
||
| def parse_max_age(header: Optional[str]) -> Optional[int]: | ||
| """Parse max-age value from a Cache-Control header. | ||
|
|
||
| Returns: | ||
| The max-age value in seconds, or None if not present. | ||
| """ | ||
| if header is None: | ||
| return None | ||
| for directive in header.split(","): | ||
| directive = directive.strip() | ||
| if directive.startswith("max-age="): | ||
| try: | ||
| return int(directive[len("max-age=") :]) | ||
| except ValueError: | ||
| return None | ||
| return None | ||
joshuanapoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.