| 1 |
Examples |
| 2 |
======== |
| 3 |
|
| 4 |
After checking out the code using git you can run: |
| 5 |
|
| 6 |
.. code-block:: console |
| 7 |
|
| 8 |
pip install . dnslib jinja2 starlette wsproto |
| 9 |
|
| 10 |
|
| 11 |
HTTP/3 |
| 12 |
------ |
| 13 |
|
| 14 |
HTTP/3 server |
| 15 |
............. |
| 16 |
|
| 17 |
You can run the example server, which handles both HTTP/0.9 and HTTP/3: |
| 18 |
|
| 19 |
.. code-block:: console |
| 20 |
|
| 21 |
python examples/http3_server.py --certificate tests/ssl_cert.pem --private-key tests/ssl_key.pem |
| 22 |
|
| 23 |
HTTP/3 client |
| 24 |
............. |
| 25 |
|
| 26 |
You can run the example client to perform an HTTP/3 request: |
| 27 |
|
| 28 |
.. code-block:: console |
| 29 |
|
| 30 |
python examples/http3_client.py --ca-certs tests/pycacert.pem https://localhost:4433/ |
| 31 |
|
| 32 |
Alternatively you can perform an HTTP/0.9 request: |
| 33 |
|
| 34 |
.. code-block:: console |
| 35 |
|
| 36 |
python examples/http3_client.py --ca-certs tests/pycacert.pem --legacy-http https://localhost:4433/ |
| 37 |
|
| 38 |
You can also open a WebSocket over HTTP/3: |
| 39 |
|
| 40 |
.. code-block:: console |
| 41 |
|
| 42 |
python examples/http3_client.py --ca-certs tests/pycacert.pem wss://localhost:4433/ws |
| 43 |
|
| 44 |
Chromium and Chrome usage |
| 45 |
......................... |
| 46 |
|
| 47 |
Some flags are needed to allow Chrome to communicate with the demo server. Most are not necessary in a more production-oriented deployment with HTTP/2 fallback and a valid certificate, as demonstrated on https://quic.aiortc.org/ |
| 48 |
|
| 49 |
- The `--ignore-certificate-errors-spki-list`_ instructs Chrome to accept the demo TLS certificate, even though it is not signed by a known certificate authority. If you use your own valid certificate, you do not need this flag. |
| 50 |
- The `--origin-to-force-quic-on` forces Chrome to communicate using HTTP/3. This is needed because the demo server *only* provides an HTTP/3 server. Usually Chrome will connect to an HTTP/2 or HTTP/1.1 server and "discover" the server supports HTTP/3 through an Alt-Svc header. |
| 51 |
- The `--enable-experimental-web-platform-features`_ enables WebTransport, because the specifications and implementation are not yet finalised. For HTTP/3 itself, you do not need this flag. |
| 52 |
|
| 53 |
To access the demo server running on the local machine, launch Chromium or Chrome as follows: |
| 54 |
|
| 55 |
.. code:: bash |
| 56 |
|
| 57 |
google-chrome \ |
| 58 |
--enable-experimental-web-platform-features \ |
| 59 |
--ignore-certificate-errors-spki-list=BSQJ0jkQ7wwhR7KvPZ+DSNk2XTZ/MS6xCbo9qu++VdQ= \ |
| 60 |
--origin-to-force-quic-on=localhost:4433 \ |
| 61 |
https://localhost:4433/ |
| 62 |
|
| 63 |
The fingerprint passed to the `--ignore-certificate-errors-spki-list`_ option is obtained by running: |
| 64 |
|
| 65 |
.. code:: bash |
| 66 |
|
| 67 |
openssl x509 -in tests/ssl_cert.pem -pubkey -noout | \ |
| 68 |
openssl pkey -pubin -outform der | \ |
| 69 |
openssl dgst -sha256 -binary | \ |
| 70 |
openssl enc -base64 |
| 71 |
|
| 72 |
WebTransport |
| 73 |
............ |
| 74 |
|
| 75 |
The demo server runs a :code:`WebTransport` echo service at `/wt`. You can connect by opening Developer Tools and running the following: |
| 76 |
|
| 77 |
.. code:: javascript |
| 78 |
|
| 79 |
let transport = new WebTransport('https://localhost:4433/wt'); |
| 80 |
await transport.ready; |
| 81 |
|
| 82 |
let stream = await transport.createBidirectionalStream(); |
| 83 |
let reader = stream.readable.getReader(); |
| 84 |
let writer = stream.writable.getWriter(); |
| 85 |
|
| 86 |
await writer.write(new Uint8Array([65, 66, 67])); |
| 87 |
let received = await reader.read(); |
| 88 |
await transport.close(); |
| 89 |
|
| 90 |
console.log('received', received); |
| 91 |
|
| 92 |
If all is well you should see: |
| 93 |
|
| 94 |
.. image:: https://user-images.githubusercontent.com/1567624/126713050-e3c0664c-b0b9-4ac8-a393-9b647c9cab6b.png |
| 95 |
|
| 96 |
|
| 97 |
DNS over QUIC |
| 98 |
------------- |
| 99 |
|
| 100 |
By default the server will use the `Google Public DNS`_ service, you can |
| 101 |
override this with the ``--resolver`` argument. |
| 102 |
|
| 103 |
By default the server will listen for requests on port 853, which requires |
| 104 |
a privileged user. You can override this with the `--port` argument. |
| 105 |
|
| 106 |
You can run the server locally using: |
| 107 |
|
| 108 |
.. code-block:: console |
| 109 |
|
| 110 |
python examples/doq_server.py --certificate tests/ssl_cert.pem --private-key tests/ssl_key.pem --port 8053 |
| 111 |
|
| 112 |
You can then run the client with a specific query: |
| 113 |
|
| 114 |
.. code-block:: console |
| 115 |
|
| 116 |
python examples/doq_client.py --ca-certs tests/pycacert.pem --query-type A --query-name quic.aiortc.org --port 8053 |
| 117 |
|
| 118 |
Please note that for real-world usage you will need to obtain a valid TLS certificate. |
| 119 |
|
| 120 |
.. _Google Public DNS: https://developers.google.com/speed/public-dns |
| 121 |
.. _--enable-experimental-web-platform-features: https://peter.sh/experiments/chromium-command-line-switches/#enable-experimental-web-platform-features |
| 122 |
.. _--ignore-certificate-errors-spki-list: https://peter.sh/experiments/chromium-command-line-switches/#ignore-certificate-errors-spki-list |