APIHttp.Wire
Http.Wire
HTTP/1.1 framing that requests and responses share: header blocks, body framing, and writing a message after its start line.
Http.Server and Http.Client build on it; applications rarely need it
directly. Failures raise Http.Protocol.invalid.
Framing
type Framing = NoBody | Fixed Int | Chunked | UntilCloseSource
How a message’s body is delimited.
Constructors
UntilClose
UntilClose : FramingSource
A response without framing headers lasts until the connection closes.
Instances:
Eq Framing
allToken
allToken : Bytes -> Int -> BoolSource
Whether the bytes from index on are all HTTP token characters, and the
whole is nonempty, as a header name or method must be.
import Bytes
import Http.Wire
Http.Wire.allToken (Bytes.fromString "Content-Type") 0
Http.Wire.allToken (Bytes.fromString "bad name") 0 == False
Http.Wire.allToken Bytes.empty 0 == False
checkMessage
checkMessage : List Header -> Body e -> Bool ->{Protocol} ()Source
Rejects a message before any of it is written. An unframed message (204, 304, or a request without a body) carries no framing headers and no body.
decodeField
decodeField : Bytes ->{Protocol} StringSource
A header field’s text, failing with Malformed when it is not UTF-8.
emptyBody
emptyBody : Reader eSource
A reader with no bytes, for a message without a body.
framing
framing : List Header -> Int ->{Protocol} FramingSource
A request without framing headers has no body.
headerLines
headerLines : Reader e -> Int -> List Header ->{Protocol, e} List HeaderSource
Reads a header block up to its empty line, failing with HeadersTooLarge
when it exceeds remaining bytes, and prepends its fields, in order, to
the reversed list given.
responseFraming
responseFraming : List Header -> Int ->{Protocol} FramingSource
A response without framing headers lasts until the connection closes.
withBody
withBody : Framing -> Reader e -> Int -> Int -> (Reader {#s} ->{#s} a) ->{Protocol, e} (a, Bool)Source
Scopes a framed body reader to action. The Bool reports whether the consumer
reached the end of the framed body.
writeCheckedMessage
writeCheckedMessage : (Error ->{e} ()) -> Writer e -> String -> List Header -> Body e -> Bool -> Bool ->{e} ()Source
Writes a message that passed checkMessage, after its start line. The head
goes out in one write, together with a byte body. sendBody False writes
only the head, as for HEAD. A sized body of the wrong length is passed to
reject, which must not return.
writeMessage
writeMessage : Writer {Protocol, e} -> String -> List Header -> Body {Protocol, e} -> Bool -> Bool ->{Protocol, e} ()Source
Checks a message with checkMessage and writes it after its start line:
the start line, its headers, and its body framed as Content-Length or
chunked. framed False marks a message that cannot carry a body;
sendBody False writes only the head, as for HEAD.
