Shorten output where possible#38
Open
dlenski wants to merge 5 commits into
Open
Conversation
The '-A' and '-b' options for these specific headers have been available in curl for a very long time.
The '--json' option was added in curl 7.82, and it implies *both* 'Content-Type: application/json' and 'Accept: application/json'. https://daniel.haxx.se/blog/2022/02/02/curl-dash-dash-json/
Curl defaults to 'Content-Type: application/x-www-form-urlencoded' when -d/--data-raw are specified, so there's no need to repeat this.
This is curl's default behavior with HTTP/1.1, and does nothing with HTTP/2 and newer protocol versions. The other plausible value of this header is 'Connection: close', and should still be provided to curl.
dlenski
commented
May 5, 2026
Comment on lines
+33
to
+35
| if isinstance(body, bytes): | ||
| body = body.decode('utf-8') | ||
| inferred_length = len(body) |
Author
There was a problem hiding this comment.
I'm not sure what the reasonable behavior here is for a non-ASCII string.
On systems with UTF-8 shells, curl will use the UTF-8 string provided by the shell. For example, this will return 7, because the length of the string Hééé encoded as UTF-8 is 7 bytes, and so curl fills in Content-Length: 7 for this payload:
curl -s https://httpbin.org/post -d 'Hééé' | jq '.headers["Content-Length"] | tonumber'But on other systems, the encoding will be different.
If body is bytes or a pure-ASCII string, inferred_length = len(body) is reasonable.
But if body is any other string, the behavior of Python requests (defaults to UTF-8) and curl may differ.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR updates the module to use shorter curl command-line options where they are available and semantically equivalent. All tests are updated to pass, and an optional
modern=Falseoption can be specified to prevent it from using the--jsonoption added in curl 7.82.Document 'pretty' parameter
Use abbreviated options for 'User-Agent' and 'Cookie' headers
The '-A' and '-b' options for these specific headers have been
available in curl for a very long time.
Use '--json', and omit 'Content-Length' when set automatically
The '--json' option was added in curl 7.82, and it implies both
'Content-Type: application/json' and 'Accept: application/json'.
https://daniel.haxx.se/blog/2022/02/02/curl-dash-dash-json/