README.rst 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473
  1. nghttp2 - HTTP/2 C Library
  2. ==========================
  3. This is an implementation of the Hypertext Transfer Protocol version 2
  4. in C.
  5. The framing layer of HTTP/2 is implemented as a reusable C library.
  6. On top of that, we have implemented an HTTP/2 client, server and
  7. proxy. We have also developed load test and benchmarking tools for
  8. HTTP/2.
  9. An HPACK encoder and decoder are available as a public API.
  10. Development Status
  11. ------------------
  12. nghttp2 was originally developed based on `RFC 7540
  13. <https://tools.ietf.org/html/rfc7540>`_ HTTP/2 and `RFC 7541
  14. <https://tools.ietf.org/html/rfc7541>`_ HPACK - Header Compression for
  15. HTTP/2. Now we are updating our code to implement `RFC 9113
  16. <https://datatracker.ietf.org/doc/html/rfc9113>`_.
  17. The nghttp2 code base was forked from the spdylay
  18. (https://github.com/tatsuhiro-t/spdylay) project.
  19. Public Test Server
  20. ------------------
  21. The following endpoints are available to try out our nghttp2
  22. implementation.
  23. * https://nghttp2.org/ (TLS + ALPN/NPN and HTTP/3)
  24. This endpoint supports ``h2``, ``h2-16``, ``h2-14``, and
  25. ``http/1.1`` via ALPN/NPN and requires TLSv1.2 for HTTP/2
  26. connection.
  27. It also supports HTTP/3.
  28. * http://nghttp2.org/ (HTTP Upgrade and HTTP/2 Direct)
  29. ``h2c`` and ``http/1.1``.
  30. Requirements
  31. ------------
  32. The following package is required to build the libnghttp2 library:
  33. * pkg-config >= 0.20
  34. To build and run the unit test programs, the following package is
  35. required:
  36. * cunit >= 2.1
  37. To build the documentation, you need to install:
  38. * sphinx (http://sphinx-doc.org/)
  39. If you need libnghttp2 (C library) only, then the above packages are
  40. all you need. Use ``--enable-lib-only`` to ensure that only
  41. libnghttp2 is built. This avoids potential build error related to
  42. building bundled applications.
  43. To build and run the application programs (``nghttp``, ``nghttpd``,
  44. ``nghttpx`` and ``h2load``) in the ``src`` directory, the following packages
  45. are required:
  46. * OpenSSL >= 1.0.1
  47. * libev >= 4.11
  48. * zlib >= 1.2.3
  49. * libc-ares >= 1.7.5
  50. ALPN support requires OpenSSL >= 1.0.2 (released 22 January 2015).
  51. LibreSSL >= 2.2.0 can be used instead of OpenSSL, but OpenSSL has more
  52. features than LibreSSL at the time of this writing.
  53. To enable ``-a`` option (getting linked assets from the downloaded
  54. resource) in ``nghttp``, the following package is required:
  55. * libxml2 >= 2.6.26
  56. To enable systemd support in nghttpx, the following package is
  57. required:
  58. * libsystemd-dev >= 209
  59. The HPACK tools require the following package:
  60. * jansson >= 2.5
  61. To build sources under the examples directory, libevent is required:
  62. * libevent-openssl >= 2.0.8
  63. To mitigate heap fragmentation in long running server programs
  64. (``nghttpd`` and ``nghttpx``), jemalloc is recommended:
  65. * jemalloc
  66. .. note::
  67. Alpine Linux currently does not support malloc replacement
  68. due to musl limitations. See details in issue `#762 <https://github.com/nghttp2/nghttp2/issues/762>`_.
  69. To enable mruby support for nghttpx, `mruby
  70. <https://github.com/mruby/mruby>`_ is required. We need to build
  71. mruby with C++ ABI explicitly turned on, and probably need other
  72. mrgems, mruby is manged by git submodule under third-party/mruby
  73. directory. Currently, mruby support for nghttpx is disabled by
  74. default. To enable mruby support, use ``--with-mruby`` configure
  75. option. Note that at the time of this writing, libmruby-dev and mruby
  76. packages in Debian/Ubuntu are not usable for nghttp2, since they do
  77. not enable C++ ABI. To build mruby, the following packages are
  78. required:
  79. * ruby
  80. * bison
  81. nghttpx supports `neverbleed <https://github.com/h2o/neverbleed>`_,
  82. privilege separation engine for OpenSSL / LibreSSL. In short, it
  83. minimizes the risk of private key leakage when serious bug like
  84. Heartbleed is exploited. The neverbleed is disabled by default. To
  85. enable it, use ``--with-neverbleed`` configure option.
  86. To enable the experimental HTTP/3 support for h2load and nghttpx, the
  87. following libraries are required:
  88. * `OpenSSL with QUIC support
  89. <https://github.com/quictls/openssl/tree/OpenSSL_1_1_1w+quic>`_; or
  90. `BoringSSL <https://boringssl.googlesource.com/boringssl/>`_ (commit
  91. 6ca49385b168f47a50e7172d82a590b218f55e4d)
  92. * `ngtcp2 <https://github.com/ngtcp2/ngtcp2>`_ >= 1.0.0
  93. * `nghttp3 <https://github.com/ngtcp2/nghttp3>`_ >= 1.0.0
  94. Use ``--enable-http3`` configure option to enable HTTP/3 feature for
  95. h2load and nghttpx.
  96. In order to build optional eBPF program to direct an incoming QUIC UDP
  97. datagram to a correct socket for nghttpx, the following libraries are
  98. required:
  99. * libbpf-dev >= 0.7.0
  100. Use ``--with-libbpf`` configure option to build eBPF program.
  101. libelf-dev is needed to build libbpf.
  102. For Ubuntu 20.04, you can build libbpf from `the source code
  103. <https://github.com/libbpf/libbpf/releases/tag/v1.2.2>`_. nghttpx
  104. requires eBPF program for reloading its configuration and hot swapping
  105. its executable.
  106. Compiling libnghttp2 C source code requires a C99 compiler. gcc 4.8
  107. is known to be adequate. In order to compile the C++ source code, gcc
  108. >= 6.0 or clang >= 6.0 is required. C++ source code requires C++14
  109. language features.
  110. .. note::
  111. To enable mruby support in nghttpx, and use ``--with-mruby``
  112. configure option.
  113. .. note::
  114. Mac OS X users may need the ``--disable-threads`` configure option to
  115. disable multi-threading in nghttpd, nghttpx and h2load to prevent
  116. them from crashing. A patch is welcome to make multi threading work
  117. on Mac OS X platform.
  118. .. note::
  119. To compile the associated applications (nghttp, nghttpd, nghttpx
  120. and h2load), you must use the ``--enable-app`` configure option and
  121. ensure that the specified requirements above are met. Normally,
  122. configure script checks required dependencies to build these
  123. applications, and enable ``--enable-app`` automatically, so you
  124. don't have to use it explicitly. But if you found that
  125. applications were not built, then using ``--enable-app`` may find
  126. that cause, such as the missing dependency.
  127. .. note::
  128. In order to detect third party libraries, pkg-config is used
  129. (however we don't use pkg-config for some libraries (e.g., libev)).
  130. By default, pkg-config searches ``*.pc`` file in the standard
  131. locations (e.g., /usr/lib/pkgconfig). If it is necessary to use
  132. ``*.pc`` file in the custom location, specify paths to
  133. ``PKG_CONFIG_PATH`` environment variable, and pass it to configure
  134. script, like so:
  135. .. code-block:: text
  136. $ ./configure PKG_CONFIG_PATH=/path/to/pkgconfig
  137. For pkg-config managed libraries, ``*_CFLAG`` and ``*_LIBS``
  138. environment variables are defined (e.g., ``OPENSSL_CFLAGS``,
  139. ``OPENSSL_LIBS``). Specifying non-empty string to these variables
  140. completely overrides pkg-config. In other words, if they are
  141. specified, pkg-config is not used for detection, and user is
  142. responsible to specify the correct values to these variables. For
  143. complete list of these variables, run ``./configure -h``.
  144. If you are using Ubuntu 22.04 LTS, run the following to install the
  145. required packages:
  146. .. code-block:: text
  147. sudo apt-get install g++ clang make binutils autoconf automake \
  148. autotools-dev libtool pkg-config \
  149. zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev \
  150. libevent-dev libjansson-dev \
  151. libc-ares-dev libjemalloc-dev libsystemd-dev \
  152. ruby-dev bison libelf-dev
  153. Building nghttp2 from release tar archive
  154. -----------------------------------------
  155. The nghttp2 project regularly releases tar archives which includes
  156. nghttp2 source code, and generated build files. They can be
  157. downloaded from `Releases
  158. <https://github.com/nghttp2/nghttp2/releases>`_ page.
  159. Building nghttp2 from git requires autotools development packages.
  160. Building from tar archives does not require them, and thus it is much
  161. easier. The usual build step is as follows:
  162. .. code-block:: text
  163. $ tar xf nghttp2-X.Y.Z.tar.bz2
  164. $ cd nghttp2-X.Y.Z
  165. $ ./configure
  166. $ make
  167. Building from git
  168. -----------------
  169. Building from git is easy, but please be sure that at least autoconf 2.68 is
  170. used:
  171. .. code-block:: text
  172. $ git submodule update --init
  173. $ autoreconf -i
  174. $ automake
  175. $ autoconf
  176. $ ./configure
  177. $ make
  178. Notes for building on Windows (MSVC)
  179. ------------------------------------
  180. The easiest way to build native Windows nghttp2 dll is use `cmake
  181. <https://cmake.org/>`_. The free version of `Visual C++ Build Tools
  182. <http://landinghub.visualstudio.com/visual-cpp-build-tools>`_ works
  183. fine.
  184. 1. Install cmake for windows
  185. 2. Open "Visual C++ ... Native Build Tool Command Prompt", and inside
  186. nghttp2 directly, run ``cmake``.
  187. 3. Then run ``cmake --build`` to build library.
  188. 4. nghttp2.dll, nghttp2.lib, nghttp2.exp are placed under lib directory.
  189. Note that the above steps most likely produce nghttp2 library only.
  190. No bundled applications are compiled.
  191. Notes for building on Windows (Mingw/Cygwin)
  192. --------------------------------------------
  193. Under Mingw environment, you can only compile the library, it's
  194. ``libnghttp2-X.dll`` and ``libnghttp2.a``.
  195. If you want to compile the applications(``h2load``, ``nghttp``,
  196. ``nghttpx``, ``nghttpd``), you need to use the Cygwin environment.
  197. Under Cygwin environment, to compile the applications you need to
  198. compile and install the libev first.
  199. Secondly, you need to undefine the macro ``__STRICT_ANSI__``, if you
  200. not, the functions ``fdopen``, ``fileno`` and ``strptime`` will not
  201. available.
  202. the sample command like this:
  203. .. code-block:: text
  204. $ export CFLAGS="-U__STRICT_ANSI__ -I$libev_PREFIX/include -L$libev_PREFIX/lib"
  205. $ export CXXFLAGS=$CFLAGS
  206. $ ./configure
  207. $ make
  208. If you want to compile the applications under ``examples/``, you need
  209. to remove or rename the ``event.h`` from libev's installation, because
  210. it conflicts with libevent's installation.
  211. Notes for installation on Linux systems
  212. --------------------------------------------
  213. After installing nghttp2 tool suite with ``make install`` one might experience a similar error:
  214. .. code-block:: text
  215. nghttpx: error while loading shared libraries: libnghttp2.so.14: cannot open shared object file: No such file or directory
  216. This means that the tool is unable to locate the ``libnghttp2.so`` shared library.
  217. To update the shared library cache run ``sudo ldconfig``.
  218. Building the documentation
  219. --------------------------
  220. .. note::
  221. Documentation is still incomplete.
  222. To build the documentation, run:
  223. .. code-block:: text
  224. $ make html
  225. The documents will be generated under ``doc/manual/html/``.
  226. The generated documents will not be installed with ``make install``.
  227. The online documentation is available at
  228. https://nghttp2.org/documentation/
  229. Build HTTP/3 enabled h2load and nghttpx
  230. ---------------------------------------
  231. To build h2load and nghttpx with HTTP/3 feature enabled, run the
  232. configure script with ``--enable-http3``.
  233. For nghttpx to reload configurations and swapping its executable while
  234. gracefully terminating old worker processes, eBPF is required. Run
  235. the configure script with ``--enable-http3 --with-libbpf`` to build
  236. eBPF program. The QUIC keying material must be set with
  237. ``--frontend-quic-secret-file`` in order to keep the existing
  238. connections alive during reload.
  239. The detailed steps to build HTTP/3 enabled h2load and nghttpx follow.
  240. Build custom OpenSSL:
  241. .. code-block:: text
  242. $ git clone --depth 1 -b OpenSSL_1_1_1w+quic https://github.com/quictls/openssl
  243. $ cd openssl
  244. $ ./config --prefix=$PWD/build --openssldir=/etc/ssl
  245. $ make -j$(nproc)
  246. $ make install_sw
  247. $ cd ..
  248. Build nghttp3:
  249. .. code-block:: text
  250. $ git clone --depth 1 -b v1.0.0 https://github.com/ngtcp2/nghttp3
  251. $ cd nghttp3
  252. $ autoreconf -i
  253. $ ./configure --prefix=$PWD/build --enable-lib-only
  254. $ make -j$(nproc)
  255. $ make install
  256. $ cd ..
  257. Build ngtcp2:
  258. .. code-block:: text
  259. $ git clone --depth 1 -b v1.0.1 https://github.com/ngtcp2/ngtcp2
  260. $ cd ngtcp2
  261. $ autoreconf -i
  262. $ ./configure --prefix=$PWD/build --enable-lib-only \
  263. PKG_CONFIG_PATH="$PWD/../openssl/build/lib/pkgconfig"
  264. $ make -j$(nproc)
  265. $ make install
  266. $ cd ..
  267. If your Linux distribution does not have libbpf-dev >= 0.7.0, build
  268. from source:
  269. .. code-block:: text
  270. $ git clone --depth 1 -b v1.2.2 https://github.com/libbpf/libbpf
  271. $ cd libbpf
  272. $ PREFIX=$PWD/build make -C src install
  273. $ cd ..
  274. Build nghttp2:
  275. .. code-block:: text
  276. $ git clone https://github.com/nghttp2/nghttp2
  277. $ cd nghttp2
  278. $ git submodule update --init
  279. $ autoreconf -i
  280. $ ./configure --with-mruby --with-neverbleed --enable-http3 --with-libbpf \
  281. CC=clang-14 CXX=clang++-14 \
  282. PKG_CONFIG_PATH="$PWD/../openssl/build/lib/pkgconfig:$PWD/../nghttp3/build/lib/pkgconfig:$PWD/../ngtcp2/build/lib/pkgconfig:$PWD/../libbpf/build/lib64/pkgconfig" \
  283. LDFLAGS="$LDFLAGS -Wl,-rpath,$PWD/../openssl/build/lib -Wl,-rpath,$PWD/../libbpf/build/lib64"
  284. $ make -j$(nproc)
  285. The eBPF program ``reuseport_kern.o`` should be found under bpf
  286. directory. Pass ``--quic-bpf-program-file=bpf/reuseport_kern.o``
  287. option to nghttpx to load it. See also `HTTP/3 section in nghttpx -
  288. HTTP/2 proxy - HOW-TO
  289. <https://nghttp2.org/documentation/nghttpx-howto.html#http-3>`_.
  290. Unit tests
  291. ----------
  292. Unit tests are done by simply running ``make check``.
  293. Integration tests
  294. -----------------
  295. We have the integration tests for the nghttpx proxy server. The tests are
  296. written in the `Go programming language <http://golang.org/>`_ and uses
  297. its testing framework. We depend on the following libraries:
  298. * golang.org/x/net/http2
  299. * golang.org/x/net/websocket
  300. * https://github.com/tatsuhiro-t/go-nghttp2
  301. Go modules will download these dependencies automatically.
  302. To run the tests, run the following command under
  303. ``integration-tests`` directory:
  304. .. code-block:: text
  305. $ make it
  306. Inside the tests, we use port 3009 to run the test subject server.
  307. Migration from v0.7.15 or earlier
  308. ---------------------------------
  309. nghttp2 v1.0.0 introduced several backward incompatible changes. In
  310. this section, we describe these changes and how to migrate to v1.0.0.
  311. ALPN protocol ID is now ``h2`` and ``h2c``
  312. ++++++++++++++++++++++++++++++++++++++++++
  313. Previously we announced ``h2-14`` and ``h2c-14``. v1.0.0 implements
  314. final protocol version, and we changed ALPN ID to ``h2`` and ``h2c``.
  315. The macros ``NGHTTP2_PROTO_VERSION_ID``,
  316. ``NGHTTP2_PROTO_VERSION_ID_LEN``,
  317. ``NGHTTP2_CLEARTEXT_PROTO_VERSION_ID``, and
  318. ``NGHTTP2_CLEARTEXT_PROTO_VERSION_ID_LEN`` have been updated to
  319. reflect this change.
  320. Basically, existing applications do not have to do anything, just
  321. recompiling is enough for this change.
  322. Use word "client magic" where we use "client connection preface"
  323. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  324. We use "client connection preface" to mean first 24 bytes of client
  325. connection preface. This is technically not correct, since client
  326. connection preface is composed of 24 bytes client magic byte string
  327. followed by SETTINGS frame. For clarification, we call "client magic"
  328. for this 24 bytes byte string and updated API.
  329. * ``NGHTTP2_CLIENT_CONNECTION_PREFACE`` was replaced with
  330. ``NGHTTP2_CLIENT_MAGIC``.
  331. * ``NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN`` was replaced with
  332. ``NGHTTP2_CLIENT_MAGIC_LEN``.
  333. * ``NGHTTP2_BAD_PREFACE`` was renamed as ``NGHTTP2_BAD_CLIENT_MAGIC``
  334. The already deprecated ``NGHTTP2_CLIENT_CONNECTION_HEADER`` and
  335. ``NGHTTP2_CLIENT_CONNECTION_HEADER_LEN`` were removed.
  336. If application uses these macros, just replace old ones with new ones.
  337. Since v1.0.0, client magic is sent by library (see next subsection),
  338. so client application may just remove these macro use.
  339. Client magic is sent by library
  340. +++++++++++++++++++++++++++++++
  341. Previously nghttp2 library did not send client magic, which is first
  342. 24 bytes byte string of client connection preface, and client
  343. applications have to send it by themselves. Since v1.0.0, client
  344. magic is sent by library via first call of ``nghttp2_session_send()``
  345. or ``nghttp2_session_mem_send()``.
  346. The client applications which send client magic must remove the
  347. relevant code.
  348. Remove HTTP Alternative Services (Alt-Svc) related code
  349. +++++++++++++++++++++++++++++++++++++++++++++++++++++++
  350. Alt-Svc specification is not finalized yet. To make our API stable,
  351. we have decided to remove all Alt-Svc related API from nghttp2.
  352. * ``NGHTTP2_EXT_ALTSVC`` was removed.
  353. * ``nghttp2_ext_altsvc`` was removed.
  354. We have already removed the functionality of Alt-Svc in v0.7 series
  355. and they have been essentially noop. The application using these
  356. macro and struct, remove those lines.
  357. Use nghttp2_error in nghttp2_on_invalid_frame_recv_callback
  358. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  359. Previously ``nghttp2_on_invalid_frame_recv_cb_called`` took the
  360. ``error_code``, defined in ``nghttp2_error_code``, as parameter. But
  361. they are not detailed enough to debug. Therefore, we decided to use
  362. more detailed ``nghttp2_error`` values instead.
  363. The application using this callback should update the callback
  364. signature. If it treats ``error_code`` as HTTP/2 error code, update
  365. the code so that it is treated as ``nghttp2_error``.
  366. Receive client magic by default
  367. +++++++++++++++++++++++++++++++
  368. Previously nghttp2 did not process client magic (24 bytes byte
  369. string). To make it deal with it, we had to use
  370. ``nghttp2_option_set_recv_client_preface()``. Since v1.0.0, nghttp2
  371. processes client magic by default and
  372. ``nghttp2_option_set_recv_client_preface()`` was removed.
  373. Some application may want to disable this behaviour, so we added
  374. ``nghttp2_option_set_no_recv_client_magic()`` to achieve this.
  375. The application using ``nghttp2_option_set_recv_client_preface()``
  376. with nonzero value, just remove it.
  377. The application using ``nghttp2_option_set_recv_client_preface()``
  378. with zero value or not using it must use
  379. ``nghttp2_option_set_no_recv_client_magic()`` with nonzero value.
  380. Client, Server and Proxy programs
  381. ---------------------------------
  382. The ``src`` directory contains the HTTP/2 client, server and proxy programs.
  383. nghttp - client
  384. +++++++++++++++
  385. ``nghttp`` is a HTTP/2 client. It can connect to the HTTP/2 server
  386. with prior knowledge, HTTP Upgrade and NPN/ALPN TLS extension.
  387. It has verbose output mode for framing information. Here is sample
  388. output from ``nghttp`` client:
  389. .. code-block:: text
  390. $ nghttp -nv https://nghttp2.org
  391. [ 0.190] Connected
  392. The negotiated protocol: h2
  393. [ 0.212] recv SETTINGS frame <length=12, flags=0x00, stream_id=0>
  394. (niv=2)
  395. [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
  396. [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
  397. [ 0.212] send SETTINGS frame <length=12, flags=0x00, stream_id=0>
  398. (niv=2)
  399. [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
  400. [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
  401. [ 0.212] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
  402. ; ACK
  403. (niv=0)
  404. [ 0.212] send PRIORITY frame <length=5, flags=0x00, stream_id=3>
  405. (dep_stream_id=0, weight=201, exclusive=0)
  406. [ 0.212] send PRIORITY frame <length=5, flags=0x00, stream_id=5>
  407. (dep_stream_id=0, weight=101, exclusive=0)
  408. [ 0.212] send PRIORITY frame <length=5, flags=0x00, stream_id=7>
  409. (dep_stream_id=0, weight=1, exclusive=0)
  410. [ 0.212] send PRIORITY frame <length=5, flags=0x00, stream_id=9>
  411. (dep_stream_id=7, weight=1, exclusive=0)
  412. [ 0.212] send PRIORITY frame <length=5, flags=0x00, stream_id=11>
  413. (dep_stream_id=3, weight=1, exclusive=0)
  414. [ 0.212] send HEADERS frame <length=39, flags=0x25, stream_id=13>
  415. ; END_STREAM | END_HEADERS | PRIORITY
  416. (padlen=0, dep_stream_id=11, weight=16, exclusive=0)
  417. ; Open new stream
  418. :method: GET
  419. :path: /
  420. :scheme: https
  421. :authority: nghttp2.org
  422. accept: */*
  423. accept-encoding: gzip, deflate
  424. user-agent: nghttp2/1.0.1-DEV
  425. [ 0.221] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
  426. ; ACK
  427. (niv=0)
  428. [ 0.221] recv (stream_id=13) :method: GET
  429. [ 0.221] recv (stream_id=13) :scheme: https
  430. [ 0.221] recv (stream_id=13) :path: /stylesheets/screen.css
  431. [ 0.221] recv (stream_id=13) :authority: nghttp2.org
  432. [ 0.221] recv (stream_id=13) accept-encoding: gzip, deflate
  433. [ 0.222] recv (stream_id=13) user-agent: nghttp2/1.0.1-DEV
  434. [ 0.222] recv PUSH_PROMISE frame <length=50, flags=0x04, stream_id=13>
  435. ; END_HEADERS
  436. (padlen=0, promised_stream_id=2)
  437. [ 0.222] recv (stream_id=13) :status: 200
  438. [ 0.222] recv (stream_id=13) date: Thu, 21 May 2015 16:38:14 GMT
  439. [ 0.222] recv (stream_id=13) content-type: text/html
  440. [ 0.222] recv (stream_id=13) last-modified: Fri, 15 May 2015 15:38:06 GMT
  441. [ 0.222] recv (stream_id=13) etag: W/"555612de-19f6"
  442. [ 0.222] recv (stream_id=13) link: </stylesheets/screen.css>; rel=preload; as=stylesheet
  443. [ 0.222] recv (stream_id=13) content-encoding: gzip
  444. [ 0.222] recv (stream_id=13) server: nghttpx nghttp2/1.0.1-DEV
  445. [ 0.222] recv (stream_id=13) via: 1.1 nghttpx
  446. [ 0.222] recv (stream_id=13) strict-transport-security: max-age=31536000
  447. [ 0.222] recv HEADERS frame <length=166, flags=0x04, stream_id=13>
  448. ; END_HEADERS
  449. (padlen=0)
  450. ; First response header
  451. [ 0.222] recv DATA frame <length=2601, flags=0x01, stream_id=13>
  452. ; END_STREAM
  453. [ 0.222] recv (stream_id=2) :status: 200
  454. [ 0.222] recv (stream_id=2) date: Thu, 21 May 2015 16:38:14 GMT
  455. [ 0.222] recv (stream_id=2) content-type: text/css
  456. [ 0.222] recv (stream_id=2) last-modified: Fri, 15 May 2015 15:38:06 GMT
  457. [ 0.222] recv (stream_id=2) etag: W/"555612de-9845"
  458. [ 0.222] recv (stream_id=2) content-encoding: gzip
  459. [ 0.222] recv (stream_id=2) server: nghttpx nghttp2/1.0.1-DEV
  460. [ 0.222] recv (stream_id=2) via: 1.1 nghttpx
  461. [ 0.222] recv (stream_id=2) strict-transport-security: max-age=31536000
  462. [ 0.222] recv HEADERS frame <length=32, flags=0x04, stream_id=2>
  463. ; END_HEADERS
  464. (padlen=0)
  465. ; First push response header
  466. [ 0.228] recv DATA frame <length=8715, flags=0x01, stream_id=2>
  467. ; END_STREAM
  468. [ 0.228] send GOAWAY frame <length=8, flags=0x00, stream_id=0>
  469. (last_stream_id=2, error_code=NO_ERROR(0x00), opaque_data(0)=[])
  470. The HTTP Upgrade is performed like so:
  471. .. code-block:: text
  472. $ nghttp -nvu http://nghttp2.org
  473. [ 0.011] Connected
  474. [ 0.011] HTTP Upgrade request
  475. GET / HTTP/1.1
  476. Host: nghttp2.org
  477. Connection: Upgrade, HTTP2-Settings
  478. Upgrade: h2c
  479. HTTP2-Settings: AAMAAABkAAQAAP__
  480. Accept: */*
  481. User-Agent: nghttp2/1.0.1-DEV
  482. [ 0.018] HTTP Upgrade response
  483. HTTP/1.1 101 Switching Protocols
  484. Connection: Upgrade
  485. Upgrade: h2c
  486. [ 0.018] HTTP Upgrade success
  487. [ 0.018] recv SETTINGS frame <length=12, flags=0x00, stream_id=0>
  488. (niv=2)
  489. [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
  490. [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
  491. [ 0.018] send SETTINGS frame <length=12, flags=0x00, stream_id=0>
  492. (niv=2)
  493. [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
  494. [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
  495. [ 0.018] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
  496. ; ACK
  497. (niv=0)
  498. [ 0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=3>
  499. (dep_stream_id=0, weight=201, exclusive=0)
  500. [ 0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=5>
  501. (dep_stream_id=0, weight=101, exclusive=0)
  502. [ 0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=7>
  503. (dep_stream_id=0, weight=1, exclusive=0)
  504. [ 0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=9>
  505. (dep_stream_id=7, weight=1, exclusive=0)
  506. [ 0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=11>
  507. (dep_stream_id=3, weight=1, exclusive=0)
  508. [ 0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=1>
  509. (dep_stream_id=11, weight=16, exclusive=0)
  510. [ 0.019] recv (stream_id=1) :method: GET
  511. [ 0.019] recv (stream_id=1) :scheme: http
  512. [ 0.019] recv (stream_id=1) :path: /stylesheets/screen.css
  513. [ 0.019] recv (stream_id=1) host: nghttp2.org
  514. [ 0.019] recv (stream_id=1) user-agent: nghttp2/1.0.1-DEV
  515. [ 0.019] recv PUSH_PROMISE frame <length=49, flags=0x04, stream_id=1>
  516. ; END_HEADERS
  517. (padlen=0, promised_stream_id=2)
  518. [ 0.019] recv (stream_id=1) :status: 200
  519. [ 0.019] recv (stream_id=1) date: Thu, 21 May 2015 16:39:16 GMT
  520. [ 0.019] recv (stream_id=1) content-type: text/html
  521. [ 0.019] recv (stream_id=1) content-length: 6646
  522. [ 0.019] recv (stream_id=1) last-modified: Fri, 15 May 2015 15:38:06 GMT
  523. [ 0.019] recv (stream_id=1) etag: "555612de-19f6"
  524. [ 0.019] recv (stream_id=1) link: </stylesheets/screen.css>; rel=preload; as=stylesheet
  525. [ 0.019] recv (stream_id=1) accept-ranges: bytes
  526. [ 0.019] recv (stream_id=1) server: nghttpx nghttp2/1.0.1-DEV
  527. [ 0.019] recv (stream_id=1) via: 1.1 nghttpx
  528. [ 0.019] recv HEADERS frame <length=157, flags=0x04, stream_id=1>
  529. ; END_HEADERS
  530. (padlen=0)
  531. ; First response header
  532. [ 0.019] recv DATA frame <length=6646, flags=0x01, stream_id=1>
  533. ; END_STREAM
  534. [ 0.019] recv (stream_id=2) :status: 200
  535. [ 0.019] recv (stream_id=2) date: Thu, 21 May 2015 16:39:16 GMT
  536. [ 0.019] recv (stream_id=2) content-type: text/css
  537. [ 0.019] recv (stream_id=2) content-length: 38981
  538. [ 0.019] recv (stream_id=2) last-modified: Fri, 15 May 2015 15:38:06 GMT
  539. [ 0.019] recv (stream_id=2) etag: "555612de-9845"
  540. [ 0.019] recv (stream_id=2) accept-ranges: bytes
  541. [ 0.019] recv (stream_id=2) server: nghttpx nghttp2/1.0.1-DEV
  542. [ 0.019] recv (stream_id=2) via: 1.1 nghttpx
  543. [ 0.019] recv HEADERS frame <length=36, flags=0x04, stream_id=2>
  544. ; END_HEADERS
  545. (padlen=0)
  546. ; First push response header
  547. [ 0.026] recv DATA frame <length=16384, flags=0x00, stream_id=2>
  548. [ 0.027] recv DATA frame <length=7952, flags=0x00, stream_id=2>
  549. [ 0.027] send WINDOW_UPDATE frame <length=4, flags=0x00, stream_id=0>
  550. (window_size_increment=33343)
  551. [ 0.032] send WINDOW_UPDATE frame <length=4, flags=0x00, stream_id=2>
  552. (window_size_increment=33707)
  553. [ 0.032] recv DATA frame <length=14645, flags=0x01, stream_id=2>
  554. ; END_STREAM
  555. [ 0.032] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
  556. ; ACK
  557. (niv=0)
  558. [ 0.032] send GOAWAY frame <length=8, flags=0x00, stream_id=0>
  559. (last_stream_id=2, error_code=NO_ERROR(0x00), opaque_data(0)=[])
  560. Using the ``-s`` option, ``nghttp`` prints out some timing information for
  561. requests, sorted by completion time:
  562. .. code-block:: text
  563. $ nghttp -nas https://nghttp2.org/
  564. ***** Statistics *****
  565. Request timing:
  566. responseEnd: the time when last byte of response was received
  567. relative to connectEnd
  568. requestStart: the time just before first byte of request was sent
  569. relative to connectEnd. If '*' is shown, this was
  570. pushed by server.
  571. process: responseEnd - requestStart
  572. code: HTTP status code
  573. size: number of bytes received as response body without
  574. inflation.
  575. URI: request URI
  576. see http://www.w3.org/TR/resource-timing/#processing-model
  577. sorted by 'complete'
  578. id responseEnd requestStart process code size request path
  579. 13 +37.19ms +280us 36.91ms 200 2K /
  580. 2 +72.65ms * +36.38ms 36.26ms 200 8K /stylesheets/screen.css
  581. 17 +77.43ms +38.67ms 38.75ms 200 3K /javascripts/octopress.js
  582. 15 +78.12ms +38.66ms 39.46ms 200 3K /javascripts/modernizr-2.0.js
  583. Using the ``-r`` option, ``nghttp`` writes more detailed timing data to
  584. the given file in HAR format.
  585. nghttpd - server
  586. ++++++++++++++++
  587. ``nghttpd`` is a multi-threaded static web server.
  588. By default, it uses SSL/TLS connection. Use ``--no-tls`` option to
  589. disable it.
  590. ``nghttpd`` only accepts HTTP/2 connections via NPN/ALPN or direct
  591. HTTP/2 connections. No HTTP Upgrade is supported.
  592. The ``-p`` option allows users to configure server push.
  593. Just like ``nghttp``, it has a verbose output mode for framing
  594. information. Here is sample output from ``nghttpd``:
  595. .. code-block:: text
  596. $ nghttpd --no-tls -v 8080
  597. IPv4: listen 0.0.0.0:8080
  598. IPv6: listen :::8080
  599. [id=1] [ 1.521] send SETTINGS frame <length=6, flags=0x00, stream_id=0>
  600. (niv=1)
  601. [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
  602. [id=1] [ 1.521] recv SETTINGS frame <length=12, flags=0x00, stream_id=0>
  603. (niv=2)
  604. [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
  605. [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
  606. [id=1] [ 1.521] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
  607. ; ACK
  608. (niv=0)
  609. [id=1] [ 1.521] recv PRIORITY frame <length=5, flags=0x00, stream_id=3>
  610. (dep_stream_id=0, weight=201, exclusive=0)
  611. [id=1] [ 1.521] recv PRIORITY frame <length=5, flags=0x00, stream_id=5>
  612. (dep_stream_id=0, weight=101, exclusive=0)
  613. [id=1] [ 1.521] recv PRIORITY frame <length=5, flags=0x00, stream_id=7>
  614. (dep_stream_id=0, weight=1, exclusive=0)
  615. [id=1] [ 1.521] recv PRIORITY frame <length=5, flags=0x00, stream_id=9>
  616. (dep_stream_id=7, weight=1, exclusive=0)
  617. [id=1] [ 1.521] recv PRIORITY frame <length=5, flags=0x00, stream_id=11>
  618. (dep_stream_id=3, weight=1, exclusive=0)
  619. [id=1] [ 1.521] recv (stream_id=13) :method: GET
  620. [id=1] [ 1.521] recv (stream_id=13) :path: /
  621. [id=1] [ 1.521] recv (stream_id=13) :scheme: http
  622. [id=1] [ 1.521] recv (stream_id=13) :authority: localhost:8080
  623. [id=1] [ 1.521] recv (stream_id=13) accept: */*
  624. [id=1] [ 1.521] recv (stream_id=13) accept-encoding: gzip, deflate
  625. [id=1] [ 1.521] recv (stream_id=13) user-agent: nghttp2/1.0.0-DEV
  626. [id=1] [ 1.521] recv HEADERS frame <length=41, flags=0x25, stream_id=13>
  627. ; END_STREAM | END_HEADERS | PRIORITY
  628. (padlen=0, dep_stream_id=11, weight=16, exclusive=0)
  629. ; Open new stream
  630. [id=1] [ 1.521] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
  631. ; ACK
  632. (niv=0)
  633. [id=1] [ 1.521] send HEADERS frame <length=86, flags=0x04, stream_id=13>
  634. ; END_HEADERS
  635. (padlen=0)
  636. ; First response header
  637. :status: 200
  638. server: nghttpd nghttp2/1.0.0-DEV
  639. content-length: 10
  640. cache-control: max-age=3600
  641. date: Fri, 15 May 2015 14:49:04 GMT
  642. last-modified: Tue, 30 Sep 2014 12:40:52 GMT
  643. [id=1] [ 1.522] send DATA frame <length=10, flags=0x01, stream_id=13>
  644. ; END_STREAM
  645. [id=1] [ 1.522] stream_id=13 closed
  646. [id=1] [ 1.522] recv GOAWAY frame <length=8, flags=0x00, stream_id=0>
  647. (last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[])
  648. [id=1] [ 1.522] closed
  649. nghttpx - proxy
  650. +++++++++++++++
  651. ``nghttpx`` is a multi-threaded reverse proxy for HTTP/3, HTTP/2, and
  652. HTTP/1.1, and powers http://nghttp2.org and supports HTTP/2 server
  653. push.
  654. We reworked ``nghttpx`` command-line interface, and as a result, there
  655. are several incompatibles from 1.8.0 or earlier. This is necessary to
  656. extend its capability, and secure the further feature enhancements in
  657. the future release. Please read `Migration from nghttpx v1.8.0 or
  658. earlier
  659. <https://nghttp2.org/documentation/nghttpx-howto.html#migration-from-nghttpx-v1-8-0-or-earlier>`_
  660. to know how to migrate from earlier releases.
  661. ``nghttpx`` implements `important performance-oriented features
  662. <https://istlsfastyet.com/#server-performance>`_ in TLS, such as
  663. session IDs, session tickets (with automatic key rotation), OCSP
  664. stapling, dynamic record sizing, ALPN/NPN, forward secrecy and HTTP/2.
  665. ``nghttpx`` also offers the functionality to share session cache and
  666. ticket keys among multiple ``nghttpx`` instances via memcached.
  667. ``nghttpx`` has 2 operation modes:
  668. ================== ======================== ================ =============
  669. Mode option Frontend Backend Note
  670. ================== ======================== ================ =============
  671. default mode HTTP/3, HTTP/2, HTTP/1.1 HTTP/1.1, HTTP/2 Reverse proxy
  672. ``--http2-proxy`` HTTP/3, HTTP/2, HTTP/1.1 HTTP/1.1, HTTP/2 Forward proxy
  673. ================== ======================== ================ =============
  674. The interesting mode at the moment is the default mode. It works like
  675. a reverse proxy and listens for HTTP/3, HTTP/2, and HTTP/1.1 and can
  676. be deployed as a SSL/TLS terminator for existing web server.
  677. In all modes, the frontend connections are encrypted by SSL/TLS by
  678. default. To disable encryption, use the ``no-tls`` keyword in
  679. ``--frontend`` option. If encryption is disabled, incoming HTTP/1.1
  680. connections can be upgraded to HTTP/2 through HTTP Upgrade. On the
  681. other hard, backend connections are not encrypted by default. To
  682. encrypt backend connections, use ``tls`` keyword in ``--backend``
  683. option.
  684. ``nghttpx`` supports a configuration file. See the ``--conf`` option and
  685. sample configuration file ``nghttpx.conf.sample``.
  686. In the default mode, ``nghttpx`` works as reverse proxy to the backend
  687. server:
  688. .. code-block:: text
  689. Client <-- (HTTP/3, HTTP/2, HTTP/1.1) --> nghttpx <-- (HTTP/1.1, HTTP/2) --> Web Server
  690. [reverse proxy]
  691. With the ``--http2-proxy`` option, it works as forward proxy, and it
  692. is so called secure HTTP/2 proxy:
  693. .. code-block:: text
  694. Client <-- (HTTP/3, HTTP/2, HTTP/1.1) --> nghttpx <-- (HTTP/1.1) --> Proxy
  695. [secure proxy] (e.g., Squid, ATS)
  696. The ``Client`` in the above example needs to be configured to use
  697. ``nghttpx`` as secure proxy.
  698. At the time of this writing, both Chrome and Firefox support secure
  699. HTTP/2 proxy. One way to configure Chrome to use a secure proxy is to
  700. create a proxy.pac script like this:
  701. .. code-block:: javascript
  702. function FindProxyForURL(url, host) {
  703. return "HTTPS SERVERADDR:PORT";
  704. }
  705. ``SERVERADDR`` and ``PORT`` is the hostname/address and port of the
  706. machine nghttpx is running on. Please note that Chrome requires a valid
  707. certificate for secure proxy.
  708. Then run Chrome with the following arguments:
  709. .. code-block:: text
  710. $ google-chrome --proxy-pac-url=file:///path/to/proxy.pac --use-npn
  711. The backend HTTP/2 connections can be tunneled through an HTTP proxy.
  712. The proxy is specified using ``--backend-http-proxy-uri``. The
  713. following figure illustrates how nghttpx talks to the outside HTTP/2
  714. proxy through an HTTP proxy:
  715. .. code-block:: text
  716. Client <-- (HTTP/3, HTTP/2, HTTP/1.1) --> nghttpx <-- (HTTP/2) --
  717. --===================---> HTTP/2 Proxy
  718. (HTTP proxy tunnel) (e.g., nghttpx -s)
  719. Benchmarking tool
  720. -----------------
  721. The ``h2load`` program is a benchmarking tool for HTTP/3, HTTP/2, and
  722. HTTP/1.1. The UI of ``h2load`` is heavily inspired by ``weighttp``
  723. (https://github.com/lighttpd/weighttp). The typical usage is as
  724. follows:
  725. .. code-block:: text
  726. $ h2load -n100000 -c100 -m100 https://localhost:8443/
  727. starting benchmark...
  728. spawning thread #0: 100 concurrent clients, 100000 total requests
  729. Protocol: TLSv1.2
  730. Cipher: ECDHE-RSA-AES128-GCM-SHA256
  731. Server Temp Key: ECDH P-256 256 bits
  732. progress: 10% done
  733. progress: 20% done
  734. progress: 30% done
  735. progress: 40% done
  736. progress: 50% done
  737. progress: 60% done
  738. progress: 70% done
  739. progress: 80% done
  740. progress: 90% done
  741. progress: 100% done
  742. finished in 771.26ms, 129658 req/s, 4.71MB/s
  743. requests: 100000 total, 100000 started, 100000 done, 100000 succeeded, 0 failed, 0 errored
  744. status codes: 100000 2xx, 0 3xx, 0 4xx, 0 5xx
  745. traffic: 3812300 bytes total, 1009900 bytes headers, 1000000 bytes data
  746. min max mean sd +/- sd
  747. time for request: 25.12ms 124.55ms 51.07ms 15.36ms 84.87%
  748. time for connect: 208.94ms 254.67ms 241.38ms 7.95ms 63.00%
  749. time to 1st byte: 209.11ms 254.80ms 241.51ms 7.94ms 63.00%
  750. The above example issued total 100,000 requests, using 100 concurrent
  751. clients (in other words, 100 HTTP/2 sessions), and a maximum of 100 streams
  752. per client. With the ``-t`` option, ``h2load`` will use multiple native
  753. threads to avoid saturating a single core on client side.
  754. .. warning::
  755. **Don't use this tool against publicly available servers.** That is
  756. considered a DOS attack. Please only use it against your private
  757. servers.
  758. If the experimental HTTP/3 is enabled, h2load can send requests to
  759. HTTP/3 server. To do this, specify ``h3`` to ``--npn-list`` option
  760. like so:
  761. .. code-block:: text
  762. $ h2load --npn-list h3 https://127.0.0.1:4433
  763. HPACK tools
  764. -----------
  765. The ``src`` directory contains the HPACK tools. The ``deflatehd`` program is a
  766. command-line header compression tool. The ``inflatehd`` program is a
  767. command-line header decompression tool. Both tools read input from
  768. stdin and write output to stdout. Errors are written to stderr.
  769. They take JSON as input and output. We (mostly) use the same JSON data
  770. format described at https://github.com/http2jp/hpack-test-case.
  771. deflatehd - header compressor
  772. +++++++++++++++++++++++++++++
  773. The ``deflatehd`` program reads JSON data or HTTP/1-style header fields from
  774. stdin and outputs compressed header block in JSON.
  775. For the JSON input, the root JSON object must include a ``cases`` key.
  776. Its value has to include the sequence of input header set. They share
  777. the same compression context and are processed in the order they
  778. appear. Each item in the sequence is a JSON object and it must
  779. include a ``headers`` key. Its value is an array of JSON objects,
  780. which includes exactly one name/value pair.
  781. Example:
  782. .. code-block:: json
  783. {
  784. "cases":
  785. [
  786. {
  787. "headers": [
  788. { ":method": "GET" },
  789. { ":path": "/" }
  790. ]
  791. },
  792. {
  793. "headers": [
  794. { ":method": "POST" },
  795. { ":path": "/" }
  796. ]
  797. }
  798. ]
  799. }
  800. With the ``-t`` option, the program can accept more familiar HTTP/1 style
  801. header field blocks. Each header set is delimited by an empty line:
  802. Example:
  803. .. code-block:: text
  804. :method: GET
  805. :scheme: https
  806. :path: /
  807. :method: POST
  808. user-agent: nghttp2
  809. The output is in JSON object. It should include a ``cases`` key and its
  810. value is an array of JSON objects, which has at least the following keys:
  811. seq
  812. The index of header set in the input.
  813. input_length
  814. The sum of the length of the name/value pairs in the input.
  815. output_length
  816. The length of the compressed header block.
  817. percentage_of_original_size
  818. ``output_length`` / ``input_length`` * 100
  819. wire
  820. The compressed header block as a hex string.
  821. headers
  822. The input header set.
  823. header_table_size
  824. The header table size adjusted before deflating the header set.
  825. Examples:
  826. .. code-block:: json
  827. {
  828. "cases":
  829. [
  830. {
  831. "seq": 0,
  832. "input_length": 66,
  833. "output_length": 20,
  834. "percentage_of_original_size": 30.303030303030305,
  835. "wire": "01881f3468e5891afcbf83868a3d856659c62e3f",
  836. "headers": [
  837. {
  838. ":authority": "example.org"
  839. },
  840. {
  841. ":method": "GET"
  842. },
  843. {
  844. ":path": "/"
  845. },
  846. {
  847. ":scheme": "https"
  848. },
  849. {
  850. "user-agent": "nghttp2"
  851. }
  852. ],
  853. "header_table_size": 4096
  854. }
  855. ,
  856. {
  857. "seq": 1,
  858. "input_length": 74,
  859. "output_length": 10,
  860. "percentage_of_original_size": 13.513513513513514,
  861. "wire": "88448504252dd5918485",
  862. "headers": [
  863. {
  864. ":authority": "example.org"
  865. },
  866. {
  867. ":method": "POST"
  868. },
  869. {
  870. ":path": "/account"
  871. },
  872. {
  873. ":scheme": "https"
  874. },
  875. {
  876. "user-agent": "nghttp2"
  877. }
  878. ],
  879. "header_table_size": 4096
  880. }
  881. ]
  882. }
  883. The output can be used as the input for ``inflatehd`` and
  884. ``deflatehd``.
  885. With the ``-d`` option, the extra ``header_table`` key is added and its
  886. associated value includes the state of dynamic header table after the
  887. corresponding header set was processed. The value includes at least
  888. the following keys:
  889. entries
  890. The entry in the header table. If ``referenced`` is ``true``, it
  891. is in the reference set. The ``size`` includes the overhead (32
  892. bytes). The ``index`` corresponds to the index of header table.
  893. The ``name`` is the header field name and the ``value`` is the
  894. header field value.
  895. size
  896. The sum of the spaces entries occupied, this includes the
  897. entry overhead.
  898. max_size
  899. The maximum header table size.
  900. deflate_size
  901. The sum of the spaces entries occupied within
  902. ``max_deflate_size``.
  903. max_deflate_size
  904. The maximum header table size the encoder uses. This can be smaller
  905. than ``max_size``. In this case, the encoder only uses up to first
  906. ``max_deflate_size`` buffer. Since the header table size is still
  907. ``max_size``, the encoder has to keep track of entries outside the
  908. ``max_deflate_size`` but inside the ``max_size`` and make sure
  909. that they are no longer referenced.
  910. Example:
  911. .. code-block:: json
  912. {
  913. "cases":
  914. [
  915. {
  916. "seq": 0,
  917. "input_length": 66,
  918. "output_length": 20,
  919. "percentage_of_original_size": 30.303030303030305,
  920. "wire": "01881f3468e5891afcbf83868a3d856659c62e3f",
  921. "headers": [
  922. {
  923. ":authority": "example.org"
  924. },
  925. {
  926. ":method": "GET"
  927. },
  928. {
  929. ":path": "/"
  930. },
  931. {
  932. ":scheme": "https"
  933. },
  934. {
  935. "user-agent": "nghttp2"
  936. }
  937. ],
  938. "header_table_size": 4096,
  939. "header_table": {
  940. "entries": [
  941. {
  942. "index": 1,
  943. "name": "user-agent",
  944. "value": "nghttp2",
  945. "referenced": true,
  946. "size": 49
  947. },
  948. {
  949. "index": 2,
  950. "name": ":scheme",
  951. "value": "https",
  952. "referenced": true,
  953. "size": 44
  954. },
  955. {
  956. "index": 3,
  957. "name": ":path",
  958. "value": "/",
  959. "referenced": true,
  960. "size": 38
  961. },
  962. {
  963. "index": 4,
  964. "name": ":method",
  965. "value": "GET",
  966. "referenced": true,
  967. "size": 42
  968. },
  969. {
  970. "index": 5,
  971. "name": ":authority",
  972. "value": "example.org",
  973. "referenced": true,
  974. "size": 53
  975. }
  976. ],
  977. "size": 226,
  978. "max_size": 4096,
  979. "deflate_size": 226,
  980. "max_deflate_size": 4096
  981. }
  982. }
  983. ,
  984. {
  985. "seq": 1,
  986. "input_length": 74,
  987. "output_length": 10,
  988. "percentage_of_original_size": 13.513513513513514,
  989. "wire": "88448504252dd5918485",
  990. "headers": [
  991. {
  992. ":authority": "example.org"
  993. },
  994. {
  995. ":method": "POST"
  996. },
  997. {
  998. ":path": "/account"
  999. },
  1000. {
  1001. ":scheme": "https"
  1002. },
  1003. {
  1004. "user-agent": "nghttp2"
  1005. }
  1006. ],
  1007. "header_table_size": 4096,
  1008. "header_table": {
  1009. "entries": [
  1010. {
  1011. "index": 1,
  1012. "name": ":method",
  1013. "value": "POST",
  1014. "referenced": true,
  1015. "size": 43
  1016. },
  1017. {
  1018. "index": 2,
  1019. "name": "user-agent",
  1020. "value": "nghttp2",
  1021. "referenced": true,
  1022. "size": 49
  1023. },
  1024. {
  1025. "index": 3,
  1026. "name": ":scheme",
  1027. "value": "https",
  1028. "referenced": true,
  1029. "size": 44
  1030. },
  1031. {
  1032. "index": 4,
  1033. "name": ":path",
  1034. "value": "/",
  1035. "referenced": false,
  1036. "size": 38
  1037. },
  1038. {
  1039. "index": 5,
  1040. "name": ":method",
  1041. "value": "GET",
  1042. "referenced": false,
  1043. "size": 42
  1044. },
  1045. {
  1046. "index": 6,
  1047. "name": ":authority",
  1048. "value": "example.org",
  1049. "referenced": true,
  1050. "size": 53
  1051. }
  1052. ],
  1053. "size": 269,
  1054. "max_size": 4096,
  1055. "deflate_size": 269,
  1056. "max_deflate_size": 4096
  1057. }
  1058. }
  1059. ]
  1060. }
  1061. inflatehd - header decompressor
  1062. +++++++++++++++++++++++++++++++
  1063. The ``inflatehd`` program reads JSON data from stdin and outputs decompressed
  1064. name/value pairs in JSON.
  1065. The root JSON object must include the ``cases`` key. Its value has to
  1066. include the sequence of compressed header blocks. They share the same
  1067. compression context and are processed in the order they appear. Each
  1068. item in the sequence is a JSON object and it must have at least a
  1069. ``wire`` key. Its value is a compressed header block as a hex string.
  1070. Example:
  1071. .. code-block:: json
  1072. {
  1073. "cases":
  1074. [
  1075. { "wire": "8285" },
  1076. { "wire": "8583" }
  1077. ]
  1078. }
  1079. The output is a JSON object. It should include a ``cases`` key and its
  1080. value is an array of JSON objects, which has at least following keys:
  1081. seq
  1082. The index of the header set in the input.
  1083. headers
  1084. A JSON array that includes decompressed name/value pairs.
  1085. wire
  1086. The compressed header block as a hex string.
  1087. header_table_size
  1088. The header table size adjusted before inflating compressed header
  1089. block.
  1090. Example:
  1091. .. code-block:: json
  1092. {
  1093. "cases":
  1094. [
  1095. {
  1096. "seq": 0,
  1097. "wire": "01881f3468e5891afcbf83868a3d856659c62e3f",
  1098. "headers": [
  1099. {
  1100. ":authority": "example.org"
  1101. },
  1102. {
  1103. ":method": "GET"
  1104. },
  1105. {
  1106. ":path": "/"
  1107. },
  1108. {
  1109. ":scheme": "https"
  1110. },
  1111. {
  1112. "user-agent": "nghttp2"
  1113. }
  1114. ],
  1115. "header_table_size": 4096
  1116. }
  1117. ,
  1118. {
  1119. "seq": 1,
  1120. "wire": "88448504252dd5918485",
  1121. "headers": [
  1122. {
  1123. ":method": "POST"
  1124. },
  1125. {
  1126. ":path": "/account"
  1127. },
  1128. {
  1129. "user-agent": "nghttp2"
  1130. },
  1131. {
  1132. ":scheme": "https"
  1133. },
  1134. {
  1135. ":authority": "example.org"
  1136. }
  1137. ],
  1138. "header_table_size": 4096
  1139. }
  1140. ]
  1141. }
  1142. The output can be used as the input for ``deflatehd`` and
  1143. ``inflatehd``.
  1144. With the ``-d`` option, the extra ``header_table`` key is added and its
  1145. associated value includes the state of the dynamic header table after the
  1146. corresponding header set was processed. The format is the same as
  1147. ``deflatehd``.
  1148. Contribution
  1149. ------------
  1150. [This text was composed based on 1.2. License section of curl/libcurl
  1151. project.]
  1152. When contributing with code, you agree to put your changes and new
  1153. code under the same license nghttp2 is already using unless stated and
  1154. agreed otherwise.
  1155. When changing existing source code, do not alter the copyright of
  1156. the original file(s). The copyright will still be owned by the
  1157. original creator(s) or those who have been assigned copyright by the
  1158. original author(s).
  1159. By submitting a patch to the nghttp2 project, you (or your employer, as
  1160. the case may be) agree to assign the copyright of your submission to us.
  1161. .. the above really needs to be reworded to pass legal muster.
  1162. We will credit you for your
  1163. changes as far as possible, to give credit but also to keep a trace
  1164. back to who made what changes. Please always provide us with your
  1165. full real name when contributing!
  1166. See `Contribution Guidelines
  1167. <https://nghttp2.org/documentation/contribute.html>`_ for more
  1168. details.
  1169. Reporting vulnerability
  1170. -----------------------
  1171. If you find a vulnerability in our software, please send the email to
  1172. "tatsuhiro.t at gmail dot com" about its details instead of submitting
  1173. issues on github issue page. It is a standard practice not to
  1174. disclose vulnerability information publicly until a fixed version is
  1175. released, or mitigation is worked out.
  1176. In the future, we may setup a dedicated mail address for this purpose.
  1177. Versioning
  1178. ----------
  1179. In general, we follow `Semantic Versioning <http://semver.org/>`_.
  1180. We may release PATCH releases between the regular releases, mainly for
  1181. severe security bug fixes.
  1182. We have no plan to break API compatibility changes involving soname
  1183. bump, so MAJOR version will stay 1 for the foreseeable future.
  1184. License
  1185. -------
  1186. The MIT License