Safe Haskell | None |
---|---|
Language | Haskell2010 |
Utilities for working with headers.
- lowercaseHeaders :: Headers -> Headers
- headersAreLowercase :: Headers -> Bool
- headersAreLowercaseAtHeaderEditor :: HeaderEditor -> Bool
- fetchHeader :: Headers -> ByteString -> Maybe ByteString
- data HeaderEditor
- fromList :: Headers -> HeaderEditor
- toList :: HeaderEditor -> Headers
- headerLens :: ByteString -> Lens' HeaderEditor (Maybe ByteString)
- replaceHeaderValue :: HeaderEditor -> ByteString -> Maybe ByteString -> HeaderEditor
- replaceHostByAuthority :: HeaderEditor -> HeaderEditor
- introduceDateHeader :: HeaderEditor -> IO HeaderEditor
Simple manipulation
These transformations are simple enough that don't require
going away from the list representation (see type Headers
)
lowercaseHeaders :: Headers -> Headers Source
HTTP headers are case-insensitive, so we can use lowercase versions everywhere
headersAreLowercase :: Headers -> Bool Source
Checks that headers are lowercase
headersAreLowercaseAtHeaderEditor :: HeaderEditor -> Bool Source
fetchHeader :: Headers -> ByteString -> Maybe ByteString Source
Looks for a given header
Transformations based on maps
Many operations benefit from transforming the list to a map with custom sorting and doing a set of operations on that representation.
data HeaderEditor Source
Introducing and removing the HeaderEditor
fromList :: Headers -> HeaderEditor Source
O(n*log n) Builds the editor from a list.
toList :: HeaderEditor -> Headers Source
O(n) Takes the HeaderEditor back to Headers
Access to a particular header
headerLens :: ByteString -> Lens' HeaderEditor (Maybe ByteString) Source
headerLens header_name represents a lens into the headers,
and you can use it then to add, alter and remove headers.
It uses the same semantics than replaceHeaderValue
replaceHeaderValue :: HeaderEditor -> ByteString -> Maybe ByteString -> HeaderEditor Source
replaceHeaderValue headers header_name maybe_header_value looks for header_name. If header_name is found and maybe_header_value is nothing, it returns a new headers list with the header deleted. If header_name is found and header_value is Just new_value, it returns a new list with the header containing the new value. If header_name is not in headers and maybe_header_value is Nothing, it returns the original headers list. If header_name is not in headers and maybe_header_value is Just new_value, it returns a new list where the last element is (header_name, new_value)
HTTP utilities
replaceHostByAuthority :: HeaderEditor -> HeaderEditor Source
Replaces a "host" HTTP/1.1 header by an ":authority" HTTP/2 header. The list is expected to be already in lowercase, so nothing will happen if there the header name portion is "Host" instead of "host".
Notice that having a Host header in an HTTP/2 message is perfectly valid in certain circumstances, check Section 8.1.2.3 of the spec for details.
introduceDateHeader :: HeaderEditor -> IO HeaderEditor Source
Given a header editor, introduces a Date header. This function has a side-effect: to get the current time