2014-03-30 12:09:21 +02:00
|
|
|
nghttp2 - HTTP/2 C Library
|
2014-06-14 15:42:18 +02:00
|
|
|
==========================
|
2012-01-26 17:38:35 +01:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
This is an implementation of the Hypertext Transfer Protocol version 2
|
2014-06-14 15:42:18 +02:00
|
|
|
in C.
|
|
|
|
|
2017-12-17 05:23:37 +01:00
|
|
|
The framing layer of HTTP/2 is implemented as a reusable C library.
|
|
|
|
On top of that, we have implemented an HTTP/2 client, server and
|
|
|
|
proxy. We have also developed load test and benchmarking tools for
|
|
|
|
HTTP/2.
|
2014-06-14 15:42:18 +02:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
An HPACK encoder and decoder are available as a public API.
|
2014-06-14 15:42:18 +02:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
An experimental high level C++ library is also available.
|
2014-09-23 17:25:37 +02:00
|
|
|
|
2015-05-12 03:49:42 +02:00
|
|
|
We have Python bindings of this library, but we do not have full
|
2015-03-16 07:42:19 +01:00
|
|
|
code coverage yet.
|
2012-09-12 15:37:05 +02:00
|
|
|
|
2012-04-25 14:25:51 +02:00
|
|
|
Development Status
|
|
|
|
------------------
|
2012-03-26 16:46:02 +02:00
|
|
|
|
2015-04-28 16:05:00 +02:00
|
|
|
We have implemented `RFC 7540 <https://tools.ietf.org/html/rfc7540>`_
|
2015-04-28 16:06:48 +02:00
|
|
|
HTTP/2 and `RFC 7541 <https://tools.ietf.org/html/rfc7541>`_ HPACK -
|
2015-04-28 16:05:00 +02:00
|
|
|
Header Compression for HTTP/2
|
2013-08-22 20:45:55 +02:00
|
|
|
|
2015-04-05 16:07:42 +02:00
|
|
|
The nghttp2 code base was forked from the spdylay
|
|
|
|
(https://github.com/tatsuhiro-t/spdylay) project.
|
2014-06-14 15:42:18 +02:00
|
|
|
|
2013-08-10 12:06:33 +02:00
|
|
|
Public Test Server
|
|
|
|
------------------
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
The following endpoints are available to try out our nghttp2
|
2014-02-16 07:50:36 +01:00
|
|
|
implementation.
|
2013-08-10 12:06:33 +02:00
|
|
|
|
2021-09-23 05:00:46 +02:00
|
|
|
* https://nghttp2.org/ (TLS + ALPN/NPN and HTTP/3)
|
2013-08-30 17:50:09 +02:00
|
|
|
|
2017-12-17 05:23:37 +01:00
|
|
|
This endpoint supports ``h2``, ``h2-16``, ``h2-14``, and
|
|
|
|
``http/1.1`` via ALPN/NPN and requires TLSv1.2 for HTTP/2
|
2015-02-26 17:02:48 +01:00
|
|
|
connection.
|
2014-06-18 05:13:01 +02:00
|
|
|
|
2021-09-23 05:00:46 +02:00
|
|
|
It also supports HTTP/3.
|
|
|
|
|
2015-04-05 16:07:42 +02:00
|
|
|
* http://nghttp2.org/ (HTTP Upgrade and HTTP/2 Direct)
|
2014-02-16 07:50:36 +01:00
|
|
|
|
2015-04-05 16:07:42 +02:00
|
|
|
``h2c`` and ``http/1.1``.
|
2013-08-10 12:06:33 +02:00
|
|
|
|
2013-07-27 14:56:46 +02:00
|
|
|
Requirements
|
|
|
|
------------
|
2013-07-16 17:08:05 +02:00
|
|
|
|
2014-05-06 16:18:12 +02:00
|
|
|
The following package is required to build the libnghttp2 library:
|
2013-07-19 19:05:07 +02:00
|
|
|
|
2013-07-27 14:56:46 +02:00
|
|
|
* pkg-config >= 0.20
|
2013-07-19 19:05:07 +02:00
|
|
|
|
2014-05-06 16:18:12 +02:00
|
|
|
To build and run the unit test programs, the following package is
|
2013-07-27 14:56:46 +02:00
|
|
|
required:
|
|
|
|
|
|
|
|
* cunit >= 2.1
|
|
|
|
|
2013-09-01 14:53:52 +02:00
|
|
|
To build the documentation, you need to install:
|
|
|
|
|
|
|
|
* sphinx (http://sphinx-doc.org/)
|
|
|
|
|
2016-09-11 06:34:34 +02:00
|
|
|
If you need libnghttp2 (C library) only, then the above packages are
|
|
|
|
all you need. Use ``--enable-lib-only`` to ensure that only
|
|
|
|
libnghttp2 is built. This avoids potential build error related to
|
|
|
|
building bundled applications.
|
|
|
|
|
2016-02-09 07:57:11 +01:00
|
|
|
To build and run the application programs (``nghttp``, ``nghttpd``,
|
|
|
|
``nghttpx`` and ``h2load``) in the ``src`` directory, the following packages
|
|
|
|
are required:
|
2013-07-27 14:56:46 +02:00
|
|
|
|
|
|
|
* OpenSSL >= 1.0.1
|
2016-03-13 12:50:33 +01:00
|
|
|
* libev >= 4.11
|
2014-05-06 16:18:12 +02:00
|
|
|
* zlib >= 1.2.3
|
2016-12-10 13:40:50 +01:00
|
|
|
* libc-ares >= 1.7.5
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2015-03-21 23:16:56 +01:00
|
|
|
ALPN support requires OpenSSL >= 1.0.2 (released 22 January 2015).
|
2015-06-17 11:27:27 +02:00
|
|
|
LibreSSL >= 2.2.0 can be used instead of OpenSSL, but OpenSSL has more
|
2015-06-20 12:02:33 +02:00
|
|
|
features than LibreSSL at the time of this writing.
|
2014-01-02 05:32:43 +01:00
|
|
|
|
2013-07-27 14:56:46 +02:00
|
|
|
To enable ``-a`` option (getting linked assets from the downloaded
|
2014-05-06 16:18:12 +02:00
|
|
|
resource) in ``nghttp``, the following package is required:
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2017-10-04 15:19:25 +02:00
|
|
|
* libxml2 >= 2.6.26
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2017-02-10 09:02:52 +01:00
|
|
|
To enable systemd support in nghttpx, the following package is
|
|
|
|
required:
|
|
|
|
|
|
|
|
* libsystemd-dev >= 209
|
|
|
|
|
2014-01-10 13:53:48 +01:00
|
|
|
The HPACK tools require the following package:
|
2013-10-27 08:23:24 +01:00
|
|
|
|
2014-01-08 17:48:34 +01:00
|
|
|
* jansson >= 2.5
|
2013-10-27 08:23:24 +01:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
To build sources under the examples directory, libevent is required:
|
2015-01-02 13:54:52 +01:00
|
|
|
|
|
|
|
* libevent-openssl >= 2.0.8
|
|
|
|
|
2014-03-05 13:46:26 +01:00
|
|
|
To mitigate heap fragmentation in long running server programs
|
|
|
|
(``nghttpd`` and ``nghttpx``), jemalloc is recommended:
|
|
|
|
|
|
|
|
* jemalloc
|
|
|
|
|
2017-01-03 20:27:03 +01:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
Alpine Linux currently does not support malloc replacement
|
|
|
|
due to musl limitations. See details in issue `#762 <https://github.com/nghttp2/nghttp2/issues/762>`_.
|
|
|
|
|
2014-09-23 17:25:37 +02:00
|
|
|
libnghttp2_asio C++ library requires the following packages:
|
|
|
|
|
2014-09-24 19:08:09 +02:00
|
|
|
* libboost-dev >= 1.54.0
|
|
|
|
* libboost-thread-dev >= 1.54.0
|
2014-09-23 17:25:37 +02:00
|
|
|
|
2014-01-10 17:01:28 +01:00
|
|
|
The Python bindings require the following packages:
|
|
|
|
|
|
|
|
* cython >= 0.19
|
2020-12-29 10:27:07 +01:00
|
|
|
* python >= 3.8
|
2015-07-09 14:12:25 +02:00
|
|
|
* python-setuptools
|
2014-01-10 17:01:28 +01:00
|
|
|
|
2017-02-10 14:21:19 +01:00
|
|
|
If you are using Ubuntu 16.04 LTS (Xenial Xerus) or Debian 8 (jessie)
|
|
|
|
and above, run the following to install the required packages:
|
2016-04-16 11:58:18 +02:00
|
|
|
|
|
|
|
.. code-block:: text
|
2015-01-27 16:58:08 +01:00
|
|
|
|
2015-10-25 03:48:10 +01:00
|
|
|
sudo apt-get install g++ make binutils autoconf automake autotools-dev libtool pkg-config \
|
2015-03-20 16:37:06 +01:00
|
|
|
zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev libjansson-dev \
|
2017-12-17 05:23:37 +01:00
|
|
|
libc-ares-dev libjemalloc-dev libsystemd-dev \
|
2017-02-10 14:21:19 +01:00
|
|
|
cython python3-dev python-setuptools
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2015-09-05 14:39:26 +02:00
|
|
|
To enable mruby support for nghttpx, `mruby
|
|
|
|
<https://github.com/mruby/mruby>`_ is required. We need to build
|
|
|
|
mruby with C++ ABI explicitly turned on, and probably need other
|
|
|
|
mrgems, mruby is manged by git submodule under third-party/mruby
|
|
|
|
directory. Currently, mruby support for nghttpx is disabled by
|
|
|
|
default. To enable mruby support, use ``--with-mruby`` configure
|
2015-09-05 15:46:55 +02:00
|
|
|
option. Note that at the time of this writing, libmruby-dev and mruby
|
|
|
|
packages in Debian/Ubuntu are not usable for nghttp2, since they do
|
2015-09-07 19:37:51 +02:00
|
|
|
not enable C++ ABI. To build mruby, the following packages are
|
|
|
|
required:
|
|
|
|
|
|
|
|
* ruby
|
|
|
|
* bison
|
2015-09-05 14:39:26 +02:00
|
|
|
|
2015-09-26 15:24:44 +02:00
|
|
|
nghttpx supports `neverbleed <https://github.com/h2o/neverbleed>`_,
|
|
|
|
privilege separation engine for OpenSSL / LibreSSL. In short, it
|
|
|
|
minimizes the risk of private key leakage when serious bug like
|
|
|
|
Heartbleed is exploited. The neverbleed is disabled by default. To
|
|
|
|
enable it, use ``--with-neverbleed`` configure option.
|
|
|
|
|
2021-08-22 11:07:52 +02:00
|
|
|
To enable the experimental HTTP/3 support for h2load and nghttpx, the
|
|
|
|
following libraries are required:
|
|
|
|
|
|
|
|
* `OpenSSL with QUIC support
|
2022-05-07 03:54:51 +02:00
|
|
|
<https://github.com/quictls/openssl/tree/OpenSSL_1_1_1o+quic>`_; or
|
2021-10-15 16:24:23 +02:00
|
|
|
`BoringSSL <https://boringssl.googlesource.com/boringssl/>`_ (commit
|
2022-02-23 09:01:00 +01:00
|
|
|
36a41bf0bf2dd3176f8780e09c03585351f29963)
|
2022-05-16 14:10:39 +02:00
|
|
|
* `ngtcp2 <https://github.com/ngtcp2/ngtcp2>`_ >= 0.5.0
|
2022-04-20 14:28:23 +02:00
|
|
|
* `nghttp3 <https://github.com/ngtcp2/nghttp3>`_ >= 0.4.0
|
2021-08-22 11:07:52 +02:00
|
|
|
|
2021-09-17 14:21:42 +02:00
|
|
|
Use ``--enable-http3`` configure option to enable HTTP/3 feature for
|
|
|
|
h2load and nghttpx.
|
|
|
|
|
2021-08-26 15:12:54 +02:00
|
|
|
In order to build optional eBPF program to direct an incoming QUIC UDP
|
|
|
|
datagram to a correct socket for nghttpx, the following libraries are
|
|
|
|
required:
|
|
|
|
|
2022-02-21 13:18:52 +01:00
|
|
|
* libbpf-dev >= 0.7.0
|
2021-08-26 15:12:54 +02:00
|
|
|
|
2021-09-17 14:21:42 +02:00
|
|
|
Use ``--with-libbpf`` configure option to build eBPF program.
|
2021-09-17 16:53:35 +02:00
|
|
|
libelf-dev is needed to build libbpf.
|
2021-09-17 14:21:42 +02:00
|
|
|
|
2021-08-31 12:01:15 +02:00
|
|
|
For Ubuntu 20.04, you can build libbpf from `the source code
|
2022-02-21 13:18:52 +01:00
|
|
|
<https://github.com/libbpf/libbpf/releases/tag/v0.7.0>`_. nghttpx
|
2021-08-31 12:01:15 +02:00
|
|
|
requires eBPF program for reloading its configuration and hot swapping
|
|
|
|
its executable.
|
|
|
|
|
2019-01-21 15:03:10 +01:00
|
|
|
Compiling libnghttp2 C source code requires a C99 compiler. gcc 4.8
|
|
|
|
is known to be adequate. In order to compile the C++ source code, gcc
|
|
|
|
>= 6.0 or clang >= 6.0 is required. C++ source code requires C++14
|
|
|
|
language features.
|
2014-07-18 14:15:28 +02:00
|
|
|
|
2015-09-05 15:46:55 +02:00
|
|
|
.. note::
|
|
|
|
|
2016-12-21 15:34:28 +01:00
|
|
|
To enable mruby support in nghttpx, and use ``--with-mruby``
|
2015-09-05 18:23:11 +02:00
|
|
|
configure option.
|
2015-09-05 15:46:55 +02:00
|
|
|
|
2014-05-21 16:01:21 +02:00
|
|
|
.. note::
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
Mac OS X users may need the ``--disable-threads`` configure option to
|
|
|
|
disable multi-threading in nghttpd, nghttpx and h2load to prevent
|
|
|
|
them from crashing. A patch is welcome to make multi threading work
|
2014-05-21 16:01:21 +02:00
|
|
|
on Mac OS X platform.
|
2014-05-17 15:20:48 +02:00
|
|
|
|
2016-02-09 07:57:11 +01:00
|
|
|
.. note::
|
|
|
|
|
2016-02-13 14:39:24 +01:00
|
|
|
To compile the associated applications (nghttp, nghttpd, nghttpx
|
|
|
|
and h2load), you must use the ``--enable-app`` configure option and
|
|
|
|
ensure that the specified requirements above are met. Normally,
|
|
|
|
configure script checks required dependencies to build these
|
|
|
|
applications, and enable ``--enable-app`` automatically, so you
|
|
|
|
don't have to use it explicitly. But if you found that
|
|
|
|
applications were not built, then using ``--enable-app`` may find
|
|
|
|
that cause, such as the missing dependency.
|
2016-02-09 07:57:11 +01:00
|
|
|
|
2017-03-02 15:08:29 +01:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
In order to detect third party libraries, pkg-config is used
|
|
|
|
(however we don't use pkg-config for some libraries (e.g., libev)).
|
2017-03-12 15:46:21 +01:00
|
|
|
By default, pkg-config searches ``*.pc`` file in the standard
|
|
|
|
locations (e.g., /usr/lib/pkgconfig). If it is necessary to use
|
|
|
|
``*.pc`` file in the custom location, specify paths to
|
|
|
|
``PKG_CONFIG_PATH`` environment variable, and pass it to configure
|
|
|
|
script, like so:
|
2017-03-02 15:08:29 +01:00
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
|
|
|
$ ./configure PKG_CONFIG_PATH=/path/to/pkgconfig
|
|
|
|
|
|
|
|
For pkg-config managed libraries, ``*_CFLAG`` and ``*_LIBS``
|
|
|
|
environment variables are defined (e.g., ``OPENSSL_CFLAGS``,
|
|
|
|
``OPENSSL_LIBS``). Specifying non-empty string to these variables
|
|
|
|
completely overrides pkg-config. In other words, if they are
|
|
|
|
specified, pkg-config is not used for detection, and user is
|
|
|
|
responsible to specify the correct values to these variables. For
|
|
|
|
complete list of these variables, run ``./configure -h``.
|
|
|
|
|
2017-04-06 13:13:00 +02:00
|
|
|
Building nghttp2 from release tar archive
|
|
|
|
-----------------------------------------
|
|
|
|
|
|
|
|
The nghttp2 project regularly releases tar archives which includes
|
|
|
|
nghttp2 source code, and generated build files. They can be
|
2017-04-06 13:14:49 +02:00
|
|
|
downloaded from `Releases
|
|
|
|
<https://github.com/nghttp2/nghttp2/releases>`_ page.
|
2017-04-06 13:13:00 +02:00
|
|
|
|
|
|
|
Building nghttp2 from git requires autotools development packages.
|
|
|
|
Building from tar archives does not require them, and thus it is much
|
|
|
|
easier. The usual build step is as follows:
|
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
|
|
|
$ tar xf nghttp2-X.Y.Z.tar.bz2
|
|
|
|
$ cd nghttp2-X.Y.Z
|
|
|
|
$ ./configure
|
|
|
|
$ make
|
|
|
|
|
|
|
|
Building from git
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
Building from git is easy, but please be sure that at least autoconf 2.68 is
|
|
|
|
used:
|
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
|
|
|
$ git submodule update --init
|
|
|
|
$ autoreconf -i
|
|
|
|
$ automake
|
|
|
|
$ autoconf
|
|
|
|
$ ./configure
|
|
|
|
$ make
|
|
|
|
|
2016-07-07 16:26:15 +02:00
|
|
|
Notes for building on Windows (MSVC)
|
|
|
|
------------------------------------
|
|
|
|
|
2016-07-16 05:51:04 +02:00
|
|
|
The easiest way to build native Windows nghttp2 dll is use `cmake
|
|
|
|
<https://cmake.org/>`_. The free version of `Visual C++ Build Tools
|
|
|
|
<http://landinghub.visualstudio.com/visual-cpp-build-tools>`_ works
|
|
|
|
fine.
|
2016-07-07 16:26:15 +02:00
|
|
|
|
|
|
|
1. Install cmake for windows
|
|
|
|
2. Open "Visual C++ ... Native Build Tool Command Prompt", and inside
|
|
|
|
nghttp2 directly, run ``cmake``.
|
|
|
|
3. Then run ``cmake --build`` to build library.
|
|
|
|
4. nghttp2.dll, nghttp2.lib, nghttp2.exp are placed under lib directory.
|
|
|
|
|
|
|
|
Note that the above steps most likely produce nghttp2 library only.
|
|
|
|
No bundled applications are compiled.
|
|
|
|
|
2015-03-30 12:29:10 +02:00
|
|
|
Notes for building on Windows (Mingw/Cygwin)
|
2015-03-31 14:32:25 +02:00
|
|
|
--------------------------------------------
|
2015-03-30 12:29:10 +02:00
|
|
|
|
2015-03-31 14:32:25 +02:00
|
|
|
Under Mingw environment, you can only compile the library, it's
|
|
|
|
``libnghttp2-X.dll`` and ``libnghttp2.a``.
|
2015-03-30 12:29:10 +02:00
|
|
|
|
2015-03-31 14:32:25 +02:00
|
|
|
If you want to compile the applications(``h2load``, ``nghttp``,
|
|
|
|
``nghttpx``, ``nghttpd``), you need to use the Cygwin environment.
|
2015-03-30 12:29:10 +02:00
|
|
|
|
2015-03-31 14:32:25 +02:00
|
|
|
Under Cygwin environment, to compile the applications you need to
|
|
|
|
compile and install the libev first.
|
2015-03-30 12:29:10 +02:00
|
|
|
|
2015-03-31 14:32:25 +02:00
|
|
|
Secondly, you need to undefine the macro ``__STRICT_ANSI__``, if you
|
|
|
|
not, the functions ``fdopen``, ``fileno`` and ``strptime`` will not
|
|
|
|
available.
|
2015-03-30 12:29:10 +02:00
|
|
|
|
2016-04-16 11:58:18 +02:00
|
|
|
the sample command like this:
|
|
|
|
|
|
|
|
.. code-block:: text
|
2015-03-30 12:29:10 +02:00
|
|
|
|
2015-03-31 14:32:25 +02:00
|
|
|
$ export CFLAGS="-U__STRICT_ANSI__ -I$libev_PREFIX/include -L$libev_PREFIX/lib"
|
|
|
|
$ export CXXFLAGS=$CFLAGS
|
|
|
|
$ ./configure
|
|
|
|
$ make
|
2015-03-30 12:29:10 +02:00
|
|
|
|
2015-03-31 14:32:25 +02:00
|
|
|
If you want to compile the applications under ``examples/``, you need
|
|
|
|
to remove or rename the ``event.h`` from libev's installation, because
|
|
|
|
it conflicts with libevent's installation.
|
2015-03-30 12:29:10 +02:00
|
|
|
|
2017-05-12 17:34:19 +02:00
|
|
|
Notes for installation on Linux systems
|
|
|
|
--------------------------------------------
|
|
|
|
After installing nghttp2 tool suite with ``make install`` one might experience a similar error:
|
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
|
|
|
nghttpx: error while loading shared libraries: libnghttp2.so.14: cannot open shared object file: No such file or directory
|
|
|
|
|
|
|
|
This means that the tool is unable to locate the ``libnghttp2.so`` shared library.
|
|
|
|
|
|
|
|
To update the shared library cache run ``sudo ldconfig``.
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
Building the documentation
|
|
|
|
--------------------------
|
2013-07-27 14:56:46 +02:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
Documentation is still incomplete.
|
|
|
|
|
2016-04-16 11:58:18 +02:00
|
|
|
To build the documentation, run:
|
|
|
|
|
|
|
|
.. code-block:: text
|
2013-07-27 14:56:46 +02:00
|
|
|
|
|
|
|
$ make html
|
|
|
|
|
|
|
|
The documents will be generated under ``doc/manual/html/``.
|
|
|
|
|
|
|
|
The generated documents will not be installed with ``make install``.
|
|
|
|
|
2013-07-28 16:00:12 +02:00
|
|
|
The online documentation is available at
|
2014-05-14 17:11:40 +02:00
|
|
|
https://nghttp2.org/documentation/
|
2013-07-28 16:00:12 +02:00
|
|
|
|
2021-09-17 16:53:35 +02:00
|
|
|
Build HTTP/3 enabled h2load and nghttpx
|
|
|
|
---------------------------------------
|
|
|
|
|
|
|
|
To build h2load and nghttpx with HTTP/3 feature enabled, run the
|
|
|
|
configure script with ``--enable-http3``.
|
|
|
|
|
|
|
|
For nghttpx to reload configurations and swapping its executable while
|
|
|
|
gracefully terminating old worker processes, eBPF is required. Run
|
|
|
|
the configure script with ``--enable-http3 --with-libbpf`` to build
|
2021-09-22 11:24:50 +02:00
|
|
|
eBPF program. The QUIC keying material must be set with
|
|
|
|
``--frontend-quic-secret-file`` in order to keep the existing
|
|
|
|
connections alive during reload.
|
2021-09-17 16:53:35 +02:00
|
|
|
|
|
|
|
The detailed steps to build HTTP/3 enabled h2load and nghttpx follow.
|
|
|
|
|
|
|
|
Build custom OpenSSL:
|
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
2022-05-07 03:54:51 +02:00
|
|
|
$ git clone --depth 1 -b OpenSSL_1_1_1o+quic https://github.com/quictls/openssl
|
2021-09-17 16:53:35 +02:00
|
|
|
$ cd openssl
|
|
|
|
$ ./config --prefix=$PWD/build --openssldir=/etc/ssl
|
|
|
|
$ make -j$(nproc)
|
|
|
|
$ make install_sw
|
|
|
|
$ cd ..
|
|
|
|
|
|
|
|
Build nghttp3:
|
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
2022-05-16 14:10:39 +02:00
|
|
|
$ git clone --depth 1 -b v0.4.1 https://github.com/ngtcp2/nghttp3
|
2021-09-17 16:53:35 +02:00
|
|
|
$ cd nghttp3
|
|
|
|
$ autoreconf -i
|
|
|
|
$ ./configure --prefix=$PWD/build --enable-lib-only
|
|
|
|
$ make -j$(nproc)
|
|
|
|
$ make install
|
|
|
|
$ cd ..
|
|
|
|
|
|
|
|
Build ngtcp2:
|
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
2022-05-16 14:10:39 +02:00
|
|
|
$ git clone --depth 1 -b v0.5.0 https://github.com/ngtcp2/ngtcp2
|
2021-09-17 16:53:35 +02:00
|
|
|
$ cd ngtcp2
|
|
|
|
$ autoreconf -i
|
|
|
|
$ ./configure --prefix=$PWD/build --enable-lib-only \
|
|
|
|
PKG_CONFIG_PATH="$PWD/../openssl/build/lib/pkgconfig"
|
|
|
|
$ make -j$(nproc)
|
|
|
|
$ make install
|
|
|
|
$ cd ..
|
|
|
|
|
2022-02-21 13:18:52 +01:00
|
|
|
If your Linux distribution does not have libbpf-dev >= 0.7.0, build
|
2021-09-17 16:53:35 +02:00
|
|
|
from source:
|
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
2022-02-21 13:18:52 +01:00
|
|
|
$ git clone --depth 1 -b v0.7.0 https://github.com/libbpf/libbpf
|
2021-09-17 16:53:35 +02:00
|
|
|
$ cd libbpf
|
|
|
|
$ PREFIX=$PWD/build make -C src install
|
|
|
|
$ cd ..
|
|
|
|
|
|
|
|
Build nghttp2:
|
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
|
|
|
$ git clone https://github.com/nghttp2/nghttp2
|
|
|
|
$ cd nghttp2
|
|
|
|
$ git submodule update --init
|
|
|
|
$ autoreconf -i
|
|
|
|
$ ./configure --with-mruby --with-neverbleed --enable-http3 --with-libbpf \
|
|
|
|
--disable-python-bindings \
|
2022-02-23 09:08:04 +01:00
|
|
|
CC=clang-12 CXX=clang++-12 \
|
2021-09-17 16:53:35 +02:00
|
|
|
PKG_CONFIG_PATH="$PWD/../openssl/build/lib/pkgconfig:$PWD/../nghttp3/build/lib/pkgconfig:$PWD/../ngtcp2/build/lib/pkgconfig:$PWD/../libbpf/build/lib64/pkgconfig" \
|
|
|
|
LDFLAGS="$LDFLAGS -Wl,-rpath,$PWD/../openssl/build/lib -Wl,-rpath,$PWD/../libbpf/build/lib64"
|
|
|
|
$ make -j$(nproc)
|
|
|
|
|
|
|
|
The eBPF program ``reuseport_kern.o`` should be found under bpf
|
|
|
|
directory. Pass ``--quic-bpf-program-file=bpf/reuseport_kern.o``
|
|
|
|
option to nghttpx to load it. See also `HTTP/3 section in nghttpx -
|
|
|
|
HTTP/2 proxy - HOW-TO
|
|
|
|
<https://nghttp2.org/documentation/nghttpx-howto.html#http-3>`_.
|
|
|
|
|
2015-01-19 16:45:51 +01:00
|
|
|
Unit tests
|
|
|
|
----------
|
|
|
|
|
2015-10-29 15:13:11 +01:00
|
|
|
Unit tests are done by simply running ``make check``.
|
2015-01-19 16:45:51 +01:00
|
|
|
|
|
|
|
Integration tests
|
|
|
|
-----------------
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
We have the integration tests for the nghttpx proxy server. The tests are
|
|
|
|
written in the `Go programming language <http://golang.org/>`_ and uses
|
2015-01-21 05:54:22 +01:00
|
|
|
its testing framework. We depend on the following libraries:
|
2015-01-19 16:45:51 +01:00
|
|
|
|
2015-10-08 17:08:54 +02:00
|
|
|
* golang.org/x/net/http2
|
|
|
|
* golang.org/x/net/websocket
|
2015-01-19 16:45:51 +01:00
|
|
|
* https://github.com/tatsuhiro-t/go-nghttp2
|
|
|
|
|
2019-06-07 16:49:46 +02:00
|
|
|
Go modules will download these dependencies automatically.
|
2015-01-23 17:05:20 +01:00
|
|
|
|
|
|
|
To run the tests, run the following command under
|
2016-04-16 11:58:18 +02:00
|
|
|
``integration-tests`` directory:
|
|
|
|
|
|
|
|
.. code-block:: text
|
2015-01-19 16:45:51 +01:00
|
|
|
|
2015-01-19 17:14:22 +01:00
|
|
|
$ make it
|
2015-01-19 16:45:51 +01:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
Inside the tests, we use port 3009 to run the test subject server.
|
2015-01-19 16:45:51 +01:00
|
|
|
|
2015-05-15 17:15:00 +02:00
|
|
|
Migration from v0.7.15 or earlier
|
|
|
|
---------------------------------
|
2015-04-05 16:53:19 +02:00
|
|
|
|
|
|
|
nghttp2 v1.0.0 introduced several backward incompatible changes. In
|
|
|
|
this section, we describe these changes and how to migrate to v1.0.0.
|
|
|
|
|
|
|
|
ALPN protocol ID is now ``h2`` and ``h2c``
|
|
|
|
++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
Previously we announced ``h2-14`` and ``h2c-14``. v1.0.0 implements
|
|
|
|
final protocol version, and we changed ALPN ID to ``h2`` and ``h2c``.
|
|
|
|
The macros ``NGHTTP2_PROTO_VERSION_ID``,
|
|
|
|
``NGHTTP2_PROTO_VERSION_ID_LEN``,
|
|
|
|
``NGHTTP2_CLEARTEXT_PROTO_VERSION_ID``, and
|
|
|
|
``NGHTTP2_CLEARTEXT_PROTO_VERSION_ID_LEN`` have been updated to
|
|
|
|
reflect this change.
|
|
|
|
|
|
|
|
Basically, existing applications do not have to do anything, just
|
|
|
|
recompiling is enough for this change.
|
|
|
|
|
|
|
|
Use word "client magic" where we use "client connection preface"
|
|
|
|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
We use "client connection preface" to mean first 24 bytes of client
|
|
|
|
connection preface. This is technically not correct, since client
|
|
|
|
connection preface is composed of 24 bytes client magic byte string
|
|
|
|
followed by SETTINGS frame. For clarification, we call "client magic"
|
|
|
|
for this 24 bytes byte string and updated API.
|
|
|
|
|
|
|
|
* ``NGHTTP2_CLIENT_CONNECTION_PREFACE`` was replaced with
|
|
|
|
``NGHTTP2_CLIENT_MAGIC``.
|
|
|
|
* ``NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN`` was replaced with
|
|
|
|
``NGHTTP2_CLIENT_MAGIC_LEN``.
|
|
|
|
* ``NGHTTP2_BAD_PREFACE`` was renamed as ``NGHTTP2_BAD_CLIENT_MAGIC``
|
|
|
|
|
2016-01-05 14:14:54 +01:00
|
|
|
The already deprecated ``NGHTTP2_CLIENT_CONNECTION_HEADER`` and
|
2015-04-05 16:53:19 +02:00
|
|
|
``NGHTTP2_CLIENT_CONNECTION_HEADER_LEN`` were removed.
|
|
|
|
|
|
|
|
If application uses these macros, just replace old ones with new ones.
|
|
|
|
Since v1.0.0, client magic is sent by library (see next subsection),
|
|
|
|
so client application may just remove these macro use.
|
|
|
|
|
|
|
|
Client magic is sent by library
|
|
|
|
+++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
Previously nghttp2 library did not send client magic, which is first
|
|
|
|
24 bytes byte string of client connection preface, and client
|
|
|
|
applications have to send it by themselves. Since v1.0.0, client
|
|
|
|
magic is sent by library via first call of ``nghttp2_session_send()``
|
|
|
|
or ``nghttp2_session_mem_send()``.
|
|
|
|
|
|
|
|
The client applications which send client magic must remove the
|
|
|
|
relevant code.
|
|
|
|
|
|
|
|
Remove HTTP Alternative Services (Alt-Svc) related code
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
Alt-Svc specification is not finalized yet. To make our API stable,
|
|
|
|
we have decided to remove all Alt-Svc related API from nghttp2.
|
|
|
|
|
|
|
|
* ``NGHTTP2_EXT_ALTSVC`` was removed.
|
|
|
|
* ``nghttp2_ext_altsvc`` was removed.
|
|
|
|
|
|
|
|
We have already removed the functionality of Alt-Svc in v0.7 series
|
|
|
|
and they have been essentially noop. The application using these
|
|
|
|
macro and struct, remove those lines.
|
|
|
|
|
|
|
|
Use nghttp2_error in nghttp2_on_invalid_frame_recv_callback
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
Previously ``nghttp2_on_invalid_frame_recv_cb_called`` took the
|
|
|
|
``error_code``, defined in ``nghttp2_error_code``, as parameter. But
|
|
|
|
they are not detailed enough to debug. Therefore, we decided to use
|
|
|
|
more detailed ``nghttp2_error`` values instead.
|
|
|
|
|
|
|
|
The application using this callback should update the callback
|
|
|
|
signature. If it treats ``error_code`` as HTTP/2 error code, update
|
|
|
|
the code so that it is treated as ``nghttp2_error``.
|
|
|
|
|
|
|
|
Receive client magic by default
|
|
|
|
+++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
Previously nghttp2 did not process client magic (24 bytes byte
|
|
|
|
string). To make it deal with it, we had to use
|
|
|
|
``nghttp2_option_set_recv_client_preface()``. Since v1.0.0, nghttp2
|
|
|
|
processes client magic by default and
|
|
|
|
``nghttp2_option_set_recv_client_preface()`` was removed.
|
|
|
|
|
|
|
|
Some application may want to disable this behaviour, so we added
|
|
|
|
``nghttp2_option_set_no_recv_client_magic()`` to achieve this.
|
|
|
|
|
|
|
|
The application using ``nghttp2_option_set_recv_client_preface()``
|
|
|
|
with nonzero value, just remove it.
|
|
|
|
|
|
|
|
The application using ``nghttp2_option_set_recv_client_preface()``
|
|
|
|
with zero value or not using it must use
|
|
|
|
``nghttp2_option_set_no_recv_client_magic()`` with nonzero value.
|
|
|
|
|
2013-07-27 14:56:46 +02:00
|
|
|
Client, Server and Proxy programs
|
|
|
|
---------------------------------
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
The ``src`` directory contains the HTTP/2 client, server and proxy programs.
|
2013-07-27 14:56:46 +02:00
|
|
|
|
|
|
|
nghttp - client
|
|
|
|
+++++++++++++++
|
|
|
|
|
2014-04-08 16:12:02 +02:00
|
|
|
``nghttp`` is a HTTP/2 client. It can connect to the HTTP/2 server
|
2014-01-01 17:00:11 +01:00
|
|
|
with prior knowledge, HTTP Upgrade and NPN/ALPN TLS extension.
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2014-04-08 16:12:02 +02:00
|
|
|
It has verbose output mode for framing information. Here is sample
|
2016-04-16 11:58:18 +02:00
|
|
|
output from ``nghttp`` client:
|
|
|
|
|
|
|
|
.. code-block:: text
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2015-02-01 10:08:21 +01:00
|
|
|
$ nghttp -nv https://nghttp2.org
|
2015-05-21 18:40:23 +02:00
|
|
|
[ 0.190] Connected
|
2015-04-05 16:07:42 +02:00
|
|
|
The negotiated protocol: h2
|
2015-05-21 18:40:23 +02:00
|
|
|
[ 0.212] recv SETTINGS frame <length=12, flags=0x00, stream_id=0>
|
|
|
|
(niv=2)
|
|
|
|
[SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
|
|
|
|
[SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
|
|
|
|
[ 0.212] send SETTINGS frame <length=12, flags=0x00, stream_id=0>
|
|
|
|
(niv=2)
|
|
|
|
[SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
|
|
|
|
[SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
|
|
|
|
[ 0.212] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
|
|
|
|
; ACK
|
|
|
|
(niv=0)
|
|
|
|
[ 0.212] send PRIORITY frame <length=5, flags=0x00, stream_id=3>
|
|
|
|
(dep_stream_id=0, weight=201, exclusive=0)
|
|
|
|
[ 0.212] send PRIORITY frame <length=5, flags=0x00, stream_id=5>
|
|
|
|
(dep_stream_id=0, weight=101, exclusive=0)
|
|
|
|
[ 0.212] send PRIORITY frame <length=5, flags=0x00, stream_id=7>
|
|
|
|
(dep_stream_id=0, weight=1, exclusive=0)
|
|
|
|
[ 0.212] send PRIORITY frame <length=5, flags=0x00, stream_id=9>
|
|
|
|
(dep_stream_id=7, weight=1, exclusive=0)
|
|
|
|
[ 0.212] send PRIORITY frame <length=5, flags=0x00, stream_id=11>
|
|
|
|
(dep_stream_id=3, weight=1, exclusive=0)
|
|
|
|
[ 0.212] send HEADERS frame <length=39, flags=0x25, stream_id=13>
|
|
|
|
; END_STREAM | END_HEADERS | PRIORITY
|
|
|
|
(padlen=0, dep_stream_id=11, weight=16, exclusive=0)
|
|
|
|
; Open new stream
|
|
|
|
:method: GET
|
|
|
|
:path: /
|
|
|
|
:scheme: https
|
|
|
|
:authority: nghttp2.org
|
|
|
|
accept: */*
|
|
|
|
accept-encoding: gzip, deflate
|
|
|
|
user-agent: nghttp2/1.0.1-DEV
|
|
|
|
[ 0.221] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
|
|
|
|
; ACK
|
|
|
|
(niv=0)
|
|
|
|
[ 0.221] recv (stream_id=13) :method: GET
|
|
|
|
[ 0.221] recv (stream_id=13) :scheme: https
|
|
|
|
[ 0.221] recv (stream_id=13) :path: /stylesheets/screen.css
|
|
|
|
[ 0.221] recv (stream_id=13) :authority: nghttp2.org
|
|
|
|
[ 0.221] recv (stream_id=13) accept-encoding: gzip, deflate
|
|
|
|
[ 0.222] recv (stream_id=13) user-agent: nghttp2/1.0.1-DEV
|
|
|
|
[ 0.222] recv PUSH_PROMISE frame <length=50, flags=0x04, stream_id=13>
|
|
|
|
; END_HEADERS
|
|
|
|
(padlen=0, promised_stream_id=2)
|
|
|
|
[ 0.222] recv (stream_id=13) :status: 200
|
|
|
|
[ 0.222] recv (stream_id=13) date: Thu, 21 May 2015 16:38:14 GMT
|
|
|
|
[ 0.222] recv (stream_id=13) content-type: text/html
|
|
|
|
[ 0.222] recv (stream_id=13) last-modified: Fri, 15 May 2015 15:38:06 GMT
|
|
|
|
[ 0.222] recv (stream_id=13) etag: W/"555612de-19f6"
|
|
|
|
[ 0.222] recv (stream_id=13) link: </stylesheets/screen.css>; rel=preload; as=stylesheet
|
|
|
|
[ 0.222] recv (stream_id=13) content-encoding: gzip
|
|
|
|
[ 0.222] recv (stream_id=13) server: nghttpx nghttp2/1.0.1-DEV
|
|
|
|
[ 0.222] recv (stream_id=13) via: 1.1 nghttpx
|
|
|
|
[ 0.222] recv (stream_id=13) strict-transport-security: max-age=31536000
|
|
|
|
[ 0.222] recv HEADERS frame <length=166, flags=0x04, stream_id=13>
|
|
|
|
; END_HEADERS
|
|
|
|
(padlen=0)
|
|
|
|
; First response header
|
|
|
|
[ 0.222] recv DATA frame <length=2601, flags=0x01, stream_id=13>
|
|
|
|
; END_STREAM
|
|
|
|
[ 0.222] recv (stream_id=2) :status: 200
|
|
|
|
[ 0.222] recv (stream_id=2) date: Thu, 21 May 2015 16:38:14 GMT
|
|
|
|
[ 0.222] recv (stream_id=2) content-type: text/css
|
|
|
|
[ 0.222] recv (stream_id=2) last-modified: Fri, 15 May 2015 15:38:06 GMT
|
|
|
|
[ 0.222] recv (stream_id=2) etag: W/"555612de-9845"
|
|
|
|
[ 0.222] recv (stream_id=2) content-encoding: gzip
|
|
|
|
[ 0.222] recv (stream_id=2) server: nghttpx nghttp2/1.0.1-DEV
|
|
|
|
[ 0.222] recv (stream_id=2) via: 1.1 nghttpx
|
|
|
|
[ 0.222] recv (stream_id=2) strict-transport-security: max-age=31536000
|
|
|
|
[ 0.222] recv HEADERS frame <length=32, flags=0x04, stream_id=2>
|
|
|
|
; END_HEADERS
|
|
|
|
(padlen=0)
|
|
|
|
; First push response header
|
|
|
|
[ 0.228] recv DATA frame <length=8715, flags=0x01, stream_id=2>
|
|
|
|
; END_STREAM
|
|
|
|
[ 0.228] send GOAWAY frame <length=8, flags=0x00, stream_id=0>
|
|
|
|
(last_stream_id=2, error_code=NO_ERROR(0x00), opaque_data(0)=[])
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2016-04-16 11:58:18 +02:00
|
|
|
The HTTP Upgrade is performed like so:
|
|
|
|
|
|
|
|
.. code-block:: text
|
2013-08-03 12:44:13 +02:00
|
|
|
|
2015-02-01 10:08:21 +01:00
|
|
|
$ nghttp -nvu http://nghttp2.org
|
2015-05-21 18:40:23 +02:00
|
|
|
[ 0.011] Connected
|
|
|
|
[ 0.011] HTTP Upgrade request
|
2013-08-03 12:44:13 +02:00
|
|
|
GET / HTTP/1.1
|
2014-05-14 17:27:24 +02:00
|
|
|
Host: nghttp2.org
|
2013-08-03 12:44:13 +02:00
|
|
|
Connection: Upgrade, HTTP2-Settings
|
2015-05-15 16:55:30 +02:00
|
|
|
Upgrade: h2c
|
|
|
|
HTTP2-Settings: AAMAAABkAAQAAP__
|
2013-08-03 12:44:13 +02:00
|
|
|
Accept: */*
|
2015-05-21 18:40:23 +02:00
|
|
|
User-Agent: nghttp2/1.0.1-DEV
|
2013-08-03 12:44:13 +02:00
|
|
|
|
|
|
|
|
2015-05-21 18:40:23 +02:00
|
|
|
[ 0.018] HTTP Upgrade response
|
2013-08-03 12:44:13 +02:00
|
|
|
HTTP/1.1 101 Switching Protocols
|
|
|
|
Connection: Upgrade
|
2015-05-15 16:55:30 +02:00
|
|
|
Upgrade: h2c
|
2013-08-03 12:44:13 +02:00
|
|
|
|
|
|
|
|
2015-05-21 18:40:23 +02:00
|
|
|
[ 0.018] HTTP Upgrade success
|
|
|
|
[ 0.018] recv SETTINGS frame <length=12, flags=0x00, stream_id=0>
|
|
|
|
(niv=2)
|
|
|
|
[SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
|
|
|
|
[SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
|
|
|
|
[ 0.018] send SETTINGS frame <length=12, flags=0x00, stream_id=0>
|
|
|
|
(niv=2)
|
|
|
|
[SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
|
|
|
|
[SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
|
|
|
|
[ 0.018] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
|
|
|
|
; ACK
|
|
|
|
(niv=0)
|
|
|
|
[ 0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=3>
|
|
|
|
(dep_stream_id=0, weight=201, exclusive=0)
|
|
|
|
[ 0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=5>
|
|
|
|
(dep_stream_id=0, weight=101, exclusive=0)
|
|
|
|
[ 0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=7>
|
|
|
|
(dep_stream_id=0, weight=1, exclusive=0)
|
|
|
|
[ 0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=9>
|
|
|
|
(dep_stream_id=7, weight=1, exclusive=0)
|
|
|
|
[ 0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=11>
|
|
|
|
(dep_stream_id=3, weight=1, exclusive=0)
|
|
|
|
[ 0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=1>
|
|
|
|
(dep_stream_id=11, weight=16, exclusive=0)
|
|
|
|
[ 0.019] recv (stream_id=1) :method: GET
|
|
|
|
[ 0.019] recv (stream_id=1) :scheme: http
|
|
|
|
[ 0.019] recv (stream_id=1) :path: /stylesheets/screen.css
|
|
|
|
[ 0.019] recv (stream_id=1) host: nghttp2.org
|
|
|
|
[ 0.019] recv (stream_id=1) user-agent: nghttp2/1.0.1-DEV
|
|
|
|
[ 0.019] recv PUSH_PROMISE frame <length=49, flags=0x04, stream_id=1>
|
|
|
|
; END_HEADERS
|
|
|
|
(padlen=0, promised_stream_id=2)
|
|
|
|
[ 0.019] recv (stream_id=1) :status: 200
|
|
|
|
[ 0.019] recv (stream_id=1) date: Thu, 21 May 2015 16:39:16 GMT
|
|
|
|
[ 0.019] recv (stream_id=1) content-type: text/html
|
|
|
|
[ 0.019] recv (stream_id=1) content-length: 6646
|
|
|
|
[ 0.019] recv (stream_id=1) last-modified: Fri, 15 May 2015 15:38:06 GMT
|
|
|
|
[ 0.019] recv (stream_id=1) etag: "555612de-19f6"
|
|
|
|
[ 0.019] recv (stream_id=1) link: </stylesheets/screen.css>; rel=preload; as=stylesheet
|
|
|
|
[ 0.019] recv (stream_id=1) accept-ranges: bytes
|
|
|
|
[ 0.019] recv (stream_id=1) server: nghttpx nghttp2/1.0.1-DEV
|
|
|
|
[ 0.019] recv (stream_id=1) via: 1.1 nghttpx
|
|
|
|
[ 0.019] recv HEADERS frame <length=157, flags=0x04, stream_id=1>
|
|
|
|
; END_HEADERS
|
|
|
|
(padlen=0)
|
|
|
|
; First response header
|
|
|
|
[ 0.019] recv DATA frame <length=6646, flags=0x01, stream_id=1>
|
|
|
|
; END_STREAM
|
|
|
|
[ 0.019] recv (stream_id=2) :status: 200
|
|
|
|
[ 0.019] recv (stream_id=2) date: Thu, 21 May 2015 16:39:16 GMT
|
|
|
|
[ 0.019] recv (stream_id=2) content-type: text/css
|
|
|
|
[ 0.019] recv (stream_id=2) content-length: 38981
|
|
|
|
[ 0.019] recv (stream_id=2) last-modified: Fri, 15 May 2015 15:38:06 GMT
|
|
|
|
[ 0.019] recv (stream_id=2) etag: "555612de-9845"
|
|
|
|
[ 0.019] recv (stream_id=2) accept-ranges: bytes
|
|
|
|
[ 0.019] recv (stream_id=2) server: nghttpx nghttp2/1.0.1-DEV
|
|
|
|
[ 0.019] recv (stream_id=2) via: 1.1 nghttpx
|
|
|
|
[ 0.019] recv HEADERS frame <length=36, flags=0x04, stream_id=2>
|
|
|
|
; END_HEADERS
|
|
|
|
(padlen=0)
|
|
|
|
; First push response header
|
|
|
|
[ 0.026] recv DATA frame <length=16384, flags=0x00, stream_id=2>
|
|
|
|
[ 0.027] recv DATA frame <length=7952, flags=0x00, stream_id=2>
|
|
|
|
[ 0.027] send WINDOW_UPDATE frame <length=4, flags=0x00, stream_id=0>
|
|
|
|
(window_size_increment=33343)
|
|
|
|
[ 0.032] send WINDOW_UPDATE frame <length=4, flags=0x00, stream_id=2>
|
|
|
|
(window_size_increment=33707)
|
|
|
|
[ 0.032] recv DATA frame <length=14645, flags=0x01, stream_id=2>
|
|
|
|
; END_STREAM
|
|
|
|
[ 0.032] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
|
|
|
|
; ACK
|
|
|
|
(niv=0)
|
|
|
|
[ 0.032] send GOAWAY frame <length=8, flags=0x00, stream_id=0>
|
|
|
|
(last_stream_id=2, error_code=NO_ERROR(0x00), opaque_data(0)=[])
|
2013-08-03 12:44:13 +02:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
Using the ``-s`` option, ``nghttp`` prints out some timing information for
|
2016-04-16 11:58:18 +02:00
|
|
|
requests, sorted by completion time:
|
|
|
|
|
|
|
|
.. code-block:: text
|
2015-02-01 10:08:21 +01:00
|
|
|
|
|
|
|
$ nghttp -nas https://nghttp2.org/
|
|
|
|
***** Statistics *****
|
|
|
|
|
|
|
|
Request timing:
|
2015-05-15 16:55:30 +02:00
|
|
|
responseEnd: the time when last byte of response was received
|
|
|
|
relative to connectEnd
|
|
|
|
requestStart: the time just before first byte of request was sent
|
|
|
|
relative to connectEnd. If '*' is shown, this was
|
|
|
|
pushed by server.
|
|
|
|
process: responseEnd - requestStart
|
|
|
|
code: HTTP status code
|
|
|
|
size: number of bytes received as response body without
|
|
|
|
inflation.
|
|
|
|
URI: request URI
|
|
|
|
|
|
|
|
see http://www.w3.org/TR/resource-timing/#processing-model
|
2015-02-01 10:08:21 +01:00
|
|
|
|
|
|
|
sorted by 'complete'
|
|
|
|
|
2015-05-15 16:55:30 +02:00
|
|
|
id responseEnd requestStart process code size request path
|
|
|
|
13 +37.19ms +280us 36.91ms 200 2K /
|
|
|
|
2 +72.65ms * +36.38ms 36.26ms 200 8K /stylesheets/screen.css
|
|
|
|
17 +77.43ms +38.67ms 38.75ms 200 3K /javascripts/octopress.js
|
|
|
|
15 +78.12ms +38.66ms 39.46ms 200 3K /javascripts/modernizr-2.0.js
|
2015-02-01 10:08:21 +01:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
Using the ``-r`` option, ``nghttp`` writes more detailed timing data to
|
|
|
|
the given file in HAR format.
|
2015-02-01 10:08:21 +01:00
|
|
|
|
2013-07-27 14:56:46 +02:00
|
|
|
nghttpd - server
|
|
|
|
++++++++++++++++
|
|
|
|
|
2014-03-04 15:16:46 +01:00
|
|
|
``nghttpd`` is a multi-threaded static web server.
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2014-04-08 16:12:02 +02:00
|
|
|
By default, it uses SSL/TLS connection. Use ``--no-tls`` option to
|
2013-07-27 15:40:44 +02:00
|
|
|
disable it.
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
``nghttpd`` only accepts HTTP/2 connections via NPN/ALPN or direct
|
|
|
|
HTTP/2 connections. No HTTP Upgrade is supported.
|
2013-08-03 12:44:13 +02:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
The ``-p`` option allows users to configure server push.
|
2013-12-08 16:06:53 +01:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
Just like ``nghttp``, it has a verbose output mode for framing
|
2016-04-16 11:58:18 +02:00
|
|
|
information. Here is sample output from ``nghttpd``:
|
|
|
|
|
|
|
|
.. code-block:: text
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2015-02-01 10:08:21 +01:00
|
|
|
$ nghttpd --no-tls -v 8080
|
2015-05-15 16:55:30 +02:00
|
|
|
IPv4: listen 0.0.0.0:8080
|
|
|
|
IPv6: listen :::8080
|
|
|
|
[id=1] [ 1.521] send SETTINGS frame <length=6, flags=0x00, stream_id=0>
|
|
|
|
(niv=1)
|
|
|
|
[SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
|
|
|
|
[id=1] [ 1.521] recv SETTINGS frame <length=12, flags=0x00, stream_id=0>
|
2014-02-15 09:19:49 +01:00
|
|
|
(niv=2)
|
2015-05-15 16:55:30 +02:00
|
|
|
[SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
|
|
|
|
[SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
|
|
|
|
[id=1] [ 1.521] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
|
2014-01-11 09:06:26 +01:00
|
|
|
; ACK
|
|
|
|
(niv=0)
|
2015-05-15 16:55:30 +02:00
|
|
|
[id=1] [ 1.521] recv PRIORITY frame <length=5, flags=0x00, stream_id=3>
|
|
|
|
(dep_stream_id=0, weight=201, exclusive=0)
|
|
|
|
[id=1] [ 1.521] recv PRIORITY frame <length=5, flags=0x00, stream_id=5>
|
|
|
|
(dep_stream_id=0, weight=101, exclusive=0)
|
|
|
|
[id=1] [ 1.521] recv PRIORITY frame <length=5, flags=0x00, stream_id=7>
|
|
|
|
(dep_stream_id=0, weight=1, exclusive=0)
|
|
|
|
[id=1] [ 1.521] recv PRIORITY frame <length=5, flags=0x00, stream_id=9>
|
|
|
|
(dep_stream_id=7, weight=1, exclusive=0)
|
|
|
|
[id=1] [ 1.521] recv PRIORITY frame <length=5, flags=0x00, stream_id=11>
|
|
|
|
(dep_stream_id=3, weight=1, exclusive=0)
|
|
|
|
[id=1] [ 1.521] recv (stream_id=13) :method: GET
|
|
|
|
[id=1] [ 1.521] recv (stream_id=13) :path: /
|
|
|
|
[id=1] [ 1.521] recv (stream_id=13) :scheme: http
|
|
|
|
[id=1] [ 1.521] recv (stream_id=13) :authority: localhost:8080
|
|
|
|
[id=1] [ 1.521] recv (stream_id=13) accept: */*
|
|
|
|
[id=1] [ 1.521] recv (stream_id=13) accept-encoding: gzip, deflate
|
|
|
|
[id=1] [ 1.521] recv (stream_id=13) user-agent: nghttp2/1.0.0-DEV
|
|
|
|
[id=1] [ 1.521] recv HEADERS frame <length=41, flags=0x25, stream_id=13>
|
|
|
|
; END_STREAM | END_HEADERS | PRIORITY
|
|
|
|
(padlen=0, dep_stream_id=11, weight=16, exclusive=0)
|
|
|
|
; Open new stream
|
|
|
|
[id=1] [ 1.521] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
|
2014-05-14 17:27:24 +02:00
|
|
|
; ACK
|
|
|
|
(niv=0)
|
2015-05-15 16:55:30 +02:00
|
|
|
[id=1] [ 1.521] send HEADERS frame <length=86, flags=0x04, stream_id=13>
|
2014-01-11 09:06:26 +01:00
|
|
|
; END_HEADERS
|
2014-02-15 09:19:49 +01:00
|
|
|
(padlen=0)
|
2014-01-11 09:06:26 +01:00
|
|
|
; First response header
|
2014-05-14 17:27:24 +02:00
|
|
|
:status: 200
|
2015-05-15 16:55:30 +02:00
|
|
|
server: nghttpd nghttp2/1.0.0-DEV
|
|
|
|
content-length: 10
|
2014-05-14 17:27:24 +02:00
|
|
|
cache-control: max-age=3600
|
2015-05-15 16:55:30 +02:00
|
|
|
date: Fri, 15 May 2015 14:49:04 GMT
|
|
|
|
last-modified: Tue, 30 Sep 2014 12:40:52 GMT
|
|
|
|
[id=1] [ 1.522] send DATA frame <length=10, flags=0x01, stream_id=13>
|
2014-01-11 09:06:26 +01:00
|
|
|
; END_STREAM
|
2015-05-15 16:55:30 +02:00
|
|
|
[id=1] [ 1.522] stream_id=13 closed
|
|
|
|
[id=1] [ 1.522] recv GOAWAY frame <length=8, flags=0x00, stream_id=0>
|
|
|
|
(last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[])
|
|
|
|
[id=1] [ 1.522] closed
|
2013-07-27 14:56:46 +02:00
|
|
|
|
|
|
|
nghttpx - proxy
|
|
|
|
+++++++++++++++
|
|
|
|
|
2021-09-18 08:19:15 +02:00
|
|
|
``nghttpx`` is a multi-threaded reverse proxy for HTTP/3, HTTP/2, and
|
2015-04-05 16:07:42 +02:00
|
|
|
HTTP/1.1, and powers http://nghttp2.org and supports HTTP/2 server
|
|
|
|
push.
|
2015-03-31 16:31:24 +02:00
|
|
|
|
2016-03-26 13:43:34 +01:00
|
|
|
We reworked ``nghttpx`` command-line interface, and as a result, there
|
|
|
|
are several incompatibles from 1.8.0 or earlier. This is necessary to
|
|
|
|
extend its capability, and secure the further feature enhancements in
|
|
|
|
the future release. Please read `Migration from nghttpx v1.8.0 or
|
|
|
|
earlier
|
|
|
|
<https://nghttp2.org/documentation/nghttpx-howto.html#migration-from-nghttpx-v1-8-0-or-earlier>`_
|
|
|
|
to know how to migrate from earlier releases.
|
|
|
|
|
2015-03-31 16:31:24 +02:00
|
|
|
``nghttpx`` implements `important performance-oriented features
|
|
|
|
<https://istlsfastyet.com/#server-performance>`_ in TLS, such as
|
|
|
|
session IDs, session tickets (with automatic key rotation), OCSP
|
2017-12-17 05:23:37 +01:00
|
|
|
stapling, dynamic record sizing, ALPN/NPN, forward secrecy and HTTP/2.
|
|
|
|
``nghttpx`` also offers the functionality to share session cache and
|
|
|
|
ticket keys among multiple ``nghttpx`` instances via memcached.
|
2015-03-31 16:31:24 +02:00
|
|
|
|
2016-02-28 15:12:57 +01:00
|
|
|
``nghttpx`` has 2 operation modes:
|
|
|
|
|
2021-09-18 08:19:15 +02:00
|
|
|
================== ======================== ================ =============
|
|
|
|
Mode option Frontend Backend Note
|
|
|
|
================== ======================== ================ =============
|
|
|
|
default mode HTTP/3, HTTP/2, HTTP/1.1 HTTP/1.1, HTTP/2 Reverse proxy
|
|
|
|
``--http2-proxy`` HTTP/3, HTTP/2, HTTP/1.1 HTTP/1.1, HTTP/2 Forward proxy
|
|
|
|
================== ======================== ================ =============
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2014-04-08 16:12:02 +02:00
|
|
|
The interesting mode at the moment is the default mode. It works like
|
2021-09-18 08:19:15 +02:00
|
|
|
a reverse proxy and listens for HTTP/3, HTTP/2, and HTTP/1.1 and can
|
|
|
|
be deployed as a SSL/TLS terminator for existing web server.
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2016-02-28 15:12:57 +01:00
|
|
|
In all modes, the frontend connections are encrypted by SSL/TLS by
|
2016-03-25 15:53:59 +01:00
|
|
|
default. To disable encryption, use the ``no-tls`` keyword in
|
2017-12-17 05:23:37 +01:00
|
|
|
``--frontend`` option. If encryption is disabled, incoming HTTP/1.1
|
|
|
|
connections can be upgraded to HTTP/2 through HTTP Upgrade. On the
|
|
|
|
other hard, backend connections are not encrypted by default. To
|
|
|
|
encrypt backend connections, use ``tls`` keyword in ``--backend``
|
|
|
|
option.
|
2013-07-27 15:40:44 +02:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
``nghttpx`` supports a configuration file. See the ``--conf`` option and
|
2013-07-27 14:56:46 +02:00
|
|
|
sample configuration file ``nghttpx.conf.sample``.
|
|
|
|
|
2016-02-28 15:12:57 +01:00
|
|
|
In the default mode, ``nghttpx`` works as reverse proxy to the backend
|
2016-04-16 11:58:18 +02:00
|
|
|
server:
|
|
|
|
|
|
|
|
.. code-block:: text
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2021-09-18 08:19:15 +02:00
|
|
|
Client <-- (HTTP/3, HTTP/2, HTTP/1.1) --> nghttpx <-- (HTTP/1.1, HTTP/2) --> Web Server
|
|
|
|
[reverse proxy]
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2016-02-28 15:12:57 +01:00
|
|
|
With the ``--http2-proxy`` option, it works as forward proxy, and it
|
2017-12-17 05:23:37 +01:00
|
|
|
is so called secure HTTP/2 proxy:
|
2016-04-16 11:58:18 +02:00
|
|
|
|
|
|
|
.. code-block:: text
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2021-09-18 08:19:15 +02:00
|
|
|
Client <-- (HTTP/3, HTTP/2, HTTP/1.1) --> nghttpx <-- (HTTP/1.1) --> Proxy
|
|
|
|
[secure proxy] (e.g., Squid, ATS)
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
The ``Client`` in the above example needs to be configured to use
|
2013-08-03 12:44:13 +02:00
|
|
|
``nghttpx`` as secure proxy.
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2016-02-28 15:12:57 +01:00
|
|
|
At the time of this writing, both Chrome and Firefox support secure
|
|
|
|
HTTP/2 proxy. One way to configure Chrome to use a secure proxy is to
|
|
|
|
create a proxy.pac script like this:
|
2014-01-11 09:13:24 +01:00
|
|
|
|
|
|
|
.. code-block:: javascript
|
2013-07-27 14:56:46 +02:00
|
|
|
|
|
|
|
function FindProxyForURL(url, host) {
|
|
|
|
return "HTTPS SERVERADDR:PORT";
|
|
|
|
}
|
|
|
|
|
|
|
|
``SERVERADDR`` and ``PORT`` is the hostname/address and port of the
|
2015-03-16 07:42:19 +01:00
|
|
|
machine nghttpx is running on. Please note that Chrome requires a valid
|
2013-08-03 12:44:13 +02:00
|
|
|
certificate for secure proxy.
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2016-04-16 11:58:18 +02:00
|
|
|
Then run Chrome with the following arguments:
|
|
|
|
|
|
|
|
.. code-block:: text
|
2013-07-27 14:56:46 +02:00
|
|
|
|
|
|
|
$ google-chrome --proxy-pac-url=file:///path/to/proxy.pac --use-npn
|
|
|
|
|
2016-02-28 15:12:57 +01:00
|
|
|
The backend HTTP/2 connections can be tunneled through an HTTP proxy.
|
2015-03-16 07:42:19 +01:00
|
|
|
The proxy is specified using ``--backend-http-proxy-uri``. The
|
2016-02-28 15:12:57 +01:00
|
|
|
following figure illustrates how nghttpx talks to the outside HTTP/2
|
2016-04-16 11:58:18 +02:00
|
|
|
proxy through an HTTP proxy:
|
|
|
|
|
|
|
|
.. code-block:: text
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2021-09-18 08:19:15 +02:00
|
|
|
Client <-- (HTTP/3, HTTP/2, HTTP/1.1) --> nghttpx <-- (HTTP/2) --
|
2013-07-27 14:56:46 +02:00
|
|
|
|
2014-03-30 12:09:21 +02:00
|
|
|
--===================---> HTTP/2 Proxy
|
2013-07-27 14:56:46 +02:00
|
|
|
(HTTP proxy tunnel) (e.g., nghttpx -s)
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2014-03-02 15:44:43 +01:00
|
|
|
Benchmarking tool
|
|
|
|
-----------------
|
|
|
|
|
2021-09-18 08:19:15 +02:00
|
|
|
The ``h2load`` program is a benchmarking tool for HTTP/3, HTTP/2, and
|
|
|
|
HTTP/1.1. The UI of ``h2load`` is heavily inspired by ``weighttp``
|
2014-04-08 16:12:02 +02:00
|
|
|
(https://github.com/lighttpd/weighttp). The typical usage is as
|
2016-04-16 11:58:18 +02:00
|
|
|
follows:
|
|
|
|
|
|
|
|
.. code-block:: text
|
2014-03-02 15:44:43 +01:00
|
|
|
|
2015-02-01 10:08:21 +01:00
|
|
|
$ h2load -n100000 -c100 -m100 https://localhost:8443/
|
2014-03-02 15:44:43 +01:00
|
|
|
starting benchmark...
|
2015-01-31 10:13:07 +01:00
|
|
|
spawning thread #0: 100 concurrent clients, 100000 total requests
|
|
|
|
Protocol: TLSv1.2
|
|
|
|
Cipher: ECDHE-RSA-AES128-GCM-SHA256
|
2015-05-15 16:55:30 +02:00
|
|
|
Server Temp Key: ECDH P-256 256 bits
|
2014-03-02 15:44:43 +01:00
|
|
|
progress: 10% done
|
|
|
|
progress: 20% done
|
|
|
|
progress: 30% done
|
|
|
|
progress: 40% done
|
|
|
|
progress: 50% done
|
|
|
|
progress: 60% done
|
|
|
|
progress: 70% done
|
|
|
|
progress: 80% done
|
|
|
|
progress: 90% done
|
|
|
|
progress: 100% done
|
|
|
|
|
2015-05-15 16:55:30 +02:00
|
|
|
finished in 771.26ms, 129658 req/s, 4.71MB/s
|
2015-01-31 10:13:07 +01:00
|
|
|
requests: 100000 total, 100000 started, 100000 done, 100000 succeeded, 0 failed, 0 errored
|
|
|
|
status codes: 100000 2xx, 0 3xx, 0 4xx, 0 5xx
|
2015-05-15 16:55:30 +02:00
|
|
|
traffic: 3812300 bytes total, 1009900 bytes headers, 1000000 bytes data
|
2015-02-15 08:38:42 +01:00
|
|
|
min max mean sd +/- sd
|
2015-05-15 16:55:30 +02:00
|
|
|
time for request: 25.12ms 124.55ms 51.07ms 15.36ms 84.87%
|
|
|
|
time for connect: 208.94ms 254.67ms 241.38ms 7.95ms 63.00%
|
|
|
|
time to 1st byte: 209.11ms 254.80ms 241.51ms 7.94ms 63.00%
|
2015-01-31 10:13:07 +01:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
The above example issued total 100,000 requests, using 100 concurrent
|
|
|
|
clients (in other words, 100 HTTP/2 sessions), and a maximum of 100 streams
|
|
|
|
per client. With the ``-t`` option, ``h2load`` will use multiple native
|
|
|
|
threads to avoid saturating a single core on client side.
|
2014-03-02 15:44:43 +01:00
|
|
|
|
|
|
|
.. warning::
|
|
|
|
|
2014-04-08 16:12:02 +02:00
|
|
|
**Don't use this tool against publicly available servers.** That is
|
2015-03-16 07:42:19 +01:00
|
|
|
considered a DOS attack. Please only use it against your private
|
2014-03-02 19:52:08 +01:00
|
|
|
servers.
|
2014-03-02 15:44:43 +01:00
|
|
|
|
2021-08-22 11:07:52 +02:00
|
|
|
If the experimental HTTP/3 is enabled, h2load can send requests to
|
|
|
|
HTTP/3 server. To do this, specify ``h3`` to ``--npn-list`` option
|
|
|
|
like so:
|
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
|
|
|
$ h2load --npn-list h3 https://127.0.0.1:4433
|
|
|
|
|
2014-01-10 13:53:48 +01:00
|
|
|
HPACK tools
|
|
|
|
-----------
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
The ``src`` directory contains the HPACK tools. The ``deflatehd`` program is a
|
|
|
|
command-line header compression tool. The ``inflatehd`` program is a
|
2014-01-10 13:53:48 +01:00
|
|
|
command-line header decompression tool. Both tools read input from
|
2015-03-16 07:42:19 +01:00
|
|
|
stdin and write output to stdout. Errors are written to stderr.
|
|
|
|
They take JSON as input and output. We (mostly) use the same JSON data
|
|
|
|
format described at https://github.com/http2jp/hpack-test-case.
|
2013-10-28 16:22:18 +01:00
|
|
|
|
|
|
|
deflatehd - header compressor
|
|
|
|
+++++++++++++++++++++++++++++
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
The ``deflatehd`` program reads JSON data or HTTP/1-style header fields from
|
2014-01-11 09:06:26 +01:00
|
|
|
stdin and outputs compressed header block in JSON.
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
For the JSON input, the root JSON object must include a ``cases`` key.
|
2014-04-08 16:12:02 +02:00
|
|
|
Its value has to include the sequence of input header set. They share
|
|
|
|
the same compression context and are processed in the order they
|
2014-02-15 12:00:51 +01:00
|
|
|
appear. Each item in the sequence is a JSON object and it must
|
2015-03-16 07:42:19 +01:00
|
|
|
include a ``headers`` key. Its value is an array of JSON objects,
|
2014-02-15 12:00:51 +01:00
|
|
|
which includes exactly one name/value pair.
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2014-01-11 09:13:24 +01:00
|
|
|
Example:
|
|
|
|
|
|
|
|
.. code-block:: json
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2014-01-11 09:06:26 +01:00
|
|
|
{
|
|
|
|
"cases":
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"headers": [
|
|
|
|
{ ":method": "GET" },
|
|
|
|
{ ":path": "/" }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"headers": [
|
|
|
|
{ ":method": "POST" },
|
|
|
|
{ ":path": "/" }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
With the ``-t`` option, the program can accept more familiar HTTP/1 style
|
|
|
|
header field blocks. Each header set is delimited by an empty line:
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2016-04-16 11:58:18 +02:00
|
|
|
Example:
|
|
|
|
|
|
|
|
.. code-block:: text
|
2013-10-28 16:22:18 +01:00
|
|
|
|
|
|
|
:method: GET
|
|
|
|
:scheme: https
|
|
|
|
:path: /
|
|
|
|
|
|
|
|
:method: POST
|
|
|
|
user-agent: nghttp2
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
The output is in JSON object. It should include a ``cases`` key and its
|
|
|
|
value is an array of JSON objects, which has at least the following keys:
|
2013-10-28 16:22:18 +01:00
|
|
|
|
|
|
|
seq
|
|
|
|
The index of header set in the input.
|
|
|
|
|
2014-01-11 09:06:26 +01:00
|
|
|
input_length
|
2015-03-16 07:42:19 +01:00
|
|
|
The sum of the length of the name/value pairs in the input.
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2014-01-11 09:06:26 +01:00
|
|
|
output_length
|
2015-03-16 07:42:19 +01:00
|
|
|
The length of the compressed header block.
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2014-01-11 09:06:26 +01:00
|
|
|
percentage_of_original_size
|
2018-03-12 01:19:19 +01:00
|
|
|
``output_length`` / ``input_length`` * 100
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2014-01-11 09:06:26 +01:00
|
|
|
wire
|
2015-03-16 07:42:19 +01:00
|
|
|
The compressed header block as a hex string.
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2014-01-11 09:06:26 +01:00
|
|
|
headers
|
|
|
|
The input header set.
|
|
|
|
|
|
|
|
header_table_size
|
2015-03-16 07:42:19 +01:00
|
|
|
The header table size adjusted before deflating the header set.
|
2014-01-11 09:06:26 +01:00
|
|
|
|
2014-01-11 09:13:24 +01:00
|
|
|
Examples:
|
|
|
|
|
|
|
|
.. code-block:: json
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2014-01-11 09:06:26 +01:00
|
|
|
{
|
|
|
|
"cases":
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"seq": 0,
|
|
|
|
"input_length": 66,
|
|
|
|
"output_length": 20,
|
|
|
|
"percentage_of_original_size": 30.303030303030305,
|
|
|
|
"wire": "01881f3468e5891afcbf83868a3d856659c62e3f",
|
|
|
|
"headers": [
|
|
|
|
{
|
|
|
|
":authority": "example.org"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":method": "GET"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":path": "/"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":scheme": "https"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"user-agent": "nghttp2"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"header_table_size": 4096
|
|
|
|
}
|
|
|
|
,
|
|
|
|
{
|
|
|
|
"seq": 1,
|
|
|
|
"input_length": 74,
|
|
|
|
"output_length": 10,
|
|
|
|
"percentage_of_original_size": 13.513513513513514,
|
|
|
|
"wire": "88448504252dd5918485",
|
|
|
|
"headers": [
|
|
|
|
{
|
|
|
|
":authority": "example.org"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":method": "POST"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":path": "/account"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":scheme": "https"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"user-agent": "nghttp2"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"header_table_size": 4096
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
The output can be used as the input for ``inflatehd`` and
|
|
|
|
``deflatehd``.
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
With the ``-d`` option, the extra ``header_table`` key is added and its
|
2014-03-02 19:52:08 +01:00
|
|
|
associated value includes the state of dynamic header table after the
|
2014-04-08 16:12:02 +02:00
|
|
|
corresponding header set was processed. The value includes at least
|
|
|
|
the following keys:
|
2013-10-28 16:22:18 +01:00
|
|
|
|
|
|
|
entries
|
2014-04-08 16:12:02 +02:00
|
|
|
The entry in the header table. If ``referenced`` is ``true``, it
|
|
|
|
is in the reference set. The ``size`` includes the overhead (32
|
|
|
|
bytes). The ``index`` corresponds to the index of header table.
|
2013-10-28 16:22:18 +01:00
|
|
|
The ``name`` is the header field name and the ``value`` is the
|
2014-04-08 16:12:02 +02:00
|
|
|
header field value.
|
2013-10-28 16:22:18 +01:00
|
|
|
|
|
|
|
size
|
|
|
|
The sum of the spaces entries occupied, this includes the
|
|
|
|
entry overhead.
|
|
|
|
|
2014-01-11 09:06:26 +01:00
|
|
|
max_size
|
2013-10-28 16:22:18 +01:00
|
|
|
The maximum header table size.
|
|
|
|
|
2014-01-11 09:06:26 +01:00
|
|
|
deflate_size
|
|
|
|
The sum of the spaces entries occupied within
|
|
|
|
``max_deflate_size``.
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2014-01-11 09:06:26 +01:00
|
|
|
max_deflate_size
|
2015-03-16 07:42:19 +01:00
|
|
|
The maximum header table size the encoder uses. This can be smaller
|
|
|
|
than ``max_size``. In this case, the encoder only uses up to first
|
2014-04-08 16:12:02 +02:00
|
|
|
``max_deflate_size`` buffer. Since the header table size is still
|
2015-05-12 03:49:42 +02:00
|
|
|
``max_size``, the encoder has to keep track of entries outside the
|
2014-01-11 09:06:26 +01:00
|
|
|
``max_deflate_size`` but inside the ``max_size`` and make sure
|
|
|
|
that they are no longer referenced.
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2014-01-11 09:13:24 +01:00
|
|
|
Example:
|
|
|
|
|
|
|
|
.. code-block:: json
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2014-01-11 09:06:26 +01:00
|
|
|
{
|
|
|
|
"cases":
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"seq": 0,
|
|
|
|
"input_length": 66,
|
|
|
|
"output_length": 20,
|
|
|
|
"percentage_of_original_size": 30.303030303030305,
|
|
|
|
"wire": "01881f3468e5891afcbf83868a3d856659c62e3f",
|
|
|
|
"headers": [
|
|
|
|
{
|
|
|
|
":authority": "example.org"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":method": "GET"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":path": "/"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":scheme": "https"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"user-agent": "nghttp2"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"header_table_size": 4096,
|
|
|
|
"header_table": {
|
|
|
|
"entries": [
|
|
|
|
{
|
|
|
|
"index": 1,
|
|
|
|
"name": "user-agent",
|
|
|
|
"value": "nghttp2",
|
|
|
|
"referenced": true,
|
|
|
|
"size": 49
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"index": 2,
|
|
|
|
"name": ":scheme",
|
|
|
|
"value": "https",
|
|
|
|
"referenced": true,
|
|
|
|
"size": 44
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"index": 3,
|
|
|
|
"name": ":path",
|
|
|
|
"value": "/",
|
|
|
|
"referenced": true,
|
|
|
|
"size": 38
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"index": 4,
|
|
|
|
"name": ":method",
|
|
|
|
"value": "GET",
|
|
|
|
"referenced": true,
|
|
|
|
"size": 42
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"index": 5,
|
|
|
|
"name": ":authority",
|
|
|
|
"value": "example.org",
|
|
|
|
"referenced": true,
|
|
|
|
"size": 53
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"size": 226,
|
|
|
|
"max_size": 4096,
|
|
|
|
"deflate_size": 226,
|
|
|
|
"max_deflate_size": 4096
|
|
|
|
}
|
|
|
|
}
|
|
|
|
,
|
|
|
|
{
|
|
|
|
"seq": 1,
|
|
|
|
"input_length": 74,
|
|
|
|
"output_length": 10,
|
|
|
|
"percentage_of_original_size": 13.513513513513514,
|
|
|
|
"wire": "88448504252dd5918485",
|
|
|
|
"headers": [
|
|
|
|
{
|
|
|
|
":authority": "example.org"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":method": "POST"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":path": "/account"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":scheme": "https"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"user-agent": "nghttp2"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"header_table_size": 4096,
|
|
|
|
"header_table": {
|
|
|
|
"entries": [
|
|
|
|
{
|
|
|
|
"index": 1,
|
|
|
|
"name": ":method",
|
|
|
|
"value": "POST",
|
|
|
|
"referenced": true,
|
|
|
|
"size": 43
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"index": 2,
|
|
|
|
"name": "user-agent",
|
|
|
|
"value": "nghttp2",
|
|
|
|
"referenced": true,
|
|
|
|
"size": 49
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"index": 3,
|
|
|
|
"name": ":scheme",
|
|
|
|
"value": "https",
|
|
|
|
"referenced": true,
|
|
|
|
"size": 44
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"index": 4,
|
|
|
|
"name": ":path",
|
|
|
|
"value": "/",
|
|
|
|
"referenced": false,
|
|
|
|
"size": 38
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"index": 5,
|
|
|
|
"name": ":method",
|
|
|
|
"value": "GET",
|
|
|
|
"referenced": false,
|
|
|
|
"size": 42
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"index": 6,
|
|
|
|
"name": ":authority",
|
|
|
|
"value": "example.org",
|
|
|
|
"referenced": true,
|
|
|
|
"size": 53
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"size": 269,
|
|
|
|
"max_size": 4096,
|
|
|
|
"deflate_size": 269,
|
|
|
|
"max_deflate_size": 4096
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2013-10-28 16:22:18 +01:00
|
|
|
|
|
|
|
inflatehd - header decompressor
|
|
|
|
+++++++++++++++++++++++++++++++
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
The ``inflatehd`` program reads JSON data from stdin and outputs decompressed
|
2014-01-11 09:06:26 +01:00
|
|
|
name/value pairs in JSON.
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
The root JSON object must include the ``cases`` key. Its value has to
|
|
|
|
include the sequence of compressed header blocks. They share the same
|
2014-04-08 16:12:02 +02:00
|
|
|
compression context and are processed in the order they appear. Each
|
2015-03-16 07:42:19 +01:00
|
|
|
item in the sequence is a JSON object and it must have at least a
|
|
|
|
``wire`` key. Its value is a compressed header block as a hex string.
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2014-01-11 09:13:24 +01:00
|
|
|
Example:
|
|
|
|
|
|
|
|
.. code-block:: json
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2014-01-11 09:06:26 +01:00
|
|
|
{
|
|
|
|
"cases":
|
|
|
|
[
|
|
|
|
{ "wire": "8285" },
|
|
|
|
{ "wire": "8583" }
|
|
|
|
]
|
|
|
|
}
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
The output is a JSON object. It should include a ``cases`` key and its
|
|
|
|
value is an array of JSON objects, which has at least following keys:
|
2013-10-28 16:22:18 +01:00
|
|
|
|
|
|
|
seq
|
2015-03-16 07:42:19 +01:00
|
|
|
The index of the header set in the input.
|
2013-10-28 16:22:18 +01:00
|
|
|
|
|
|
|
headers
|
2015-03-16 07:42:19 +01:00
|
|
|
A JSON array that includes decompressed name/value pairs.
|
2014-01-11 09:06:26 +01:00
|
|
|
|
|
|
|
wire
|
2015-03-16 07:42:19 +01:00
|
|
|
The compressed header block as a hex string.
|
2014-01-11 09:06:26 +01:00
|
|
|
|
|
|
|
header_table_size
|
2014-03-02 19:52:08 +01:00
|
|
|
The header table size adjusted before inflating compressed header
|
2014-01-11 09:06:26 +01:00
|
|
|
block.
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2014-01-11 09:13:24 +01:00
|
|
|
Example:
|
|
|
|
|
|
|
|
.. code-block:: json
|
2013-10-28 16:22:18 +01:00
|
|
|
|
2014-01-11 09:06:26 +01:00
|
|
|
{
|
|
|
|
"cases":
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"seq": 0,
|
|
|
|
"wire": "01881f3468e5891afcbf83868a3d856659c62e3f",
|
|
|
|
"headers": [
|
|
|
|
{
|
|
|
|
":authority": "example.org"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":method": "GET"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":path": "/"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":scheme": "https"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"user-agent": "nghttp2"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"header_table_size": 4096
|
|
|
|
}
|
|
|
|
,
|
|
|
|
{
|
|
|
|
"seq": 1,
|
|
|
|
"wire": "88448504252dd5918485",
|
|
|
|
"headers": [
|
|
|
|
{
|
|
|
|
":method": "POST"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":path": "/account"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"user-agent": "nghttp2"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":scheme": "https"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
":authority": "example.org"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"header_table_size": 4096
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
The output can be used as the input for ``deflatehd`` and
|
|
|
|
``inflatehd``.
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
With the ``-d`` option, the extra ``header_table`` key is added and its
|
|
|
|
associated value includes the state of the dynamic header table after the
|
2014-04-08 16:12:02 +02:00
|
|
|
corresponding header set was processed. The format is the same as
|
2013-10-28 16:22:18 +01:00
|
|
|
``deflatehd``.
|
2014-01-10 17:01:28 +01:00
|
|
|
|
2014-09-23 17:25:37 +02:00
|
|
|
libnghttp2_asio: High level HTTP/2 C++ library
|
|
|
|
----------------------------------------------
|
|
|
|
|
|
|
|
libnghttp2_asio is C++ library built on top of libnghttp2 and provides
|
|
|
|
high level abstraction API to build HTTP/2 applications. It depends
|
2015-03-16 07:42:19 +01:00
|
|
|
on the Boost::ASIO library and OpenSSL. Currently libnghttp2_asio
|
|
|
|
provides both client and server APIs.
|
2014-09-23 17:25:37 +02:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
libnghttp2_asio is not built by default. Use the ``--enable-asio-lib``
|
2014-09-23 17:25:37 +02:00
|
|
|
configure flag to build libnghttp2_asio. The required Boost libraries
|
|
|
|
are:
|
|
|
|
|
|
|
|
* Boost::Asio
|
|
|
|
* Boost::System
|
|
|
|
* Boost::Thread
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
The server API is designed to build an HTTP/2 server very easily to utilize
|
2018-10-15 15:35:05 +02:00
|
|
|
C++14 anonymous functions and closures. The bare minimum example of
|
2015-03-16 07:42:19 +01:00
|
|
|
an HTTP/2 server looks like this:
|
2014-09-23 17:25:37 +02:00
|
|
|
|
|
|
|
.. code-block:: cpp
|
|
|
|
|
2015-08-24 08:59:25 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
2015-03-05 18:23:17 +01:00
|
|
|
#include <nghttp2/asio_http2_server.h>
|
2014-09-23 17:25:37 +02:00
|
|
|
|
|
|
|
using namespace nghttp2::asio_http2;
|
|
|
|
using namespace nghttp2::asio_http2::server;
|
|
|
|
|
2014-11-30 14:54:55 +01:00
|
|
|
int main(int argc, char *argv[]) {
|
2015-03-06 16:39:35 +01:00
|
|
|
boost::system::error_code ec;
|
2014-09-23 17:25:37 +02:00
|
|
|
http2 server;
|
|
|
|
|
2015-03-05 18:23:17 +01:00
|
|
|
server.handle("/", [](const request &req, const response &res) {
|
|
|
|
res.write_head(200);
|
|
|
|
res.end("hello, world\n");
|
2014-11-30 14:54:55 +01:00
|
|
|
});
|
2015-03-05 18:23:17 +01:00
|
|
|
|
2015-03-06 16:39:35 +01:00
|
|
|
if (server.listen_and_serve(ec, "localhost", "3000")) {
|
|
|
|
std::cerr << "error: " << ec.message() << std::endl;
|
|
|
|
}
|
2014-09-23 17:25:37 +02:00
|
|
|
}
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
Here is sample code to use the client API:
|
2015-03-06 19:12:13 +01:00
|
|
|
|
|
|
|
.. code-block:: cpp
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <nghttp2/asio_http2_client.h>
|
|
|
|
|
|
|
|
using boost::asio::ip::tcp;
|
|
|
|
|
|
|
|
using namespace nghttp2::asio_http2;
|
|
|
|
using namespace nghttp2::asio_http2::client;
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
boost::system::error_code ec;
|
|
|
|
boost::asio::io_service io_service;
|
|
|
|
|
|
|
|
// connect to localhost:3000
|
|
|
|
session sess(io_service, "localhost", "3000");
|
|
|
|
|
|
|
|
sess.on_connect([&sess](tcp::resolver::iterator endpoint_it) {
|
2015-05-15 16:55:30 +02:00
|
|
|
boost::system::error_code ec;
|
|
|
|
|
|
|
|
auto req = sess.submit(ec, "GET", "http://localhost:3000/");
|
|
|
|
|
|
|
|
req->on_response([](const response &res) {
|
|
|
|
// print status code and response header fields.
|
|
|
|
std::cerr << "HTTP/2 " << res.status_code() << std::endl;
|
|
|
|
for (auto &kv : res.header()) {
|
|
|
|
std::cerr << kv.first << ": " << kv.second.value << "\n";
|
|
|
|
}
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
res.on_data([](const uint8_t *data, std::size_t len) {
|
|
|
|
std::cerr.write(reinterpret_cast<const char *>(data), len);
|
|
|
|
std::cerr << std::endl;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
req->on_close([&sess](uint32_t error_code) {
|
|
|
|
// shutdown session after first request was done.
|
|
|
|
sess.shutdown();
|
|
|
|
});
|
2015-03-06 19:12:13 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
sess.on_error([](const boost::system::error_code &ec) {
|
2015-05-15 16:55:30 +02:00
|
|
|
std::cerr << "error: " << ec.message() << std::endl;
|
2015-03-06 19:12:13 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
io_service.run();
|
|
|
|
}
|
|
|
|
|
2014-09-23 17:25:37 +02:00
|
|
|
For more details, see the documentation of libnghttp2_asio.
|
|
|
|
|
2014-01-10 17:01:28 +01:00
|
|
|
Python bindings
|
|
|
|
---------------
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
The ``python`` directory contains nghttp2 Python bindings. The
|
2014-04-08 16:12:02 +02:00
|
|
|
bindings currently provide HPACK compressor and decompressor classes
|
2015-03-16 07:42:19 +01:00
|
|
|
and an HTTP/2 server.
|
2014-01-10 17:01:28 +01:00
|
|
|
|
|
|
|
The extension module is called ``nghttp2``.
|
|
|
|
|
|
|
|
``make`` will build the bindings and target Python version is
|
2015-03-16 07:42:19 +01:00
|
|
|
determined by the ``configure`` script. If the detected Python version is not
|
|
|
|
what you expect, specify a path to Python executable in a ``PYTHON``
|
2014-01-10 17:01:28 +01:00
|
|
|
variable as an argument to configure script (e.g., ``./configure
|
2020-12-29 10:27:07 +01:00
|
|
|
PYTHON=/usr/bin/python3.8``).
|
2014-01-10 17:01:28 +01:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
The following example code illustrates basic usage of the HPACK compressor
|
2014-01-10 18:02:53 +01:00
|
|
|
and decompressor in Python:
|
|
|
|
|
|
|
|
.. code-block:: python
|
2014-01-10 17:01:28 +01:00
|
|
|
|
|
|
|
import binascii
|
|
|
|
import nghttp2
|
|
|
|
|
2014-02-16 07:30:46 +01:00
|
|
|
deflater = nghttp2.HDDeflater()
|
|
|
|
inflater = nghttp2.HDInflater()
|
2014-01-10 17:01:28 +01:00
|
|
|
|
|
|
|
data = deflater.deflate([(b'foo', b'bar'),
|
2014-01-11 09:06:26 +01:00
|
|
|
(b'baz', b'buz')])
|
2014-01-10 17:01:28 +01:00
|
|
|
print(binascii.b2a_hex(data))
|
|
|
|
|
|
|
|
hdrs = inflater.inflate(data)
|
|
|
|
print(hdrs)
|
2014-02-24 17:46:38 +01:00
|
|
|
|
|
|
|
The ``nghttp2.HTTP2Server`` class builds on top of the asyncio event
|
2014-04-08 16:12:02 +02:00
|
|
|
loop. On construction, *RequestHandlerClass* must be given, which
|
|
|
|
must be a subclass of ``nghttp2.BaseRequestHandler`` class.
|
2014-02-24 17:46:38 +01:00
|
|
|
|
2014-04-08 16:12:02 +02:00
|
|
|
The ``BaseRequestHandler`` class is used to handle the HTTP/2 stream.
|
|
|
|
By default, it does nothing. It must be subclassed to handle each
|
|
|
|
event callback method.
|
2014-02-24 17:46:38 +01:00
|
|
|
|
2014-04-08 16:12:02 +02:00
|
|
|
The first callback method invoked is ``on_headers()``. It is called
|
2015-03-16 07:42:19 +01:00
|
|
|
when HEADERS frame, which includes the request header fields, has arrived.
|
2014-02-24 17:46:38 +01:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
If the request has a request body, ``on_data(data)`` is invoked for each
|
2014-02-24 17:46:38 +01:00
|
|
|
chunk of received data.
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
Once the entire request is received, ``on_request_done()`` is invoked.
|
2014-02-24 17:46:38 +01:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
When the stream is closed, ``on_close(error_code)`` is called.
|
2014-02-24 17:46:38 +01:00
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
The application can send a response using ``send_response()`` method.
|
2014-04-08 16:12:02 +02:00
|
|
|
It can be used in ``on_headers()``, ``on_data()`` or
|
2014-02-24 17:46:38 +01:00
|
|
|
``on_request_done()``.
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
The application can push resources using the ``push()`` method. It must be
|
|
|
|
used before the ``send_response()`` call.
|
2014-02-24 17:46:38 +01:00
|
|
|
|
|
|
|
The following instance variables are available:
|
|
|
|
|
|
|
|
client_address
|
|
|
|
Contains a tuple of the form (host, port) referring to the
|
|
|
|
client's address.
|
|
|
|
|
|
|
|
stream_id
|
2014-03-02 19:52:08 +01:00
|
|
|
Stream ID of this stream.
|
2014-02-24 17:46:38 +01:00
|
|
|
|
|
|
|
scheme
|
2014-04-08 16:12:02 +02:00
|
|
|
Scheme of the request URI. This is a value of :scheme header
|
|
|
|
field.
|
2014-02-24 17:46:38 +01:00
|
|
|
|
|
|
|
method
|
2014-04-08 16:12:02 +02:00
|
|
|
Method of this stream. This is a value of :method header field.
|
2014-02-24 17:46:38 +01:00
|
|
|
|
|
|
|
host
|
|
|
|
This is a value of :authority or host header field.
|
|
|
|
|
|
|
|
path
|
|
|
|
This is a value of :path header field.
|
|
|
|
|
|
|
|
The following example illustrates the HTTP2Server and
|
|
|
|
BaseRequestHandler usage:
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
2020-12-29 10:27:07 +01:00
|
|
|
#!/usr/bin/env python3
|
2014-02-24 17:46:38 +01:00
|
|
|
|
|
|
|
import io, ssl
|
|
|
|
import nghttp2
|
|
|
|
|
|
|
|
class Handler(nghttp2.BaseRequestHandler):
|
|
|
|
|
|
|
|
def on_headers(self):
|
|
|
|
self.push(path='/css/bootstrap.css',
|
2014-02-25 13:25:51 +01:00
|
|
|
request_headers = [('content-length', '3')],
|
2014-02-24 17:46:38 +01:00
|
|
|
status=200,
|
|
|
|
body='foo')
|
|
|
|
|
|
|
|
self.push(path='/js/bootstrap.js',
|
|
|
|
method='GET',
|
2014-02-25 13:25:51 +01:00
|
|
|
request_headers = [('content-length', '10')],
|
2014-02-24 17:46:38 +01:00
|
|
|
status=200,
|
|
|
|
body='foobarbuzz')
|
|
|
|
|
|
|
|
self.send_response(status=200,
|
2014-02-25 13:25:51 +01:00
|
|
|
headers = [('content-type', 'text/plain')],
|
2014-02-24 17:46:38 +01:00
|
|
|
body=io.BytesIO(b'nghttp2-python FTW'))
|
|
|
|
|
|
|
|
ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
|
|
|
|
ctx.options = ssl.OP_ALL | ssl.OP_NO_SSLv2
|
|
|
|
ctx.load_cert_chain('server.crt', 'server.key')
|
|
|
|
|
|
|
|
# give None to ssl to make the server non-SSL/TLS
|
|
|
|
server = nghttp2.HTTP2Server(('127.0.0.1', 8443), Handler, ssl=ctx)
|
|
|
|
server.serve_forever()
|
2014-08-16 16:23:52 +02:00
|
|
|
|
|
|
|
Contribution
|
|
|
|
------------
|
|
|
|
|
|
|
|
[This text was composed based on 1.2. License section of curl/libcurl
|
|
|
|
project.]
|
|
|
|
|
|
|
|
When contributing with code, you agree to put your changes and new
|
|
|
|
code under the same license nghttp2 is already using unless stated and
|
|
|
|
agreed otherwise.
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
When changing existing source code, do not alter the copyright of
|
2014-08-16 16:23:52 +02:00
|
|
|
the original file(s). The copyright will still be owned by the
|
|
|
|
original creator(s) or those who have been assigned copyright by the
|
|
|
|
original author(s).
|
|
|
|
|
2015-03-16 07:42:19 +01:00
|
|
|
By submitting a patch to the nghttp2 project, you (or your employer, as
|
2015-05-01 06:29:43 +02:00
|
|
|
the case may be) agree to assign the copyright of your submission to us.
|
2015-03-16 07:42:19 +01:00
|
|
|
.. the above really needs to be reworded to pass legal muster.
|
|
|
|
We will credit you for your
|
2014-08-16 16:23:52 +02:00
|
|
|
changes as far as possible, to give credit but also to keep a trace
|
|
|
|
back to who made what changes. Please always provide us with your
|
|
|
|
full real name when contributing!
|
2014-11-26 15:43:20 +01:00
|
|
|
|
|
|
|
See `Contribution Guidelines
|
|
|
|
<https://nghttp2.org/documentation/contribute.html>`_ for more
|
|
|
|
details.
|
2016-01-29 04:35:09 +01:00
|
|
|
|
2016-08-21 05:18:31 +02:00
|
|
|
Reporting vulnerability
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
If you find a vulnerability in our software, please send the email to
|
|
|
|
"tatsuhiro.t at gmail dot com" about its details instead of submitting
|
|
|
|
issues on github issue page. It is a standard practice not to
|
|
|
|
disclose vulnerability information publicly until a fixed version is
|
|
|
|
released, or mitigation is worked out.
|
|
|
|
|
|
|
|
In the future, we may setup a dedicated mail address for this purpose.
|
|
|
|
|
2016-01-29 04:35:09 +01:00
|
|
|
Release schedule
|
|
|
|
----------------
|
|
|
|
|
2016-01-29 04:36:15 +01:00
|
|
|
In general, we follow `Semantic Versioning <http://semver.org/>`_. We
|
2016-01-29 04:35:09 +01:00
|
|
|
release MINOR version update every month, and usually we ship it
|
|
|
|
around 25th day of every month.
|
|
|
|
|
|
|
|
We may release PATCH releases between the regular releases, mainly for
|
|
|
|
severe security bug fixes.
|
|
|
|
|
|
|
|
We have no plan to break API compatibility changes involving soname
|
|
|
|
bump, so MAJOR version will stay 1 for the foreseeable future.
|
2016-08-21 04:29:21 +02:00
|
|
|
|
|
|
|
License
|
|
|
|
-------
|
|
|
|
|
|
|
|
The MIT License
|