-
Notifications
You must be signed in to change notification settings - Fork 9.1k
3.0.4: Improved request-response example #3997
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
3.0.4: Improved request-response example #3997
Conversation
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'm pretty sure I'm missing something here with the content-length, but I'm not sure what?
@@ -2036,17 +2036,21 @@ For example, given the following HTTP request: | |||
POST /subscribe/myevent?queryUrl=https://clientdomain.com/stillrunning HTTP/1.1 | |||
Host: example.org | |||
Content-Type: application/json | |||
Content-Length: 187 | |||
Content-Length: 188 |
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'm confused by both numbers- to me it looks like it's 260 if there is a trailing newline (more if the line ends are CRLF):
Python 3.8.13 (default, May 11 2022, 14:42:53)
[Clang 13.1.6 (clang-1316.0.21.2.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x = """{
... "failedUrl" : "https://clientdomain.com/failed",
... "successUrls" : [
... "failedUrl": "https://clientdomain.com/failed",
... "successUrls": [
... "https://clientdomain.com/fast",
... "https://clientdomain.com/medium",
... "https://clientdomain.com/slow"
... ]
... }
... """
>>> x
'{\n "failedUrl" : "https://clientdomain.com/failed",\n "successUrls" : [\n "failedUrl": "https://clientdomain.com/failed",\n "successUrls": [\n "https://clientdomain.com/fast",\n "https://clientdomain.com/medium",\n "https://clientdomain.com/slow"\n ]\n}\n'
>>> len(x)
260
>>>
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.
Funny, I did something similar with Node.js and get 188:
Welcome to Node.js v22.5.1.
Type ".help" for more information.
> var text = `{
... "failedUrl": "https://clientdomain.com/failed",
... "successUrls": [
... "https://clientdomain.com/fast",
... "https://clientdomain.com/medium",
... "https://clientdomain.com/slow"
... ]
... }`
undefined
> text
'{\n' +
' "failedUrl": "https://clientdomain.com/failed",\n' +
' "successUrls": [\n' +
' "https://clientdomain.com/fast",\n' +
' "https://clientdomain.com/medium",\n' +
' "https://clientdomain.com/slow"\n' +
' ]\n' +
'}'
> text.length
188
Which is identical to what my editor shows when I select that text block in the markdown source.
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.
Out of curiosity I repeated the experiment with Python:
Python 3.9.6 (default, Feb 3 2024, 15:58:27)
[Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> text="""{
... "failedUrl": "https://clientdomain.com/failed",
... "successUrls": [
... "https://clientdomain.com/fast",
... "https://clientdomain.com/medium",
... "https://clientdomain.com/slow"
... ]
... }"""
>>> text
'{\n "failedUrl": "https://clientdomain.com/failed",\n "successUrls": [\n "https://clientdomain.com/fast",\n "https://clientdomain.com/medium",\n "https://clientdomain.com/slow"\n ]\n}'
>>> len(text)
188
Which produces the same length of 188 as Node.js.
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.
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 reproduced Ralf's experiment with the same result, so 188 does seem to be the right length. But I think the result of len(text)
in Python is in units of unicode characters, which may not be the length of a UTF-8-encoded response body (though in this case it is). The way to get the length of a string encoded to UTF-8 in Python is
>>> len(text.encode('utf-8'))
188
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.
188 it is! I swear I stared at that and could not figure out what was going on.... sorry to take up your time, folks!
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.
Looks good! 👍
Fixes #1720