2021-05-26 19:05:53 +08:00
# HTTP/2
2023-03-27 19:43:59 -07:00
The transmission mode based on HTTP/2 fully implements the HTTP/2 standard and can be relayed by other HTTP servers (such as Nginx).
2021-05-26 19:05:53 +08:00
2023-03-27 19:43:59 -07:00
Based on the recommendations of HTTP/2, both the client and server must enable TLS to use this transmission mode normally.
2021-05-26 19:05:53 +08:00
2023-03-27 19:43:59 -07:00
HTTP/2 has built-in multiplexing, so it is not recommended to enable mux.cool when using HTTP/2.
2021-05-26 19:05:53 +08:00
::: tip
2023-03-27 19:43:59 -07:00
The current version of the transmission mode based on HTTP/2 does not require TLS configuration for inbound (server-side).
This makes it possible to use a plaintext HTTP/2 protocol called h2c for communication between the gateway and Xray, with external gateway components handling the TLS layer conversation in special-purpose load-balancing deployment environments.
2021-05-26 19:05:53 +08:00
:::
::: warning
2023-03-27 19:43:59 -07:00
⚠️ If you are using fallback, please note the following:
2021-05-26 19:05:53 +08:00
2023-03-27 19:43:59 -07:00
- Please make sure that `h2` is included in `(x)tlsSettings.alpn` , otherwise HTTP/2 cannot complete TLS handshake.
- HTTP/2 cannot perform path-based routing, so it is recommended to use SNI-based routing.
2021-05-26 19:05:53 +08:00
:::
## HttpObject
2023-03-27 19:43:59 -07:00
`HttpObject` corresponds to the `httpSettings` in the [Transport Protocol ](../transport.md ),
2021-05-26 19:05:53 +08:00
```json
{
"host": ["xray.com"],
2023-03-04 11:39:44 -05:00
"path": "/random/path",
"read_idle_timeout": 10,
"health_check_timeout": 15,
"method": "PUT",
"headers": {
"Header": ["value"]
}
2021-05-26 19:05:53 +08:00
}
```
> `host`: \[string\]
2023-03-27 19:43:59 -07:00
A string array, where each element is a domain name.
2021-05-26 19:05:53 +08:00
2023-03-27 19:43:59 -07:00
The client will randomly select a domain name from the list for communication, and the server will verify whether the domain name is in the list.
2021-05-26 19:05:53 +08:00
2023-03-04 11:39:44 -05:00
> `path`: string
2021-05-26 19:05:53 +08:00
2023-03-27 19:43:59 -07:00
The HTTP path starts with `/` and must be the same value between the client and server.
2021-05-26 19:05:53 +08:00
2023-03-27 19:43:59 -07:00
The default value is `/`
2023-03-04 11:39:44 -05:00
> `read_idle_timeout`: number
2023-03-27 19:43:59 -07:00
The connection health check is performed when no data has been received for a certain period of time, measured in seconds.
2023-03-04 11:39:44 -05:00
2023-03-27 19:43:59 -07:00
By default, the health check is **disabled** .
2023-03-04 11:39:44 -05:00
::: tip
2023-03-27 19:43:59 -07:00
**Only need to be configured** in ** `outbound` ** (**client**).
2023-03-04 11:39:44 -05:00
:::
::: tip
2023-03-27 19:43:59 -07:00
Enabling health checks may help solve some "connection drop" issues.
2023-03-04 11:39:44 -05:00
:::
> `health_check_timeout`: number
2023-03-27 19:43:59 -07:00
The timeout for the health check, measured in seconds. If the health check is not completed within this time period, it is considered to have failed.
The default value is `15`
2023-03-04 11:39:44 -05:00
::: tip
2023-03-27 19:43:59 -07:00
**Only need to be configured** in `outbound` ** (client)**.
2023-03-04 11:39:44 -05:00
:::
> `method`: string
2023-03-27 19:43:59 -07:00
HTTP request method. The default value is `PUT`
2023-03-04 11:39:44 -05:00
2023-03-27 19:43:59 -07:00
Please refer this [this ](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods ) when configure.
2023-03-04 11:39:44 -05:00
> `headers`: map{ string: \[string\] }
2023-03-27 19:43:59 -07:00
Custom HTTP headers, defined as key-value pairs. Each key represents an HTTP header name and its corresponding value is an array.