README.rst 49 KB

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