The Byte
type represents a byte.
public typealias Byte = UInt8
The Data
type represents binary data as a collection of bytes.
An alternative name could be
Buffer
.
public struct Data {
public var bytes: [Byte]
}
The Stream
protocol represents a bi-directional stream of binary data.
public protocol Stream {
var closed: Bool { get }
func close() -> Bool
func receive() throws -> Data
func send(data: Data) throws
func flush() throws
}
The StreamClient
protocol represents a type that can make a connection and return a stream of binary data.
public protocol StreamClient {
func connect() throws -> Stream
}
The StreamServer
protocol represents a type that can accept a connection and return a stream of binary data.
public protocol StreamServer {
func accept() throws -> Stream
}
The HTTPVersion
type represents an HTTP version.
public typealias HTTPVersion = (major: Int, minor: Int)
The HTTPHeader
type represents an HTTP header value.
public typealias HTTPHeader = (name: String, value: String)
The HTTPHeaders
type represents HTTP headers.
public typealias HTTPHeaders = [HTTPHeader]
The HTTPBody
type represents an HTTP body in buffer or stream form.
public enum HTTPBody {
case BufferBody(Data)
case StreamBody(Stream)
}
The Storage
type represents arbitrary data that can be passed between middleware and a responder in a chain.
public typealias Storage = [String: Any]
The HTTPMessage
protocol represents properties common to HTTP messages (request or response).
public protocol HTTPMessage {
var version: HTTPVersion { get set }
var headers: HTTPHeaders { get set }
var body: HTTPBody { get set }
var storage: Storage { get set }
}
The HTTPMethod
type represents an HTTP method.
public enum HTTPMethod {
case Delete
case Get
case Head
case Post
case Put
case Connect
case Options
case Trace
case Copy
case Lock
case MkCol
case Move
case PropFind
case PropPatch
case Search
case Unlock
case Bind
case Rebind
case Unbind
case ACL
case Report
case MkActicity
case Checkout
case Merge
case MSearch
case Notify
case Subscribe
case Unsubscribe
case Patch
case Purge
case MkCalendar
case Link
case Unlink
case Raw(method: String)
}
The URI
type represents an URI.
public struct URI {
public struct UserInfo {
public var username: String
public var password: String
}
public var scheme: String?
public var userInfo: UserInfo?
public var host: String?
public var port: Int?
public var path: String?
public var query: [String: String]
public var fragment: String?
}
The HTTPRequest
protocol represents an HTTP request.
public protocol HTTPRequest: HTTPMessage {
var method: HTTPMethod { get }
var uri: URI { get }
var upgrade: ((response: HTTPResponse, stream: Stream) throws -> Void)? { get }
}
The HTTPRequestParser
protocol represents a type that can parse an HTTP request.
public protocol HTTPRequestParser {
func parse(data: Data) throws -> HTTPRequest?
}
The HTTPRequestSerializer
protocol represents a type that can serialize HTTP requests.
public protocol HTTPRequestSerializer {
func serialize(request: HTTPRequest, @noescape send: Data throws -> Void) throws
}
The HTTPStatus
protocol represents an HTTP status.
public enum HTTPStatus {
case Continue
case SwitchingProtocols
case Processing
case OK
case Created
case Accepted
case NonAuthoritativeInformation
case NoContent
case ResetContent
case PartialContent
case MultipleChoices
case MovedPermanently
case Found
case SeeOther
case NotModified
case UseProxy
case SwitchProxy
case TemporaryRedirect
case PermanentRedirect
case BadRequest
case Unauthorized
case PaymentRequired
case Forbidden
case NotFound
case MethodNotAllowed
case NotAcceptable
case ProxyAuthenticationRequired
case RequestTimeout
case Conflict
case Gone
case LengthRequired
case PreconditionFailed
case RequestEntityTooLarge
case RequestURITooLong
case UnsupportedMediaType
case RequestedRangeNotSatisfiable
case ExpectationFailed
case ImATeapot
case AuthenticationTimeout
case EnhanceYourCalm
case UnprocessableEntity
case Locked
case FailedDependency
case PreconditionRequired
case TooManyRequests
case RequestHeaderFieldsTooLarge
case InternalServerError
case NotImplemented
case BadGateway
case ServiceUnavailable
case GatewayTimeout
case HTTPVersionNotSupported
case VariantAlsoNegotiates
case InsufficientStorage
case LoopDetected
case NotExtended
case NetworkAuthenticationRequired
case Raw(statusCode: Int, reasonPhrase: String)
}
The HTTPResponse
protocol represents an HTTP response.
public protocol HTTPResponse: HTTPMessage {
var status: HTTPStatus { get }
var upgrade: ((request: HTTPRequest, stream: Stream) throws -> Void)? { get }
}
The HTTPResponseParser
protocol represents a type that can parse an HTTP response.
public protocol HTTPResponseParser {
func parse(data: Data) throws -> HTTPResponse?
}
The HTTPResponseSerializer
protocol represents a type that can serialize HTTP responses.
public protocol HTTPResponseSerializer {
func serialize(response: HTTPResponse, @noescape send: Data throws -> Void) throws
}
The HTTPResponder
protocol represents a type that can respond to HTTP requests.
public protocol HTTPResponder {
func respond(request: HTTPRequest) throws -> HTTPResponse
}
The HTTPMiddleware
protocol represents a type that responds to an HTTP request optionally forwarding the request to the chain.
public protocol HTTPMiddleware {
func respond(request: HTTPRequest, chain: HTTPResponder) throws -> HTTPResponse
}
The HTTPServer
protocol represents a type that serves HTTP requests by:
- Accepting a connection
- Parsing the HTTP request
- Applying middleware to the responder
- Responding the HTTP request
- Serializing the HTTP response
public protocol HTTPServer {
var server: StreamServer { get }
var parser: HTTPRequestParser { get }
var middleware: [HTTPMiddleware] { get }
var responder: HTTPResponder { get }
var serializer: HTTPResponseSerializer { get }
}
The HTTPClient
protocol represents a type that sends HTTP requests by:
- Making a connection
- Serializing the HTTP request
- Applying middleware to itself
- Parsing the HTTP response
public protocol HTTPClient: HTTPResponder {
var client: StreamClient { get }
var serializer: HTTPRequestSerializer { get }
var middleware: [HTTPMiddleware] { get }
var parser: HTTPResponseParser { get }
}
The HTTPRoute
protocol represents an HTTP route.
public protocol HTTPRoute: HTTPResponder {
var path: String { get }
var actions: [HTTPMethod: HTTPResponder] { get }
var fallback: HTTPResponder { get }
}
The HTTPRouter
protocol represents an HTTP router.
public protocol HTTPRouter: HTTPResponder {
var middleware: [HTTPMiddleware] { get }
var routes: [HTTPRoute] { get }
var fallback: HTTPResponder { get }
func match(request: HTTPRequest) -> HTTPRoute?
}