Struct hyper::server::Http
[−]
[src]
pub struct Http<B = Chunk> { /* fields omitted */ }
An instance of the HTTP protocol, and implementation of tokio-proto's
ServerProto
trait.
This structure is used to create instances of Server
or to spawn off tasks
which handle a connection to an HTTP server. Each instance of Http
can be
configured with various protocol-level options such as keepalive.
Methods
impl<B: AsRef<[u8]> + 'static> Http<B>
[src]
pub fn new() -> Http<B>
[src]
Creates a new instance of the HTTP protocol, ready to spawn a server or start accepting connections.
pub fn keep_alive(&mut self, val: bool) -> &mut Self
[src]
Enables or disables HTTP keep-alive.
Default is true.
pub fn bind<S, Bd>(
&self,
addr: &SocketAddr,
new_service: S
) -> Result<Server<S, Bd>> where
S: NewService<Request = Request, Response = Response<Bd>, Error = Error> + Send + Sync + 'static,
Bd: Stream<Item = B, Error = Error>,
[src]
&self,
addr: &SocketAddr,
new_service: S
) -> Result<Server<S, Bd>> where
S: NewService<Request = Request, Response = Response<Bd>, Error = Error> + Send + Sync + 'static,
Bd: Stream<Item = B, Error = Error>,
Bind the provided addr
and return a server ready to handle
connections.
This method will bind the addr
provided with a new TCP listener ready
to accept connections. Each connection will be processed with the
new_service
object provided as well, creating a new service per
connection.
The returned Server
contains one method, run
, which is used to
actually run the server.
pub fn bind_connection<S, I, Bd>(
&self,
handle: &Handle,
io: I,
remote_addr: SocketAddr,
service: S
) where
S: Service<Request = Request, Response = Response<Bd>, Error = Error> + 'static,
Bd: Stream<Item = B, Error = Error> + 'static,
I: AsyncRead + AsyncWrite + 'static,
[src]
&self,
handle: &Handle,
io: I,
remote_addr: SocketAddr,
service: S
) where
S: Service<Request = Request, Response = Response<Bd>, Error = Error> + 'static,
Bd: Stream<Item = B, Error = Error> + 'static,
I: AsyncRead + AsyncWrite + 'static,
Use this Http
instance to create a new server task which handles the
connection io
provided.
This is the low-level method used to actually spawn handling a TCP
connection, typically. The handle
provided is the event loop on which
the server task will be spawned, io
is the I/O object associated with
this connection (data that's read/written), remote_addr
is the remote
peer address of the HTTP client, and service
defines how HTTP requests
will be handled (and mapped to responses).
This method is typically not invoked directly but is rather transitively
used through bind
. This can be useful,
however, when writing mocks or accepting sockets from a non-TCP
location.
pub fn bind_upgradable_connection<S, I, P, Bd>(
&self,
handle: &Handle,
io: I,
remote_addr: SocketAddr,
service: S
) -> BindUpgradableConnection<I, B, P> where
S: Service<Request = Request, Response = UpgradableResponse<P, Bd>, Error = Error> + 'static,
Bd: Stream<Item = B, Error = Error> + 'static,
I: AsyncRead + AsyncWrite + 'static,
P: 'static,
[src]
&self,
handle: &Handle,
io: I,
remote_addr: SocketAddr,
service: S
) -> BindUpgradableConnection<I, B, P> where
S: Service<Request = Request, Response = UpgradableResponse<P, Bd>, Error = Error> + 'static,
Bd: Stream<Item = B, Error = Error> + 'static,
I: AsyncRead + AsyncWrite + 'static,
P: 'static,
Use this Http
instance to create a new server task which handles the
connection io
provided, and can be upgraded to another protocol in
response to a request from the client.
This behaves like bind_connection
, except the Service
supplied must
return an UpgradableResponse
containing either an HTTP Response
or
some information describing a protocol switch. If an Upgrade
response
is returned, the server task is shut down (without closing the
underlying io
) and this information is forwarded to the Future
returned by this method, along with the underlying io
and any
remaining buffered data that has already been read from it.
If the server task shuts down normally, the Future
completes with a
None
output value. In the case of an error handling the connection,
the error is also forwarded to this Future
.
Trait Implementations
impl<B> Clone for Http<B>
[src]
fn clone(&self) -> Http<B>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<B> Debug for Http<B>
[src]
impl<T, B> ServerProto<T> for Http<B> where
T: AsyncRead + AsyncWrite + 'static,
B: AsRef<[u8]> + 'static,
[src]
T: AsyncRead + AsyncWrite + 'static,
B: AsRef<[u8]> + 'static,
type Request = __ProtoRequest
Request headers.
type RequestBody = Chunk
Request body chunks.
type Response = __ProtoResponse
Response headers.
type ResponseBody = B
Response body chunks.
type Error = Error
Errors, which are used both for error frames and for the service itself.
type Transport = __ProtoTransport<T, B>
The frame transport, which usually take T
as a parameter.
type BindTransport = __ProtoBindTransport<T, B>
A future for initializing a transport from an I/O object. Read more
fn bind_transport(&self, io: T) -> Self::BindTransport
[src]
Build a transport from the given I/O object, using self
for any configuration. Read more