@@ -156,7 +156,7 @@ This is not a socket tutorial, so we're not going to dive too deeply into how
156
156
this works. If you want more detail about sockets, there are lots of good
157
157
tutorials on the web that you should investigate.
158
158
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
160
160
address first. So let's do that. Try setting up your file to look like this:
161
161
162
162
.. code-block :: python
@@ -213,11 +213,12 @@ connection object and start handing it data. For now, let's just see what
213
213
happens as we feed it data.
214
214
215
215
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:
221
222
222
223
.. code-block :: console
223
224
@@ -227,6 +228,16 @@ shown below:
227
228
'origin': '10.0.0.2',
228
229
'url': 'https://nghttp2.org/httpbin/get'}
229
230
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
+
230
241
Assuming it works, you're now ready to start sending HTTP/2 data.
231
242
232
243
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:
290
301
handle(sock.accept()[0 ])
291
302
292
303
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
294
307
should then see the following output from your ``h2server.py `` shell:
295
308
296
309
.. code-block :: console
@@ -744,3 +757,4 @@ it, there are a few directions you could investigate:
744
757
.. _get your private key here : https://raw.githubusercontent.com/python-hyper/h2/master/examples/twisted/server.key
745
758
.. _PyOpenSSL : http://pyopenssl.readthedocs.org/
746
759
.. _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