2018-05-22 23:15:08 +02:00
---
2020-09-12 16:21:54 +01:00
title: HTTP/2
2018-05-22 23:15:08 +02:00
---
2024-05-28 20:23:34 +01:00
import RenderCodeBlock from '@theme/CodeBlock ';
import CodeBlock from '@site/src/components/code_block ';
2022-07-16 11:59:20 +02:00
2023-11-01 15:28:34 +00:00
`actix-web` automatically upgrades connections to _HTTP/2_ if possible.
2018-05-22 23:15:08 +02:00
# Negotiation
2020-09-12 16:21:54 +01:00
<!-- TODO: use rustls example -->
2022-02-26 04:41:49 +00:00
2024-03-02 17:30:54 +00:00
When either of the `rustls` or `openssl` features are enabled, `HttpServer` provides the [`bind_rustls()` ][bindrustls] method and [`bind_openssl()` ][bindopenssl] methods, respectively.
2018-05-22 23:15:08 +02:00
2022-07-16 11:59:20 +02:00
<!-- DEPENDENCY -->
2024-03-02 17:30:54 +00:00
< CodeBlock example = "http2" file = "manifest" section = "deps" language = "toml" > < / CodeBlock >
2022-02-26 04:41:49 +00:00
2022-07-16 11:59:20 +02:00
< CodeBlock example = "http2" file = "main.rs" section = "main" / >
2018-05-22 23:15:08 +02:00
2022-03-21 01:54:49 +00:00
Upgrades to HTTP/2 described in [RFC 7540 §3.2][rfcsection32] are not supported. Starting HTTP/2 with prior knowledge is supported for both cleartext and TLS connections ([RFC 7540 §3.4][rfcsection34]) (when using the lower level `actix-http` service builders).
2018-05-22 23:15:08 +02:00
2022-03-21 01:54:49 +00:00
> Check out [the TLS examples][examples] for concrete example.
2019-06-24 23:36:32 -04:00
2022-03-21 01:54:49 +00:00
[rfcsection32]: https://httpwg.org/specs/rfc7540.html#rfc .section.3.2
[rfcsection34]: https://httpwg.org/specs/rfc7540.html#rfc .section.3.4
2024-03-02 17:30:54 +00:00
[bindrustls]: https://docs.rs/actix-web/4/actix_web/struct.HttpServer.html#method .bind_rustls_0_22
2022-03-05 23:55:35 +00:00
[bindopenssl]: https://docs.rs/actix-web/4/actix_web/struct.HttpServer.html#method .bind_openssl
2019-06-24 23:36:32 -04:00
[tlsalpn]: https://tools.ietf.org/html/rfc7301
2022-03-21 01:54:49 +00:00
[examples]: https://github.com/actix/examples/tree/master/https-tls