Struct tk_http::server::Head
[−]
[src]
pub struct Head<'a> { /* fields omitted */ }A borrowed structure that represents request headers
It's passed to Codec::headers_received and you are free to store or
discard any needed fields and headers from it.
Methods
impl<'a> Head<'a>[src]
fn method(&self) -> &str
Returns a HTTP method
fn request_target(&self) -> &RequestTarget<'a>
Request-target (the middle part of the first line of request)
fn raw_request_target(&self) -> &str
Returns a raw request target as string
fn path(&self) -> Option<&str>
Returns path portion of request uri
Note: this may return something not starting from a slash when full uri is used as request-target
If the request target is in asterisk form this returns None
fn host(&self) -> Option<&str>
Return host of a request
Note: this might be extracted from request-target portion of request headers (first line).
If both Host header exists and doesn't match host in request-target
then this method returns host from request-target and
has_conflicting_host() method returns true.
fn has_conflicting_host(&self) -> bool
Returns true if Host header conflicts with host in request-uri
By spec this fact may be ignored in proxy, but better to reply BadRequest in this case
fn version(&self) -> Version
Version of HTTP request
fn headers(&self) -> HeaderIter
Iterator over the headers of HTTP request
This iterator strips the following kinds of headers:
- Hop-by-hop headers (
Connectionitself, and ones it enumerates) Content-LengthandTransfer-EncodingHostheaderUpgradeheader regardless of whether it's inConnection
You may use all_headers() if you really need to access to all of
them (mostly useful for debugging puproses). But you may want to
consider:
- Host of the target request can be received using
host()method, which is also parsed fromtargetpath of request if that is in absolute form (so conforming to the spec) - Payload size can be fetched using
body_length()method. Note: this also includes cases where length is implicitly set to zero. Connectionheader might be discovered withconnection_close()orconnection_header()Upgrademight be discovered withget_websocket_upgrade()or only looked inall_headers()ifupgradepresents inconnection_header()
fn all_headers(&self) -> &'a [Header<'a>]
All headers of HTTP request
Unlike self.headers() this does include hop-by-hop headers. This
method is here just for completeness, you shouldn't need it.
fn connection_close(&self) -> bool
Return true if Connection: close header exists
fn connection_header(&'a self) -> Option<&'a str>
Returns the value of the Connection header (all of them, if multiple)
fn has_body(&self) -> bool
Returns true if there was transfer-encoding or content-length != 0
I.e. false may mean either Content-Length: 0 or there were no
content length. This is mostly important to check for requests which
must not have body (HEAD, CONNECT, Upgrade: websocket ...)
fn body_length(&self) -> Option<u64>
Returns size of the request body if either Content-Length is set
or it is safe to assume that request body is zero-length
If request length can't be determined in advance (such as when there
is a Transfer-Encoding) None is returned
fn get_websocket_upgrade(&self) -> Result<Option<WebsocketHandshake>, ()>
Check if connection is a websocket and return hanshake info
Err(()) is returned when there was handshake but where was something
wrong with it (so you should return BadRequest even if you support
plain http on the resource).
Ok(None) is returned when it's a plain HTTP request (no upgrade).
Note: this method computes handshake again, so it's better not to call it multiple times.