Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

nghttp2 - HTTP/2 C Library and tools

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
COPYING
NotificationsYou must be signed in to change notification settings

nghttp2/nghttp2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is an implementation of the Hypertext Transfer Protocol version 2in C.

The framing layer of HTTP/2 is implemented as a reusable C library.On top of that, we have implemented an HTTP/2 client, server andproxy. We have also developed load test and benchmarking tools forHTTP/2.

An HPACK encoder and decoder are available as a public API.

Development Status

nghttp2 was originally developed based onRFC 7540 HTTP/2 andRFC 7541 HPACK - Header Compression forHTTP/2. Now we are updating our code to implementRFC 9113.

The nghttp2 code base was forked from the spdylay(https://github.com/tatsuhiro-t/spdylay) project.

Public Test Server

The following endpoints are available to try out our nghttp2implementation.

  • https://nghttp2.org/ (TLS + ALPN and HTTP/3)

    This endpoint supportsh2 andhttp/1.1 via ALPN and requiresTLSv1.2 for HTTP/2 connection.

    It also supports HTTP/3.

  • http://nghttp2.org/ (HTTP Upgrade and HTTP/2 Direct)

    h2c andhttp/1.1.

Requirements

The following package is required to build the libnghttp2 library:

  • pkg-config >= 0.20

To build the documentation, you need to install:

If you need libnghttp2 (C library) only, then the above packages areall you need. Use--enable-lib-only to ensure that onlylibnghttp2 is built. This avoids potential build error related tobuilding bundled applications.

To build and run the application programs (nghttp,nghttpd,nghttpx andh2load) in thesrc directory, the following packagesare required:

  • OpenSSL >= 1.1.1; or wolfSSL >= 5.7.0; or LibreSSL >= 3.8.1; oraws-lc >= 1.19.0; or BoringSSL
  • libev >= 4.11
  • zlib >= 1.2.3
  • libc-ares >= 1.7.5

To enable-a option (getting linked assets from the downloadedresource) innghttp, the following package is required:

  • libxml2 >= 2.6.26

To enable systemd support in nghttpx, the following package isrequired:

  • libsystemd-dev >= 209

The HPACK tools require the following package:

  • jansson >= 2.5

To build sources under the examples directory, libevent is required:

  • libevent-openssl >= 2.0.8

To mitigate heap fragmentation in long running server programs(nghttpd andnghttpx), jemalloc is recommended:

  • jemalloc

    Note

    Alpine Linux currently does not support malloc replacementdue to musl limitations. See details in issue#762.

For BoringSSL or aws-lc build, to enableRFC 8879 TLS CertificateCompression in applications, the following library is required:

  • libbrotli-dev >= 1.0.9

To enable mruby support for nghttpx,mruby is required. We need to buildmruby with C++ ABI explicitly turned on, and probably need othermrgems, mruby is managed by git submodule under third-party/mrubydirectory. Currently, mruby support for nghttpx is disabled bydefault. To enable mruby support, use--with-mruby configureoption. Note that at the time of this writing, libmruby-dev and mrubypackages in Debian/Ubuntu are not usable for nghttp2, since they donot enable C++ ABI. To build mruby, the following packages arerequired:

  • ruby
  • bison

nghttpx supportsneverbleed,privilege separation engine for OpenSSL. In short, it minimizes therisk of private key leakage when serious bug like Heartbleed isexploited. The neverbleed is disabled by default. To enable it, use--with-neverbleed configure option.

To enable the experimental HTTP/3 support for h2load and nghttpx, thefollowing libraries are required:

  • quictls; orwolfSSL; or LibreSSL (does not support 0RTT); or aws-lc; orBoringSSL (commit9b86817b23dfbf6e0837df8862a4112c51b4ea3b); or OpenSSL >= 3.5.0
  • ngtcp2 >= 1.16.0
  • nghttp3 >= 1.12.0

Use--enable-http3 configure option to enable HTTP/3 feature forh2load and nghttpx.

In order to build optional eBPF program to direct an incoming QUIC UDPdatagram to a correct socket for nghttpx, the following libraries arerequired:

  • libbpf-dev >= 0.7.0

Use--with-libbpf configure option to build eBPF program.libelf-dev is needed to build libbpf.

For Ubuntu 20.04, you can build libbpf fromthe source code. nghttpx requires eBPFprogram for reloading its configuration and hot swapping itsexecutable.

Compiling libnghttp2 C source code requires a C99 compiler. gcc 4.8is known to be adequate. In order to compile the C++ source code,C++20 compliant compiler is required. At least g++ >= 12 andclang++ >= 18 are known to work.

Note

To enable mruby support in nghttpx, and use--with-mrubyconfigure option.

Note

Mac OS X users may need the--disable-threads configure option todisable multi-threading in nghttpd, nghttpx and h2load to preventthem from crashing. A patch is welcome to make multi threading workon Mac OS X platform.

Note

To compile the associated applications (nghttp, nghttpd, nghttpxand h2load), you must use the--enable-app configure option andensure that the specified requirements above are met. Normally,configure script checks required dependencies to build theseapplications, and enable--enable-app automatically, so youdon't have to use it explicitly. But if you found thatapplications were not built, then using--enable-app may findthat cause, such as the missing dependency.

Note

In order to detect third party libraries, pkg-config is used(however we don't use pkg-config for some libraries (e.g., libev)).By default, pkg-config searches*.pc file in the standardlocations (e.g., /usr/lib/pkgconfig). If it is necessary to use*.pc file in the custom location, specify paths toPKG_CONFIG_PATH environment variable, and pass it to configurescript, like so:

$ ./configure PKG_CONFIG_PATH=/path/to/pkgconfig

For pkg-config managed libraries,*_CFLAG and*_LIBSenvironment variables are defined (e.g.,OPENSSL_CFLAGS,OPENSSL_LIBS). Specifying non-empty string to these variablescompletely overrides pkg-config. In other words, if they arespecified, pkg-config is not used for detection, and user isresponsible to specify the correct values to these variables. Forcomplete list of these variables, run./configure -h.

If you are using Ubuntu 22.04 LTS, run the following to install therequired packages:

sudo apt-get install g++ clang make binutils autoconf automake \  autotools-dev libtool pkg-config \  zlib1g-dev libssl-dev libxml2-dev libev-dev \  libevent-dev libjansson-dev \  libc-ares-dev libjemalloc-dev libsystemd-dev \  ruby-dev bison libelf-dev

Building nghttp2 from release tar archive

The nghttp2 project regularly releases tar archives which includesnghttp2 source code, and generated build files. They can bedownloaded fromReleases page.

Building nghttp2 from git requires autotools development packages.Building from tar archives does not require them, and thus it is mucheasier. The usual build step is as follows:

$ tar xf nghttp2-X.Y.Z.tar.bz2$ cd nghttp2-X.Y.Z$ ./configure$ make

Building from git

Building from git is easy, but please be sure that at least autoconf 2.68 isused:

$ git submodule update --init$ autoreconf -i$ automake$ autoconf$ ./configure$ make

Notes for building on Windows (MSVC)

The easiest way to build native Windows nghttp2 dll is usecmake. The free version ofVisual C++ Build Tools worksfine.

  1. Install cmake for windows
  2. Open "Visual C++ ... Native Build Tool Command Prompt", and insidenghttp2 directly, runcmake.
  3. Then runcmake --build to build library.
  4. nghttp2.dll, nghttp2.lib, nghttp2.exp are placed under lib directory.

Note that the above steps most likely produce nghttp2 library only.No bundled applications are compiled.

Notes for building on Windows (Mingw/Cygwin)

Under Mingw environment, you can only compile the library, it'slibnghttp2-X.dll andlibnghttp2.a.

If you want to compile the applications(h2load,nghttp,nghttpx,nghttpd), you need to use the Cygwin environment.

Under Cygwin environment, to compile the applications you need tocompile and install the libev first.

Secondly, you need to undefine the macro__STRICT_ANSI__, if younot, the functionsfdopen,fileno andstrptime will notavailable.

the sample command like this:

$ export CFLAGS="-U__STRICT_ANSI__ -I$libev_PREFIX/include -L$libev_PREFIX/lib"$ export CXXFLAGS=$CFLAGS$ ./configure$ make

If you want to compile the applications underexamples/, you needto remove or rename theevent.h from libev's installation, becauseit conflicts with libevent's installation.

Notes for installation on Linux systems

After installing nghttp2 tool suite withmake install one might experience a similar error:

nghttpx: error while loading shared libraries: libnghttp2.so.14: cannot open shared object file: No such file or directory

This means that the tool is unable to locate thelibnghttp2.so shared library.

To update the shared library cache runsudo ldconfig.

Building the documentation

Note

Documentation is still incomplete.

To build the documentation, run:

$ make html

The documents will be generated underdoc/manual/html/.

The generated documents will not be installed withmake install.

The online documentation is available athttps://nghttp2.org/documentation/

Build HTTP/3 enabled h2load and nghttpx

To build h2load and nghttpx with HTTP/3 feature enabled, run theconfigure script with--enable-http3.

For nghttpx to reload configurations and swapping its executable whilegracefully terminating old worker processes, eBPF is required. Runthe configure script with--enable-http3 --with-libbpf to buildeBPF program. The QUIC keying material must be set with--frontend-quic-secret-file in order to keep the existingconnections alive during reload.

The detailed steps to build HTTP/3 enabled h2load and nghttpx follow.

Build aws-lc:

$ git clone --depth 1 -b v1.64.0 https://github.com/aws/aws-lc$ cd aws-lc$ cmake -B build -DDISABLE_GO=ON --install-prefix=$PWD/opt$ make -j$(nproc) -C build$ cmake --install build$ cd ..

Build nghttp3:

$ git clone --depth 1 -b v1.13.1 https://github.com/ngtcp2/nghttp3$ cd nghttp3$ git submodule update --init --depth 1$ autoreconf -i$ ./configure --prefix=$PWD/build --enable-lib-only$ make -j$(nproc)$ make install$ cd ..

Build ngtcp2:

$ git clone --depth 1 -b v1.18.0 https://github.com/ngtcp2/ngtcp2$ cd ngtcp2$ git submodule update --init --depth 1$ autoreconf -i$ ./configure --prefix=$PWD/build --enable-lib-only --with-boringssl \      BORINGSSL_CFLAGS="-I$PWD/../aws-lc/opt/include" \      BORINGSSL_LIBS="-L$PWD/../aws-lc/opt/lib -lssl -lcrypto"$ make -j$(nproc)$ make install$ cd ..

If your Linux distribution does not have libbpf-dev >= 0.7.0, buildfrom source:

$ git clone --depth 1 -b v1.6.2 https://github.com/libbpf/libbpf$ cd libbpf$ PREFIX=$PWD/build make -C src install$ cd ..

Build nghttp2:

$ git clone https://github.com/nghttp2/nghttp2$ cd nghttp2$ git submodule update --init$ autoreconf -i$ ./configure --with-mruby --enable-http3 --with-libbpf \      CC=clang-19 CXX=clang++-19 \      PKG_CONFIG_PATH="$PWD/../aws-lc/opt/lib/pkgconfig:$PWD/../nghttp3/build/lib/pkgconfig:$PWD/../ngtcp2/build/lib/pkgconfig:$PWD/../libbpf/build/lib64/pkgconfig" \      LDFLAGS="$LDFLAGS -Wl,-rpath,$PWD/../aws-lc/opt/lib -Wl,-rpath,$PWD/../libbpf/build/lib64"$ make -j$(nproc)

The eBPF programreuseport_kern.o should be found under bpfdirectory. Pass--quic-bpf-program-file=bpf/reuseport_kern.ooption to nghttpx to load it. See alsoHTTP/3 section in nghttpx -HTTP/2 proxy - HOW-TO.

Unit tests

Unit tests are done by simply runningmake check.

Integration tests

We have the integration tests for the nghttpx proxy server. The tests arewritten in theGo programming language and usesits testing framework. We depend on the following libraries:

Go modules will download these dependencies automatically.

To run the tests, run the following command underintegration-tests directory:

$ make it

Inside the tests, we use port 3009 to run the test subject server.

Migration from v0.7.15 or earlier

nghttp2 v1.0.0 introduced several backward incompatible changes. Inthis section, we describe these changes and how to migrate to v1.0.0.

ALPN protocol ID is nowh2 andh2c

Previously we announcedh2-14 andh2c-14. v1.0.0 implementsfinal protocol version, and we changed ALPN ID toh2 andh2c.The macrosNGHTTP2_PROTO_VERSION_ID,NGHTTP2_PROTO_VERSION_ID_LEN,NGHTTP2_CLEARTEXT_PROTO_VERSION_ID, andNGHTTP2_CLEARTEXT_PROTO_VERSION_ID_LEN have been updated toreflect this change.

Basically, existing applications do not have to do anything, justrecompiling is enough for this change.

Use word "client magic" where we use "client connection preface"

We use "client connection preface" to mean first 24 bytes of clientconnection preface. This is technically not correct, since clientconnection preface is composed of 24 bytes client magic byte stringfollowed by SETTINGS frame. For clarification, we call "client magic"for this 24 bytes byte string and updated API.

  • NGHTTP2_CLIENT_CONNECTION_PREFACE was replaced withNGHTTP2_CLIENT_MAGIC.
  • NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN was replaced withNGHTTP2_CLIENT_MAGIC_LEN.
  • NGHTTP2_BAD_PREFACE was renamed asNGHTTP2_BAD_CLIENT_MAGIC

The already deprecatedNGHTTP2_CLIENT_CONNECTION_HEADER andNGHTTP2_CLIENT_CONNECTION_HEADER_LEN were removed.

If application uses these macros, just replace old ones with new ones.Since v1.0.0, client magic is sent by library (see next subsection),so client application may just remove these macro use.

Client magic is sent by library

Previously nghttp2 library did not send client magic, which is first24 bytes byte string of client connection preface, and clientapplications have to send it by themselves. Since v1.0.0, clientmagic is sent by library via first call ofnghttp2_session_send()ornghttp2_session_mem_send2().

The client applications which send client magic must remove therelevant code.

Remove HTTP Alternative Services (Alt-Svc) related code

Alt-Svc specification is not finalized yet. To make our API stable,we have decided to remove all Alt-Svc related API from nghttp2.

  • NGHTTP2_EXT_ALTSVC was removed.
  • nghttp2_ext_altsvc was removed.

We have already removed the functionality of Alt-Svc in v0.7 seriesand they have been essentially noop. The application using thesemacro and struct, remove those lines.

Use nghttp2_error in nghttp2_on_invalid_frame_recv_callback

Previouslynghttp2_on_invalid_frame_recv_cb_called took theerror_code, defined innghttp2_error_code, as parameter. Butthey are not detailed enough to debug. Therefore, we decided to usemore detailednghttp2_error values instead.

The application using this callback should update the callbacksignature. If it treatserror_code as HTTP/2 error code, updatethe code so that it is treated asnghttp2_error.

Receive client magic by default

Previously nghttp2 did not process client magic (24 bytes bytestring). To make it deal with it, we had to usenghttp2_option_set_recv_client_preface(). Since v1.0.0, nghttp2processes client magic by default andnghttp2_option_set_recv_client_preface() was removed.

Some application may want to disable this behaviour, so we addednghttp2_option_set_no_recv_client_magic() to achieve this.

The application usingnghttp2_option_set_recv_client_preface()with nonzero value, just remove it.

The application usingnghttp2_option_set_recv_client_preface()with zero value or not using it must usenghttp2_option_set_no_recv_client_magic() with nonzero value.

Client, Server and Proxy programs

Thesrc directory contains the HTTP/2 client, server and proxy programs.

nghttp - client

nghttp is a HTTP/2 client. It can connect to the HTTP/2 serverwith prior knowledge, HTTP Upgrade and ALPN TLS extension.

It has verbose output mode for framing information. Here is sampleoutput fromnghttp client:

$ nghttp -nv https://nghttp2.org[  0.190] ConnectedThe negotiated protocol: h2[  0.212] recv SETTINGS frame <length=12, flags=0x00, stream_id=0>          (niv=2)          [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]          [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535][  0.212] send SETTINGS frame <length=12, flags=0x00, stream_id=0>          (niv=2)          [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]          [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535][  0.212] send SETTINGS frame <length=0, flags=0x01, stream_id=0>          ; ACK          (niv=0)[  0.212] send PRIORITY frame <length=5, flags=0x00, stream_id=3>          (dep_stream_id=0, weight=201, exclusive=0)[  0.212] send PRIORITY frame <length=5, flags=0x00, stream_id=5>          (dep_stream_id=0, weight=101, exclusive=0)[  0.212] send PRIORITY frame <length=5, flags=0x00, stream_id=7>          (dep_stream_id=0, weight=1, exclusive=0)[  0.212] send PRIORITY frame <length=5, flags=0x00, stream_id=9>          (dep_stream_id=7, weight=1, exclusive=0)[  0.212] send PRIORITY frame <length=5, flags=0x00, stream_id=11>          (dep_stream_id=3, weight=1, exclusive=0)[  0.212] send HEADERS frame <length=39, flags=0x25, stream_id=13>          ; END_STREAM | END_HEADERS | PRIORITY          (padlen=0, dep_stream_id=11, weight=16, exclusive=0)          ; Open new stream          :method: GET          :path: /          :scheme: https          :authority: nghttp2.org          accept: */*          accept-encoding: gzip, deflate          user-agent: nghttp2/1.0.1-DEV[  0.221] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>          ; ACK          (niv=0)[  0.221] recv (stream_id=13) :method: GET[  0.221] recv (stream_id=13) :scheme: https[  0.221] recv (stream_id=13) :path: /stylesheets/screen.css[  0.221] recv (stream_id=13) :authority: nghttp2.org[  0.221] recv (stream_id=13) accept-encoding: gzip, deflate[  0.222] recv (stream_id=13) user-agent: nghttp2/1.0.1-DEV[  0.222] recv PUSH_PROMISE frame <length=50, flags=0x04, stream_id=13>          ; END_HEADERS          (padlen=0, promised_stream_id=2)[  0.222] recv (stream_id=13) :status: 200[  0.222] recv (stream_id=13) date: Thu, 21 May 2015 16:38:14 GMT[  0.222] recv (stream_id=13) content-type: text/html[  0.222] recv (stream_id=13) last-modified: Fri, 15 May 2015 15:38:06 GMT[  0.222] recv (stream_id=13) etag: W/"555612de-19f6"[  0.222] recv (stream_id=13) link: </stylesheets/screen.css>; rel=preload; as=stylesheet[  0.222] recv (stream_id=13) content-encoding: gzip[  0.222] recv (stream_id=13) server: nghttpx nghttp2/1.0.1-DEV[  0.222] recv (stream_id=13) via: 1.1 nghttpx[  0.222] recv (stream_id=13) strict-transport-security: max-age=31536000[  0.222] recv HEADERS frame <length=166, flags=0x04, stream_id=13>          ; END_HEADERS          (padlen=0)          ; First response header[  0.222] recv DATA frame <length=2601, flags=0x01, stream_id=13>          ; END_STREAM[  0.222] recv (stream_id=2) :status: 200[  0.222] recv (stream_id=2) date: Thu, 21 May 2015 16:38:14 GMT[  0.222] recv (stream_id=2) content-type: text/css[  0.222] recv (stream_id=2) last-modified: Fri, 15 May 2015 15:38:06 GMT[  0.222] recv (stream_id=2) etag: W/"555612de-9845"[  0.222] recv (stream_id=2) content-encoding: gzip[  0.222] recv (stream_id=2) server: nghttpx nghttp2/1.0.1-DEV[  0.222] recv (stream_id=2) via: 1.1 nghttpx[  0.222] recv (stream_id=2) strict-transport-security: max-age=31536000[  0.222] recv HEADERS frame <length=32, flags=0x04, stream_id=2>          ; END_HEADERS          (padlen=0)          ; First push response header[  0.228] recv DATA frame <length=8715, flags=0x01, stream_id=2>          ; END_STREAM[  0.228] send GOAWAY frame <length=8, flags=0x00, stream_id=0>          (last_stream_id=2, error_code=NO_ERROR(0x00), opaque_data(0)=[])

The HTTP Upgrade is performed like so:

$ nghttp -nvu http://nghttp2.org[  0.011] Connected[  0.011] HTTP Upgrade requestGET / HTTP/1.1Host: nghttp2.orgConnection: Upgrade, HTTP2-SettingsUpgrade: h2cHTTP2-Settings: AAMAAABkAAQAAP__Accept: */*User-Agent: nghttp2/1.0.1-DEV[  0.018] HTTP Upgrade responseHTTP/1.1 101 Switching ProtocolsConnection: UpgradeUpgrade: h2c[  0.018] HTTP Upgrade success[  0.018] recv SETTINGS frame <length=12, flags=0x00, stream_id=0>          (niv=2)          [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]          [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535][  0.018] send SETTINGS frame <length=12, flags=0x00, stream_id=0>          (niv=2)          [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]          [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535][  0.018] send SETTINGS frame <length=0, flags=0x01, stream_id=0>          ; ACK          (niv=0)[  0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=3>          (dep_stream_id=0, weight=201, exclusive=0)[  0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=5>          (dep_stream_id=0, weight=101, exclusive=0)[  0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=7>          (dep_stream_id=0, weight=1, exclusive=0)[  0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=9>          (dep_stream_id=7, weight=1, exclusive=0)[  0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=11>          (dep_stream_id=3, weight=1, exclusive=0)[  0.018] send PRIORITY frame <length=5, flags=0x00, stream_id=1>          (dep_stream_id=11, weight=16, exclusive=0)[  0.019] recv (stream_id=1) :method: GET[  0.019] recv (stream_id=1) :scheme: http[  0.019] recv (stream_id=1) :path: /stylesheets/screen.css[  0.019] recv (stream_id=1) host: nghttp2.org[  0.019] recv (stream_id=1) user-agent: nghttp2/1.0.1-DEV[  0.019] recv PUSH_PROMISE frame <length=49, flags=0x04, stream_id=1>          ; END_HEADERS          (padlen=0, promised_stream_id=2)[  0.019] recv (stream_id=1) :status: 200[  0.019] recv (stream_id=1) date: Thu, 21 May 2015 16:39:16 GMT[  0.019] recv (stream_id=1) content-type: text/html[  0.019] recv (stream_id=1) content-length: 6646[  0.019] recv (stream_id=1) last-modified: Fri, 15 May 2015 15:38:06 GMT[  0.019] recv (stream_id=1) etag: "555612de-19f6"[  0.019] recv (stream_id=1) link: </stylesheets/screen.css>; rel=preload; as=stylesheet[  0.019] recv (stream_id=1) accept-ranges: bytes[  0.019] recv (stream_id=1) server: nghttpx nghttp2/1.0.1-DEV[  0.019] recv (stream_id=1) via: 1.1 nghttpx[  0.019] recv HEADERS frame <length=157, flags=0x04, stream_id=1>          ; END_HEADERS          (padlen=0)          ; First response header[  0.019] recv DATA frame <length=6646, flags=0x01, stream_id=1>          ; END_STREAM[  0.019] recv (stream_id=2) :status: 200[  0.019] recv (stream_id=2) date: Thu, 21 May 2015 16:39:16 GMT[  0.019] recv (stream_id=2) content-type: text/css[  0.019] recv (stream_id=2) content-length: 38981[  0.019] recv (stream_id=2) last-modified: Fri, 15 May 2015 15:38:06 GMT[  0.019] recv (stream_id=2) etag: "555612de-9845"[  0.019] recv (stream_id=2) accept-ranges: bytes[  0.019] recv (stream_id=2) server: nghttpx nghttp2/1.0.1-DEV[  0.019] recv (stream_id=2) via: 1.1 nghttpx[  0.019] recv HEADERS frame <length=36, flags=0x04, stream_id=2>          ; END_HEADERS          (padlen=0)          ; First push response header[  0.026] recv DATA frame <length=16384, flags=0x00, stream_id=2>[  0.027] recv DATA frame <length=7952, flags=0x00, stream_id=2>[  0.027] send WINDOW_UPDATE frame <length=4, flags=0x00, stream_id=0>          (window_size_increment=33343)[  0.032] send WINDOW_UPDATE frame <length=4, flags=0x00, stream_id=2>          (window_size_increment=33707)[  0.032] recv DATA frame <length=14645, flags=0x01, stream_id=2>          ; END_STREAM[  0.032] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>          ; ACK          (niv=0)[  0.032] send GOAWAY frame <length=8, flags=0x00, stream_id=0>          (last_stream_id=2, error_code=NO_ERROR(0x00), opaque_data(0)=[])

Using the-s option,nghttp prints out some timing information forrequests, sorted by completion time:

$ nghttp -nas https://nghttp2.org/***** Statistics *****Request timing:  responseEnd: the  time  when  last  byte of  response  was  received               relative to connectEnd requestStart: the time  just before  first byte  of request  was sent               relative  to connectEnd.   If  '*' is  shown, this  was               pushed by server.      process: responseEnd - requestStart         code: HTTP status code         size: number  of  bytes  received as  response  body  without               inflation.          URI: request URIsee http://www.w3.org/TR/resource-timing/#processing-modelsorted by 'complete'id  responseEnd requestStart  process code size request path 13    +37.19ms       +280us  36.91ms  200   2K /  2    +72.65ms *   +36.38ms  36.26ms  200   8K /stylesheets/screen.css 17    +77.43ms     +38.67ms  38.75ms  200   3K /javascripts/octopress.js 15    +78.12ms     +38.66ms  39.46ms  200   3K /javascripts/modernizr-2.0.js

Using the-r option,nghttp writes more detailed timing data tothe given file in HAR format.

nghttpd - server

nghttpd is a multi-threaded static web server.

By default, it uses SSL/TLS connection. Use--no-tls option todisable it.

nghttpd only accepts HTTP/2 connections via ALPN or direct HTTP/2connections. No HTTP Upgrade is supported.

The-p option allows users to configure server push.

Just likenghttp, it has a verbose output mode for framinginformation. Here is sample output fromnghttpd:

$ nghttpd --no-tls -v 8080IPv4: listen 0.0.0.0:8080IPv6: listen :::8080[id=1] [  1.521] send SETTINGS frame <length=6, flags=0x00, stream_id=0>          (niv=1)          [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100][id=1] [  1.521] recv SETTINGS frame <length=12, flags=0x00, stream_id=0>          (niv=2)          [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]          [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535][id=1] [  1.521] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>          ; ACK          (niv=0)[id=1] [  1.521] recv PRIORITY frame <length=5, flags=0x00, stream_id=3>          (dep_stream_id=0, weight=201, exclusive=0)[id=1] [  1.521] recv PRIORITY frame <length=5, flags=0x00, stream_id=5>          (dep_stream_id=0, weight=101, exclusive=0)[id=1] [  1.521] recv PRIORITY frame <length=5, flags=0x00, stream_id=7>          (dep_stream_id=0, weight=1, exclusive=0)[id=1] [  1.521] recv PRIORITY frame <length=5, flags=0x00, stream_id=9>          (dep_stream_id=7, weight=1, exclusive=0)[id=1] [  1.521] recv PRIORITY frame <length=5, flags=0x00, stream_id=11>          (dep_stream_id=3, weight=1, exclusive=0)[id=1] [  1.521] recv (stream_id=13) :method: GET[id=1] [  1.521] recv (stream_id=13) :path: /[id=1] [  1.521] recv (stream_id=13) :scheme: http[id=1] [  1.521] recv (stream_id=13) :authority: localhost:8080[id=1] [  1.521] recv (stream_id=13) accept: */*[id=1] [  1.521] recv (stream_id=13) accept-encoding: gzip, deflate[id=1] [  1.521] recv (stream_id=13) user-agent: nghttp2/1.0.0-DEV[id=1] [  1.521] recv HEADERS frame <length=41, flags=0x25, stream_id=13>          ; END_STREAM | END_HEADERS | PRIORITY          (padlen=0, dep_stream_id=11, weight=16, exclusive=0)          ; Open new stream[id=1] [  1.521] send SETTINGS frame <length=0, flags=0x01, stream_id=0>          ; ACK          (niv=0)[id=1] [  1.521] send HEADERS frame <length=86, flags=0x04, stream_id=13>          ; END_HEADERS          (padlen=0)          ; First response header          :status: 200          server: nghttpd nghttp2/1.0.0-DEV          content-length: 10          cache-control: max-age=3600          date: Fri, 15 May 2015 14:49:04 GMT          last-modified: Tue, 30 Sep 2014 12:40:52 GMT[id=1] [  1.522] send DATA frame <length=10, flags=0x01, stream_id=13>          ; END_STREAM[id=1] [  1.522] stream_id=13 closed[id=1] [  1.522] recv GOAWAY frame <length=8, flags=0x00, stream_id=0>          (last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[])[id=1] [  1.522] closed

nghttpx - proxy

nghttpx is a multi-threaded reverse proxy for HTTP/3, HTTP/2, andHTTP/1.1, and powershttp://nghttp2.org and supports HTTP/2 serverpush.

We reworkednghttpx command-line interface, and as a result, thereare several incompatibles from 1.8.0 or earlier. This is necessary toextend its capability, and secure the further feature enhancements inthe future release. Please readMigration from nghttpx v1.8.0 orearlierto know how to migrate from earlier releases.

nghttpx implementsimportant performance-oriented features in TLS, such assession IDs, session tickets (with automatic key rotation), dynamicrecord sizing, ALPN, forward secrecy and HTTP/2.nghttpx alsooffers the functionality to share ticket keys among multiplenghttpx instances via memcached.

nghttpx has 2 operation modes:

Mode optionFrontendBackendNote
default modeHTTP/3, HTTP/2, HTTP/1.1HTTP/1.1, HTTP/2Reverse proxy
--http2-proxyHTTP/3, HTTP/2, HTTP/1.1HTTP/1.1, HTTP/2Forward proxy

The interesting mode at the moment is the default mode. It works likea reverse proxy and listens for HTTP/3, HTTP/2, and HTTP/1.1 and canbe deployed as a SSL/TLS terminator for existing web server.

In all modes, the frontend connections are encrypted by SSL/TLS bydefault. To disable encryption, use theno-tls keyword in--frontend option. If encryption is disabled, incoming HTTP/1.1connections can be upgraded to HTTP/2 through HTTP Upgrade. On theother hard, backend connections are not encrypted by default. Toencrypt backend connections, usetls keyword in--backendoption.

nghttpx supports a configuration file. See the--conf option andsample configuration filenghttpx.conf.sample.

In the default mode,nghttpx works as reverse proxy to the backendserver:

Client <-- (HTTP/3, HTTP/2, HTTP/1.1) --> nghttpx <-- (HTTP/1.1, HTTP/2) --> Web Server                                        [reverse proxy]

With the--http2-proxy option, it works as forward proxy, and itis so called secure HTTP/2 proxy:

Client <-- (HTTP/3, HTTP/2, HTTP/1.1) --> nghttpx <-- (HTTP/1.1) --> Proxy                                         [secure proxy]          (e.g., Squid, ATS)

TheClient in the above example needs to be configured to usenghttpx as secure proxy.

At the time of this writing, both Chrome and Firefox support secureHTTP/2 proxy. One way to configure Chrome to use a secure proxy is tocreate a proxy.pac script like this:

functionFindProxyForURL(url,host){return"HTTPS SERVERADDR:PORT";}

SERVERADDR andPORT is the hostname/address and port of themachine nghttpx is running on. Please note that Chrome requires a validcertificate for secure proxy.

Then run Chrome with the following arguments:

$ google-chrome --proxy-pac-url=file:///path/to/proxy.pac --use-npn

The backend HTTP/2 connections can be tunneled through an HTTP proxy.The proxy is specified using--backend-http-proxy-uri. Thefollowing figure illustrates how nghttpx talks to the outside HTTP/2proxy through an HTTP proxy:

Client <-- (HTTP/3, HTTP/2, HTTP/1.1) --> nghttpx <-- (HTTP/2) --        --===================---> HTTP/2 Proxy          (HTTP proxy tunnel)     (e.g., nghttpx -s)

Benchmarking tool

Theh2load program is a benchmarking tool for HTTP/3, HTTP/2, andHTTP/1.1. The UI ofh2load is heavily inspired byweighttp(https://github.com/lighttpd/weighttp). The typical usage is asfollows:

$ h2load -n100000 -c100 -m100 https://localhost:8443/starting benchmark...spawning thread #0: 100 concurrent clients, 100000 total requestsProtocol: TLSv1.2Cipher: ECDHE-RSA-AES128-GCM-SHA256Server Temp Key: ECDH P-256 256 bitsprogress: 10% doneprogress: 20% doneprogress: 30% doneprogress: 40% doneprogress: 50% doneprogress: 60% doneprogress: 70% doneprogress: 80% doneprogress: 90% doneprogress: 100% donefinished in 771.26ms, 129658 req/s, 4.71MB/srequests: 100000 total, 100000 started, 100000 done, 100000 succeeded, 0 failed, 0 erroredstatus codes: 100000 2xx, 0 3xx, 0 4xx, 0 5xxtraffic: 3812300 bytes total, 1009900 bytes headers, 1000000 bytes data                     min         max         mean         sd        +/- sdtime for request:    25.12ms    124.55ms     51.07ms     15.36ms    84.87%time for connect:   208.94ms    254.67ms    241.38ms      7.95ms    63.00%time to 1st byte:   209.11ms    254.80ms    241.51ms      7.94ms    63.00%

The above example issued total 100,000 requests, using 100 concurrentclients (in other words, 100 HTTP/2 sessions), and a maximum of 100 streamsper client. With the-t option,h2load will use multiple nativethreads to avoid saturating a single core on client side.

Warning

Don't use this tool against publicly available servers. That isconsidered a DOS attack. Please only use it against your privateservers.

If the experimental HTTP/3 is enabled, h2load can send requests toHTTP/3 server. To do this, specifyh3 to--alpn-list optionlike so:

$ h2load --alpn-list h3 https://127.0.0.1:4433

For nghttp2 v1.58 or earlier, use--npn-list instead of--alpn-list.

HPACK tools

Thesrc directory contains the HPACK tools. Thedeflatehd program is acommand-line header compression tool. Theinflatehd program is acommand-line header decompression tool. Both tools read input fromstdin and write output to stdout. Errors are written to stderr.They take JSON as input and output. We (mostly) use the same JSON dataformat described athttps://github.com/http2jp/hpack-test-case.

deflatehd - header compressor

Thedeflatehd program reads JSON data or HTTP/1-style header fields fromstdin and outputs compressed header block in JSON.

For the JSON input, the root JSON object must include acases key.Its value has to include the sequence of input header set. They sharethe same compression context and are processed in the order theyappear. Each item in the sequence is a JSON object and it mustinclude aheaders key. Its value is an array of JSON objects,which includes exactly one name/value pair.

Example:

{"cases":  [    {"headers": [        {":method":"GET" },        {":path":"/" }      ]    },    {"headers": [        {":method":"POST" },        {":path":"/" }      ]    }  ]}

With the-t option, the program can accept more familiar HTTP/1 styleheader field blocks. Each header set is delimited by an empty line:

Example:

:method: GET:scheme: https:path: /:method: POSTuser-agent: nghttp2

The output is in JSON object. It should include acases key and itsvalue is an array of JSON objects, which has at least the following keys:

seq
The index of header set in the input.
input_length
The sum of the length of the name/value pairs in the input.
output_length
The length of the compressed header block.
percentage_of_original_size
output_length /input_length * 100
wire
The compressed header block as a hex string.
headers
The input header set.
header_table_size
The header table size adjusted before deflating the header set.

Examples:

{"cases":  [    {"seq":0,"input_length":66,"output_length":20,"percentage_of_original_size":30.303030303030305,"wire":"01881f3468e5891afcbf83868a3d856659c62e3f","headers": [        {":authority":"example.org"        },        {":method":"GET"        },        {":path":"/"        },        {":scheme":"https"        },        {"user-agent":"nghttp2"        }      ],"header_table_size":4096    }    ,    {"seq":1,"input_length":74,"output_length":10,"percentage_of_original_size":13.513513513513514,"wire":"88448504252dd5918485","headers": [        {":authority":"example.org"        },        {":method":"POST"        },        {":path":"/account"        },        {":scheme":"https"        },        {"user-agent":"nghttp2"        }      ],"header_table_size":4096    }  ]}

The output can be used as the input forinflatehd anddeflatehd.

With the-d option, the extraheader_table key is added and itsassociated value includes the state of dynamic header table after thecorresponding header set was processed. The value includes at leastthe following keys:

entries
The entry in the header table. Ifreferenced istrue, itis in the reference set. Thesize includes the overhead (32bytes). Theindex corresponds to the index of header table.Thename is the header field name and thevalue is theheader field value.
size
The sum of the spaces entries occupied, this includes theentry overhead.
max_size
The maximum header table size.
deflate_size
The sum of the spaces entries occupied withinmax_deflate_size.
max_deflate_size
The maximum header table size the encoder uses. This can be smallerthanmax_size. In this case, the encoder only uses up to firstmax_deflate_size buffer. Since the header table size is stillmax_size, the encoder has to keep track of entries outside themax_deflate_size but inside themax_size and make surethat they are no longer referenced.

Example:

{"cases":  [    {"seq":0,"input_length":66,"output_length":20,"percentage_of_original_size":30.303030303030305,"wire":"01881f3468e5891afcbf83868a3d856659c62e3f","headers": [        {":authority":"example.org"        },        {":method":"GET"        },        {":path":"/"        },        {":scheme":"https"        },        {"user-agent":"nghttp2"        }      ],"header_table_size":4096,"header_table": {"entries": [          {"index":1,"name":"user-agent","value":"nghttp2","referenced":true,"size":49          },          {"index":2,"name":":scheme","value":"https","referenced":true,"size":44          },          {"index":3,"name":":path","value":"/","referenced":true,"size":38          },          {"index":4,"name":":method","value":"GET","referenced":true,"size":42          },          {"index":5,"name":":authority","value":"example.org","referenced":true,"size":53          }        ],"size":226,"max_size":4096,"deflate_size":226,"max_deflate_size":4096      }    }    ,    {"seq":1,"input_length":74,"output_length":10,"percentage_of_original_size":13.513513513513514,"wire":"88448504252dd5918485","headers": [        {":authority":"example.org"        },        {":method":"POST"        },        {":path":"/account"        },        {":scheme":"https"        },        {"user-agent":"nghttp2"        }      ],"header_table_size":4096,"header_table": {"entries": [          {"index":1,"name":":method","value":"POST","referenced":true,"size":43          },          {"index":2,"name":"user-agent","value":"nghttp2","referenced":true,"size":49          },          {"index":3,"name":":scheme","value":"https","referenced":true,"size":44          },          {"index":4,"name":":path","value":"/","referenced":false,"size":38          },          {"index":5,"name":":method","value":"GET","referenced":false,"size":42          },          {"index":6,"name":":authority","value":"example.org","referenced":true,"size":53          }        ],"size":269,"max_size":4096,"deflate_size":269,"max_deflate_size":4096      }    }  ]}

inflatehd - header decompressor

Theinflatehd program reads JSON data from stdin and outputs decompressedname/value pairs in JSON.

The root JSON object must include thecases key. Its value has toinclude the sequence of compressed header blocks. They share the samecompression context and are processed in the order they appear. Eachitem in the sequence is a JSON object and it must have at least awire key. Its value is a compressed header block as a hex string.

Example:

{"cases":  [    {"wire":"8285" },    {"wire":"8583" }  ]}

The output is a JSON object. It should include acases key and itsvalue is an array of JSON objects, which has at least following keys:

seq
The index of the header set in the input.
headers
A JSON array that includes decompressed name/value pairs.
wire
The compressed header block as a hex string.
header_table_size
The header table size adjusted before inflating compressed headerblock.

Example:

{"cases":  [    {"seq":0,"wire":"01881f3468e5891afcbf83868a3d856659c62e3f","headers": [        {":authority":"example.org"        },        {":method":"GET"        },        {":path":"/"        },        {":scheme":"https"        },        {"user-agent":"nghttp2"        }      ],"header_table_size":4096    }    ,    {"seq":1,"wire":"88448504252dd5918485","headers": [        {":method":"POST"        },        {":path":"/account"        },        {"user-agent":"nghttp2"        },        {":scheme":"https"        },        {":authority":"example.org"        }      ],"header_table_size":4096    }  ]}

The output can be used as the input fordeflatehd andinflatehd.

With the-d option, the extraheader_table key is added and itsassociated value includes the state of the dynamic header table after thecorresponding header set was processed. The format is the same asdeflatehd.

Contribution

[This text was composed based on 1.2. License section of curl/libcurlproject.]

When contributing with code, you agree to put your changes and newcode under the same license nghttp2 is already using unless stated andagreed otherwise.

When changing existing source code, do not alter the copyright ofthe original file(s). The copyright will still be owned by theoriginal creator(s) or those who have been assigned copyright by theoriginal author(s).

By submitting a patch to the nghttp2 project, you (or your employer, asthe case may be) agree to assign the copyright of your submission to us... the above really needs to be reworded to pass legal muster.We will credit you for yourchanges as far as possible, to give credit but also to keep a traceback to who made what changes. Please always provide us with yourfull real name when contributing!

SeeContribution Guidelines for moredetails.

Versioning

In general, we followSemantic Versioning.

We may release PATCH releases between the regular releases, mainly forsevere security bug fixes.

We have no plan to break API compatibility changes involving sonamebump, so MAJOR version will stay 1 for the foreseeable future.

License

The MIT License

About

nghttp2 - HTTP/2 C Library and tools

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
COPYING

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors144


[8]ページ先頭

©2009-2025 Movatter.jp