http_connection/lib.rs
1#![doc(html_root_url = "https://docs.rs/http-connection/0.1.0")]
2#![deny(missing_debug_implementations, missing_docs, unreachable_pub)]
3#![cfg_attr(test, deny(warnings))]
4
5//! Asynchronous HTTP connection
6//!
7//! This trait decorates an `AsyncRead + AsyncWrite` connection stream/sink with HTTP
8//! aware information like the connections HTTP version and the remote address.
9
10extern crate http;
11#[cfg(feature = "tcp")]
12extern crate tokio_tcp;
13
14use http::Version;
15use std::net::SocketAddr;
16
17#[cfg(feature = "tcp")]
18mod tcp;
19
20/// Represents a HTTP aware connection.
21///
22/// This connection is a `AsyncRead + AsyncWrite` stream that provides information
23/// on what http versions were determinted `ALPN` negotiation or what the remote address
24/// this stream is connected too.
25pub trait HttpConnection {
26 /// Returns the version that this stream is set too.
27 ///
28 /// For `version` this indicates that this stream is accepting http frames of the version
29 /// returned. If `None` is returned then there has been no prior negotiation for the http
30 /// version.
31 fn negotiated_version(&self) -> Option<Version> {
32 None
33 }
34
35 /// Returns the remote address that this connection is connected to.
36 fn remote_addr(&self) -> Option<SocketAddr> {
37 None
38 }
39}