H2O

the optimized HTTP/1.x, HTTP/2, HTTP/3 server

Powered by Oktavia

Configure > HTTP/2 Directives

H2O provides one of the world's most sophisticated HTTP/2 protocol implementation, including following features.

Prioritization

H2O is one of the few servers that fully implement prioritization of HTTP responses conformant to what is defined in the HTTP/2 specification. The server implements a O(1) scheduler that determines which HTTP response should be sent to the client, per every 16KB chunk.

Unfortunately, some web browsers fail to specify response priorities that lead to best end-user experience. H2O is capable of detecting such web browsers, and if it does, uses server-driven prioritization; i.e. send responses with certain MIME-types before others.

It is possible to tune or turn off server-driven prioritization using directives: file.mime.addtypes, http2-reprioritize-blocking-assets.

See also:

Server push

H2O recognizes link headers with preload keyword sent by a backend application server (reverse proxy or FastCGI) or an mruby handler, and pushes the designated resource to a client.

Example. A link response header triggering HTTP/2 push
link: </assets/jquery.js>; rel=preload; as=script

When the HTTP/2 driver of H2O recognizes a link response header with rel=preload attribute set, and if all of the following conditions are met, the specified resource is pushed to the client.

The server also provides a mechanism to track the clients' cache state via cookies, and to push the resources specified with the link header only when it does not exist within the clients' cache. For details, please refer to the documentation of http2-casper configuration directive.

When a resource is pushed, the priority is determined using the priority attribute of the MIME-type configuration. If the priority is set to highest then the resource will be sent to the client before anything else; otherwise the resource will be sent to client after the main content, as per defined by the HTTP/2 specification.

HTTP/1.1 allows a server to send an informational response (see RFC 7230 section 6.2) before sending the final response. Starting from version 2.1, web applications can take advantage of the informational response to initiate HTTP/2 pushes before starting to process the request. The following example shows how such responses would look like.

Example. 100 response with link headers
HTTP/1.1 100 Continue
Link: </assets/style.css>; rel=preload; as=style
Link: </assets/jquery.js>; rel=preload; as=script

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8

<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/assets/style.css">
<script type="text/javascript" src="/assets/jquery.js"></scrrpt>
...

Pushed responses will have x-http2-push: pushed header set; by looking for the header, it is possible to determine if a resource has been pushed. It is also possible to log the value in the access log by specifying %{x-http2-push}o, push responses but cancelled by CASPER will have the value of the header logged as cancelled.

See also:

Latency Optimization

When using HTTP/2, a client often issues high-priority requests (e.g. requests for CSS and JavaScript files that block the rendering) while a lower-priority response (e.g. HTML) is in flight. In such case, it is desirable for a server to switch to sending the response of the high-priority requests as soon as it observes the requests.

In order to do so, send buffer of the TCP/IP stack should be kept empty except for the packets in-flight, and size of the TLS records must be small enough to avoid head-of-line blocking. The downside is that obeying the requirement increases the interaction between the server process and kernel, which result in consumption of more CPU cycles and slightly increased latency.

Starting from version 2.1, H2O provides directives that lets the users tune how the TCP/IP stack is used depending on the observed RTT, CWND, and the additional latency imposed by the interaction between the server and the OS.

For TCP/IP connections with greater RTT and smaller CWND than the configured threshold, the server will try to keep the size of HTTP/2 frames unsent as small as possible so that it can switch to sending a higher-priority response. Benchmarks suggest that users can expect in average 1 RTT reduction when this optimization is enabled. For connections that do not meet the criteria, the server will utilize the TCP/IP stack in ordinary ways.

The default values of the thresholds have been chosen that the optimization will come into action for mobile and long-distance networks but not when a proxy exists on the network.

The optimization is supported only on Linux and OS X. The two are the operating systems that provide access to TCP_INFO and an interface to adjust the size of the unsent buffer (TCP_NOTSENT_LOWAT).

Please refer to the documentation of the directives below to configure the optimization:

See also:

The following describes the configuration directives for controlling the HTTP/2 protocol handler.

Description:

Configures CASPer (cache-aware server-push).

When enabled, H2O maintains a fingerprint of the web browser cache, and cancels server-push suggested by the handlers if the client is known to be in possession of the content. The fingerprint is stored in a cookie named h2o_casper using Golomb-compressed sets (a compressed encoding of Bloom filter).

If the value is OFF, the feature is disabled. Push requests (made by the handlers through the use of Link: rel=preload header) are processed regardless of whether if client already has the responses in its cache. If the value is ON, the feature is enabled with the defaults value specified below. If the value is mapping, the feature is enabled, recognizing the following attributes.

capacity-bits:
number of bits used for the fingerprinting. Roughly speaking, the number of bits should be log2(1/P * number-of-assets-to-track) where P being the probability of false positives. Default is 13, enough for tracking about 100 asset files with 1/100 chance of false positives (i.e. log2(100 * 100) =~ 13).
tracking-types:
specifies the types of the content tracked by casper. If omitted or set to blocking-assets, maintains fingerprint (and cancels server push) for resources with mime-type of highest priority. If set to all, tracks all responses.

