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

Refactor httpx content type handling #720

Merged
merged 6 commits into from
Dec 23, 2024
Merged

Refactor httpx content type handling #720

merged 6 commits into from
Dec 23, 2024

Conversation

alexmojaki
Copy link
Contributor

Some initial work towards capturing text bodies. Currently nothing here should affect users (except that it can handle variations of application/json such as application/ld+json which is a good fix) but I see overlap with #719 so I want to merge this.

Comment on lines +413 to +445
TEXT_SUBTYPES = {
'json',
'jsonp',
'json-p',
'javascript',
'jsonl',
'json-l',
'jsonlines',
'json-lines',
'ndjson',
'nd-json',
'json5',
'json-5',
'xml',
'xhtml',
'html',
'csv',
'tsv',
'yaml',
'yml',
'toml',
}


@lru_cache
def is_text_type(content_type: str) -> bool:
header = content_type_header_from_string(content_type)
if header.maintype == 'text':
return True
if header.maintype != 'application':
return False

return bool(content_type_subtypes(header.subtype) & TEXT_SUBTYPES)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't used yet.

@alexmojaki alexmojaki requested a review from Kludex December 23, 2024 12:42
Copy link

codecov bot commented Dec 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (4963b14) to head (628e254).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #720   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          138       138           
  Lines        11088     11128   +40     
  Branches      1548      1554    +6     
=========================================
+ Hits         11088     11128   +40     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

cloudflare-workers-and-pages bot commented Dec 23, 2024

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 628e254
Status: ✅  Deploy successful!
Preview URL: https://40c9aff2.logfire-docs.pages.dev
Branch Preview URL: https://alex-capture-text.logfire-docs.pages.dev

View logs

@alexmojaki alexmojaki merged commit 9933ce3 into main Dec 23, 2024
14 checks passed
@alexmojaki alexmojaki deleted the alex/capture-text branch December 23, 2024 13:43
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