File: asyncio-example.rst

package info (click to toggle)
python-h2 4.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,652 kB
  • sloc: python: 11,141; makefile: 14; sh: 12
file content (26 lines) | stat: -rw-r--r-- 840 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Asyncio Example Server
======================

This example is a basic HTTP/2 server written using `asyncio`_, using some
functionality that was introduced in Python 3.5. This server represents
basically just the same JSON-headers-returning server that was built in the
:doc:`basic-usage` document.

This example demonstrates some basic asyncio techniques.

.. literalinclude:: ../../examples/asyncio/asyncio-server.py
   :language: python
   :linenos:
   :encoding: utf-8


You can use ``cert.crt`` and ``cert.key`` files provided within the repository
or generate your own certificates using `OpenSSL`_:

.. code-block:: console

   $ openssl req -x509 -newkey rsa:2048 -keyout cert.key -out cert.crt -days 365 -nodes


.. _asyncio: https://docs.python.org/3/library/asyncio.html
.. _OpenSSL: https://openssl-library.org/source/index.html