Skip to content

Mention curl in contextvars docs #123838

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 2 commits into from
Sep 9, 2024

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Sep 8, 2024

telnet is rather rare in modern setups, I propose to also mention curl usage, that 100% is present on most dev machines.

Result:

» curl --http0.9 127.0.0.1:8081
GET / HTTP/1.1
Host: 127.0.0.1:8081
User-Agent: curl/8.6.0
Accept: */*
Good bye, client @ ('127.0.0.1', 53891)

Without --http0.9 it will produce:

» curl 127.0.0.1:8081
curl: (1) Received HTTP/0.9 when not allowed

@sobolevn sobolevn requested a review from 1st1 as a code owner September 8, 2024 12:04
@bedevere-app bedevere-app bot added awaiting core review docs Documentation in the Doc dir skip news labels Sep 8, 2024
Copy link
Contributor

@itamaro itamaro left a comment

Choose a reason for hiding this comment

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

Makes sense

@sobolevn
Copy link
Member Author

sobolevn commented Sep 8, 2024

The only thing that puzzles me is here, check these two lines:

» curl --http0.9 127.0.0.1:8081
GET / HTTP/1.1

We declare HTTP/1.1 in response. Why do we need --http0.9 option then? I will check that tomorrow.

@picnixz
Copy link
Member

picnixz commented Sep 8, 2024

Alternatively, you can perhaps mention nc? (not sure if it's more present on modern systems or not...)

@sobolevn
Copy link
Member Author

sobolevn commented Sep 8, 2024

This is the first time I hear about nc :)

@picnixz
Copy link
Member

picnixz commented Sep 8, 2024

Oh, nc is for netcat! (am I that old?)

@sobolevn
Copy link
Member Author

sobolevn commented Sep 9, 2024

Ok, I found the problem

  1. This example dumped request parts into response, which caused the http0.9 problem
  2. Now we just write the required response parts manually: status line, headers (empty), body

Bot curl and telnet will now work:

» curl 127.0.0.1:8081
Good bye, client @ ('127.0.0.1', 57051)
» telnet 127.0.0.1 8081
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

HTTP/1.1 200 OK

Good bye, client @ ('127.0.0.1', 57046)
Connection closed by foreign host.

@picnixz nc also works :)

» nc 127.0.0.1 8081

HTTP/1.1 200 OK

Good bye, client @ ('127.0.0.1', 57082)

@picnixz
Copy link
Member

picnixz commented Sep 9, 2024

nc also works :)

If you feel it, maybe we can replace telnet by nc (there is a classic netcat and an OpenBSD one, namely netcat-openbsd which is usually installed by default on most distributions). OTOH, telnet is not necessarily installed by default on all distros (e.g., openSUSE Leap does not bundle telnet by default IIRC).

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@sobolevn sobolevn added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Sep 9, 2024
@sobolevn sobolevn merged commit b950831 into python:main Sep 9, 2024
27 checks passed
@miss-islington-app
Copy link

Thanks @sobolevn for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@sobolevn
Copy link
Member Author

sobolevn commented Sep 9, 2024

Thanks everyone!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 9, 2024
(cherry picked from commit b950831)

Co-authored-by: sobolevn <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Sep 9, 2024

GH-123868 is a backport of this pull request to the 3.13 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 9, 2024
(cherry picked from commit b950831)

Co-authored-by: sobolevn <[email protected]>
@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Sep 9, 2024
@bedevere-app
Copy link

bedevere-app bot commented Sep 9, 2024

GH-123869 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Sep 9, 2024
sobolevn added a commit that referenced this pull request Sep 9, 2024
Mention `curl` in `contextvars` docs (GH-123838)
(cherry picked from commit b950831)

Co-authored-by: sobolevn <[email protected]>
Yhg1s pushed a commit that referenced this pull request Sep 24, 2024
Mention `curl` in `contextvars` docs (GH-123838)
(cherry picked from commit b950831)

Co-authored-by: sobolevn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip issue skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants