Skip to content

Commit 13eea71

Browse files
committed
Add note on using curl with http2
1 parent 99fb0ca commit 13eea71

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

docs/source/basic-usage.rst

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ This is not a socket tutorial, so we're not going to dive too deeply into how
156156
this works. If you want more detail about sockets, there are lots of good
157157
tutorials on the web that you should investigate.
158158

159-
When you want to listen for incoming connections, the you need to *bind* an
159+
When you want to listen for incoming connections, you need to *bind* an
160160
address first. So let's do that. Try setting up your file to look like this:
161161

162162
.. code-block:: python
@@ -213,11 +213,12 @@ connection object and start handing it data. For now, let's just see what
213213
happens as we feed it data.
214214

215215
To make HTTP/2 connections, we need a tool that knows how to speak HTTP/2.
216-
Most versions of curl in the wild don't, so let's install a Python tool. In
217-
your Python environment, run ``pip install hyper``. This will install a Python
218-
command-line HTTP/2 tool called ``hyper``. To confirm that it works, try
219-
running this command and verifying that the output looks similar to the one
220-
shown below:
216+
You can simply use `curl`_ or install a Python tool used throughout this
217+
tutorial. In your Python environment, run ``pip install hyper`` (Make sure to
218+
use ``Python < 3.10`` or install it in separate environment). This will
219+
install a Python command-line HTTP/2 tool called ``hyper``. To confirm that
220+
it works, try running this command and verifying that the output looks similar
221+
to the one shown below:
221222

222223
.. code-block:: console
223224
@@ -227,6 +228,16 @@ shown below:
227228
'origin': '10.0.0.2',
228229
'url': 'https://nghttp2.org/httpbin/get'}
229230
231+
Equivalent code with curl would look like this:
232+
233+
.. code-block:: console
234+
235+
$ curl --http2 https://nghttp2.org/httpbin/get
236+
237+
To use it with our server though, you will need to invoke it with a different
238+
``--http2-prior-knowledge`` flag as we are going to serve over the insecure
239+
connection.
240+
230241
Assuming it works, you're now ready to start sending HTTP/2 data.
231242

232243
Back in our ``h2server.py`` script, we're going to want to start handling data.
@@ -290,7 +301,9 @@ function. Your ``h2server.py`` should end up looking a like this:
290301
handle(sock.accept()[0])
291302
292303
Running that in one shell, in your other shell you can run
293-
``hyper --h2 GET http://localhost:8080/``. That shell should hang, and you
304+
``hyper --h2 GET http://localhost:8080/``. For the ``curl`` use
305+
``curl -v --http2-prior-knowledge http://localhost:8080/`` command.
306+
That shell should hang, and you
294307
should then see the following output from your ``h2server.py`` shell:
295308

296309
.. code-block:: console
@@ -744,3 +757,4 @@ it, there are a few directions you could investigate:
744757
.. _get your private key here: https://raw.githubusercontent.com/python-hyper/h2/master/examples/twisted/server.key
745758
.. _PyOpenSSL: http://pyopenssl.readthedocs.org/
746759
.. _Eventlet example: https://github.com/python-hyper/h2/blob/master/examples/eventlet/eventlet-server.py
760+
.. _curl: https://curl.se/docs/http2.html

0 commit comments

Comments
 (0)