It should be noted that the size of the cookie will be log2(P) * number-of-assets-being-tracked bits multiplied by the overhead of Base 64 encoding (4/3). Therefore with current cookie-based implementation, it is necessary in many cases to restrict the resources being tracked to those have significant effect to user-perceived response time.

Example. Enabling CASPer
http2-casper: ON

# `ON` is equivalent to:
# http2-casper:
#   capacity-bits:  13
#   tracking-types: blocking-assets
Level:
global, host
Default:
http2-casper: OFF
See also:
file.mime.addtypes, issue #421
Description:

A directive to turn on the HTTP/2 Implementation Debug State.

This experimental feature serves a JSON document at the fixed path /.well-known/h2/state, which describes an internal HTTP/2 state of the H2O server. To know the details about the response fields, please see the spec. This feature is only for developing and debugging use, so it's highly recommended that you disable this setting in the production environment.

The value of this directive specifies the property set contained in the response. Available values are minimum or hpack. If hpack is specified, the response will contain the internal hpack state of the same connection. If minimum is specified, the response doesn't contain the internal hpack state.

In some circumstances, there may be a risk of information leakage on providing an internal hpack state. For example, the case that some proxies exist between the client and the server, and they share the connections among the clients. Therefore, you should specify hpack only when the server runs in the environments you can completely control.

This feature is considered experimental yet. For now, the implementation conforms to the version draft-01 of the specification.

Level:
host
See also:
HTTP/2 Implementation Debug State (draft-01)
Description:

Timeout for idle connections in seconds.

Level:
global
Default:
http2-idle-timeout: 10
Description:

Default window size for HTTP request body.

The value is the maximum amount of request body (in bytes) that can be sent by the client in 1 RTT (round-trip time).
Level:
global
Default:
16777216
Description:

Maximum number of requests to be handled concurrently within a single HTTP/2 connection.

The value cannot exceed 256.

Level:
global
Default:
http2-max-concurrent-requests-per-connection: 100
Description:

Maximum number of streaming requests to be handled concurrently within a single HTTP/2 connection.

The value cannot exceed 256.

Level:
global
Default:
http2-max-concurrent-streaming-requests-per-connection: 1
Description:

Minimum RTT (in milliseconds) to enable latency optimization.

Latency optimization is disabled for TCP connections with smaller RTT (round-trip time) than the specified value. Otherwise, whether if the optimization is used depends on other parameters.

Setting this value to 4294967295 (i.e. UINT_MAX) effectively disables the optimization.

Level:
global
Default:
http2-latency-optimization-min-rtt: 50
Description:

Maximum additional delay (as the ratio to RTT) permitted to get latency optimization activated.

Latency optimization is disabled if the additional delay imposed by the interaction between the OS and the TCP/IP stack is estimated to be greater than the given threshold. Otherwise, whether if the optimization is used depends on other parameters.

Level:
global
Default:
http2-latency-optimization-max-additional-delay: 0.1
Description:

Maximum size (in octets) of CWND to get latency optimization activated.

CWND is a per-TCP-connection variable that represents the number of bytes that can be sent within 1 RTT.

The server will not use or stop using latency optimization mode if CWND becomes greater than the configured value. In such case, average size of HTTP/2 frames buffered unsent will be slightly above the tcp_notsent_lowat sysctl value.

Level:
global
Default:
http2-latency-optimization-max-cwnd: 65535
Description:

A boolean flag (ON or OFF) indicating whether if the server should push resources when observing a link: rel=preload header.

Level:
global, host
Default:
http2-push-preload: ON
Description:

A boolean flag (ON or OFF) indicating if the server should send contents with highest priority before anything else.

To maximize the user-perceived responsiveness of a web page, it is essential for the web server to send blocking assets (i.e. CSS and JavaScript files in <HEAD>) before any other files such as images. HTTP/2 provides a way for web browsers to specify such priorities to the web server. However, as of Sep. 2015, no major web browsers except Mozilla Firefox take advantage of the feature.

This option, when enabled, works as a workaround for such web browsers, thereby improving experience of users using the web browsers.

Technically speaking, it does the following:

  • if the client uses dependency-based prioritization, do not reprioritize
  • if the client does not use dependency-based prioritization, send the contents of which their types are given highest priority before any other responses

Level:
global
Default:
http2-reprioritize-blocking-assets: ON
See also:
file.mime.addtypes, HTTP/2 (and H2O) improves user experience over HTTP/1.1 or SPDY
Description:

A timeout in seconds. How long to wait before closing the connection on graceful shutdown. Setting the timeout to 0 deactivates the feature: H2O will wait for the peer to close the connections.

Level:
global
Default:
http2-graceful-shutdown-timeout: 0
Description:

A boolean flag (ON or OFF) indicating whether if the server should push resources belonging to a different authority.

Level:
global, path
Default:
http2-allow-cross-origin-push: OFF