-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Fix encoding error with non-prettified encoded responses #1168
Fix encoding error with non-prettified encoded responses #1168
Conversation
Removed `--format-option response.as` an promote `--response-as`: using the format option would be misleading as it is now also used by non-prettified responses.
Codecov Report
@@ Coverage Diff @@
## master #1168 +/- ##
==========================================
- Coverage 97.28% 96.66% -0.62%
==========================================
Files 67 70 +3
Lines 4235 4471 +236
==========================================
+ Hits 4120 4322 +202
- Misses 115 149 +34
Continue to review full report at Codecov.
|
* split --response-as into --response-mime and --response-charset * add support for Content-Type charset for requests printed to terminal * add support charset detection for requests printed to terminal without a Content-Type charset * etc.
httpie/encoding.py
Outdated
>>> too_short = ']"foo"' | ||
>>> detected = from_bytes(too_short.encode()).best().encoding | ||
>>> detected | ||
'utf_16_be' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know! What has changed?
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s exactly what we needed. Is there still some length threshold below which it’s unreasonable to rely on the detected encoding? Or a way to get some sort of confidence interval for the best match?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe could we require charset_normalizer>=2.0.5
and drop our own TOO_SMALL_SEQUENCE
check?
I am not sure that charset_normalizer >= 2.0.5
is available on all OSes for our package thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I committed d52a483 just to see how it goes.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll revert d52a483 as it seems too new.
Proposal
Content-Type
checks from thePrettyStream
class to theEncodedStream
parent class.--format-option response.as
and--response-as
options.--response-encoding
and--response-mime
options.Fixes #1167.