Internal Interfaces

Internal Interfaces

Parser Interface

find_end_of_header(bytes) -> length or 0

Find length of header delimited by \r\n\r\n or \n\n.

source

Find \n after chunk size in bytes.

source
find_end_of_trailer(bytes) -> length or 0

Find length of trailer delimited by \r\n\r\n (or starting with \r\n). RFC7230 4.1

source

Parse HTTP response-line bytes and set the status and version fields of response. Return a SubString containing the header-field lines.

source

Parse HTTP request-line bytes and set the method, target and version fields of request. Return a SubString containing the header-field lines.

source

Parse HTTP header-field. Return Pair(field-name => field-value) and a SubString containing the remaining header-field lines.

source

Parse HTTP chunk-size. Return number of bytes of chunk-data.

chunk-size = 1*HEXDIG

RFC7230 4.1

source

Messages Interface

Request <: Message

Represents a HTTP Request Message.

  • method::String RFC7230 3.1.1

  • target::String RFC7230 5.3

  • version::VersionNumber RFC7230 2.6

  • headers::Vector{Pair{String,String}} RFC7230 3.2

  • body::Vector{UInt8} RFC7230 3.3

  • response, the Response to this Request

  • txcount, number of times this Request has been sent (see RetryRequest.jl).

  • parent, the Response (if any) that led to this request (e.g. in the case of a redirect). RFC7230 6.4

source
Response <: Message

Represents a HTTP Response Message.

source
HTTP.Messages.iserrorFunction.
iserror(::Response)

Does this Response have an error status?

source
isredirect(::Response)

Does this Response have a redirect status?

source
ischunked(::Message)

Does the Message have a "Transfer-Encoding: chunked" header?

source
HTTP.Messages.issafeFunction.
issafe(::Request)

https://tools.ietf.org/html/rfc7231#section-4.2.1

source
isidempotent(::Request)

https://tools.ietf.org/html/rfc7231#section-4.2.2

source
HTTP.Messages.headerFunction.
header(::Message, key [, default=""]) -> String

Get header value for key (case-insensitive).

source
hasheader(::Message, key) -> Bool

Does header value for key exist (case-insensitive)?

source
hasheader(::Message, key, value) -> Bool

Does header for key match value (both case-insensitive)?

source
setheader(::Message, key => value)

Set header value for key (case-insensitive).

source
defaultheader!(::Message, key => value)

Set header value in message for key if it is not already set.

source
appendheader(::Message, key => value)

Append a header value to message.headers.

If key is the same as the previous header, the value is appended to the value of the previous header with a comma delimiter

Set-Cookie headers are not comma-combined because cookies often contain internal commas.

source
readheaders(::IO, ::Message)

Read headers (and startline) from an IO stream into a Message struct. Throw EOFError if input is incomplete.

source
setuseragent!(x::Union{String, Nothing})

Set the default User-Agent string to be used in each HTTP request. Can be manually overridden by passing an explicit User-Agent header. Setting nothing will prevent the default User-Agent header from being passed.

source

Read chunk-size from an IO stream. After the final zero size chunk, read trailers into a Message struct.

source
headerscomplete(::Message)

Have the headers been read into this Message?

source
writestartline(::IO, ::Message)

e.g. "GET /path HTTP/1.1\r\n" or "HTTP/1.1 200 OK\r\n"

source
writeheaders(::IO, ::Message)

Write Message start line and a line for each "name: value" pair and a trailing blank line.

source
Base.writeMethod.
write(::IO, ::Message)

Write start line, headers and body of HTTP Message.

source

IOExtras Interface

HTTP.IOExtrasModule.
IOExtras

This module defines extensions to the Base.IO interface to support:

  • startwrite, closewrite, startread and closeread for streams with transactional semantics.
source
startwrite(::IO)
closewrite(::IO)
startread(::IO)
closeread(::IO)

Signal start/end of write or read operations.

source
isioerror(exception)

Is exception caused by a possibly recoverable IO error.

source

Streams Interface

closebody(::Stream)

Write the final 0 chunk if needed.

source
isaborted(::Stream{Response})

Has the server signaled that it does not wish to receive the message body?

"If [the response] indicates the server does not wish to receive the message body and is closing the connection, the client SHOULD immediately cease transmitting the body and close the connection." RFC7230, 6.5

source

Connection Pooling Interface

Connection{T <: IO}

A TCPSocket or SSLContext connection to a HTTP host and port.

Fields:

  • host::String
  • port::String, exactly as specified in the URI (i.e. may be empty).
  • pipeline_limit, number of requests to send before waiting for responses.
  • idle_timeout, No. of seconds to maintain connection after last transaction.
  • peerport, remote TCP port number (used for debug messages).
  • localport, local TCP port number (used for debug messages).
  • io::T, the TCPSocket or `SSLContext.
  • clientconnection::Bool, whether the Connection was created from client code (as opposed to server code)
  • buffer::IOBuffer, left over bytes read from the connection after the end of a response header (or chunksize). These bytes are usually part of the response body.
  • sequence, number of most recent Transaction.
  • writecount, number of Messages that have been written, protected by writelock
  • writelock, lock writecount and writebusy, and signal that writecount was incremented.
  • writebusy, whether a Transaction currently holds the Connection write lock, protected by writelock
  • readcount, number of Messages that have been read, protected by readlock
  • readlock, lock readcount and readbusy, and signal that readcount was incremented.
  • readbusy, whether a Transaction currently holds the Connection read lock, protectecd by readlock
  • timestamp, time data was last received.
source
Transaction

A single pipelined HTTP Request/Response transaction.

Fields:

  • c, the shared Connection used for this Transaction.
  • sequence::Int, identifies this Transaction among the others that share c.
  • writebusy::Bool, whether this Transaction holds its parent Connection write lock, protected by c.writelock
  • readbusy::Bool, whether this Transaction holds its parent Connection read lock, protected by c.readlock
source
Missing docstring.

Missing docstring for HTTP.ConnectionPool.pool. Check Documenter's build log for details.

getconnection(type, host, port) -> Connection

Find a reusable Connection in the pool, or create a new Connection if required.

source
startwrite(::Transaction)

Wait for prior pending writes to complete.

source
closewrite(::Transaction)

Signal that an entire Request Message has been written to the Transaction.

source
startread(::Transaction)

Wait for prior pending reads to complete.

source
closeread(::Transaction)

Signal that an entire Response Message has been read from the Transaction.

Increment readcount and wake up tasks waiting in startread.

source