Struct actix_http::HttpService

source ·
pub struct HttpService<T, S, B, X = ExpectHandler, U = UpgradeHandler> { /* private fields */ }
Expand description

A ServiceFactory for HTTP/1.1 and HTTP/2 connections.

Use build to begin constructing service. Also see HttpServiceBuilder.

Automatic HTTP Version Selection

There are two ways to select the HTTP version of an incoming connection:

  • One is to rely on the ALPN information that is provided when using a TLS (HTTPS); both versions are supported automatically when using either of the .rustls() or .openssl() finalizing methods.
  • The other is to read the first few bytes of the TCP stream. This is the only viable approach for supporting H2C, which allows the HTTP/2 protocol to work over plaintext connections. Use the .tcp_auto_h2c() finalizing method to enable this behavior.

Examples

use actix_http::{HttpService, Request, Response, StatusCode};

// this service would constructed in an actix_server::Server

HttpService::build()
    // the builder finalizing method, other finalizers would not return an `HttpService`
    .finish(|_req: Request| async move {
        Ok::<_, Infallible>(
            Response::build(StatusCode::OK).body("Hello!")
        )
    })
    // the service finalizing method method
    // you can use `.tcp_auto_h2c()`, `.rustls()`, or `.openssl()` instead of `.tcp()`
    .tcp();

Implementations§

Create OpenSSL based service.

Create OpenSSL based service with custom TLS acceptor configuration.

Create Rustls based service.

Create Rustls based service with custom TLS acceptor configuration.

Constructs builder for HttpService instance.

Constructs new HttpService instance from service with default config.

Sets service for Expect: 100-Continue handling.

An expect service is called with requests that contain an Expect header. A successful response type is also a request which will be forwarded to the main service.

Sets service for custom Connection: Upgrade handling.

If service is provided then normal requests handling get halted and this service get called with original request and framed object.

Creates TCP stream service from HTTP service.

The resulting service only supports HTTP/1.x.

Creates TCP stream service from HTTP service that automatically selects HTTP/1.x or HTTP/2 on plaintext connections.

Trait Implementations§

Responses given by the created services.
Errors produced by the created services.
Service factory configuration.
The kind of Service created by this factory.
Errors potentially raised while building a service.
The future of the Service instance.g
Create and return a new service asynchronously.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Convert Self to a ServiceFactory
Should always be Self
Map this service’s output to a different type, returning a new service of the resulting type.
Map this service’s error to a different error, returning a new service.
Map this factory’s init error to a different error, returning a new service.
Call another service after call to this one has resolved successfully.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more