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]

[src]

Returns a HTTP method

[src]

Request-target (the middle part of the first line of request)

[src]

Returns a raw request target as string

[src]

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

[src]

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.

[src]

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

[src]

Version of HTTP request

[src]

Iterator over the headers of HTTP request

This iterator strips the following kinds of headers:

  1. Hop-by-hop headers (Connection itself, and ones it enumerates)
  2. Content-Length and Transfer-Encoding
  3. Host header
  4. Upgrade header regardless of whether it's in Connection

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:

  1. Host of the target request can be received using host() method, which is also parsed from target path of request if that is in absolute form (so conforming to the spec)
  2. Payload size can be fetched using body_length() method. Note: this also includes cases where length is implicitly set to zero.
  3. Connection header might be discovered with connection_close() or connection_header()
  4. Upgrade might be discovered with get_websocket_upgrade() or only looked in all_headers() if upgrade presents in connection_header()

[src]

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.

[src]

Return true if Connection: close header exists

[src]

Returns the value of the Connection header (all of them, if multiple)

[src]

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 ...)

[src]

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

[src]

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.

Trait Implementations

impl<'a> Debug for Head<'a>
[src]

[src]

Formats the value using the given formatter.