Add inlinables (#149)

### Motivation

We want to have fast code.

### Changes

Add `@inlinable` to a number of functions, to allow better compiler
optimizations.

### Result

Improvements in some benchmarks
This commit is contained in:
Fabian Fett authored and GitHub committed 2026-09-01 16:09:13 +02:00
1 parent f41c097554
commit 6aff14dae9
6 files changed
+312 -81

No files matched your search

+43 -13
View File
@@ -21,28 +21,36 @@ public struct HTTPField: Sendable, Hashable {
/// The strategy for whether the field is indexed in the HPACK or QPACK dynamic table.
public struct DynamicTableIndexingStrategy: Sendable, Hashable {
/// Default strategy.
@inlinable
public static var automatic: Self { .init(uncheckedValue: 0) }
/// Always put this field in the dynamic table if possible.
@inlinable
public static var prefer: Self { .init(uncheckedValue: 1) }
/// Don't put this field in the dynamic table.
@inlinable
public static var avoid: Self { .init(uncheckedValue: 2) }
/// Don't put this field in the dynamic table, and set a flag to disallow intermediaries to
/// index this field.
@inlinable
public static var disallow: Self { .init(uncheckedValue: 3) }
fileprivate let rawValue: UInt8
@usableFromInline
let rawValue: UInt8
private static let maxRawValue: UInt8 = 3
@inlinable
static var maxRawValue: UInt8 { 3 }
private init(uncheckedValue: UInt8) {
@inlinable
init(uncheckedValue: UInt8) {
assert(uncheckedValue <= Self.maxRawValue)
self.rawValue = uncheckedValue
}
fileprivate init?(rawValue: UInt8) {
@inlinable
init?(rawValue: UInt8) {
if rawValue > Self.maxRawValue {
return nil
}
@@ -55,6 +63,7 @@ public struct HTTPField: Sendable, Hashable {
/// - name: The HTTP field name.
/// - value: The HTTP field value is initialized from the UTF-8 encoded bytes of the string.
/// Invalid bytes are converted into space characters.
@inlinable
public init(name: Name, value: String) {
self.name = name
self.rawValue = HTTPField.Value(legalize: value)
@@ -64,6 +73,7 @@ public struct HTTPField: Sendable, Hashable {
/// - Parameters:
/// - name: The HTTP field name.
/// - value: The HTTP field value. Invalid bytes are converted into space characters.
@inlinable
public init(name: Name, value: some Collection<UInt8>) {
self.name = name
self.rawValue = HTTPField.Value(legalize: value)
@@ -75,6 +85,7 @@ public struct HTTPField: Sendable, Hashable {
/// - lenientValue: The HTTP field value. Newlines and NULs are converted into space
/// characters.
@available(HTTPTypes 1.1, *)
@inlinable
public init(name: Name, lenientValue: some Collection<UInt8>) {
self.name = name
self.rawValue = HTTPField.Value(lenient: lenientValue)
@@ -96,6 +107,7 @@ public struct HTTPField: Sendable, Hashable {
///
/// If the field is not UTF-8 encoded, `withUnsafeBytesOfValue` can be used to access the
/// underlying bytes of the field value.
@inlinable
public var value: String {
get {
self.rawValue.string
@@ -114,6 +126,7 @@ public struct HTTPField: Sendable, Hashable {
///
/// - Parameter body: The closure to be invoked with the buffer.
/// - Returns: Result of the `body` closure.
@inlinable
public func withUnsafeBytesOfValue<Result, Failure: Error>(
_ body: (UnsafeBufferPointer<UInt8>) throws(Failure) -> Result
) throws(Failure) -> Result {
@@ -123,6 +136,7 @@ public struct HTTPField: Sendable, Hashable {
/// The strategy for whether the field is indexed in the HPACK or QPACK dynamic table.
public var indexingStrategy: DynamicTableIndexingStrategy = .automatic
@usableFromInline
var rawValue: HTTPField.Value
/// Whether the string is valid for an HTTP field value based on RFC 9110.
@@ -131,6 +145,7 @@ public struct HTTPField: Sendable, Hashable {
///
/// - Parameter value: The string to validate.
/// - Returns: Whether the string is valid.
@inlinable
public static func isValidValue(_ value: String) -> Bool {
Self.Value.isValid(value)
}
@@ -141,6 +156,7 @@ public struct HTTPField: Sendable, Hashable {
///
/// - Parameter value: The byte collection to validate.
/// - Returns: Whether the byte collection is valid.
@inlinable
public static func isValidValue(_ value: some Collection<UInt8>) -> Bool {
Self.Value.isValid(value)
}
@@ -196,11 +212,13 @@ extension HTTPField: Codable {
@available(HTTPTypes 1.0, *)
extension HTTPField {
private enum TokenValidity {
@usableFromInline
enum TokenValidity {
case invalid
case valid
case canonical
@inlinable
var isValid: Bool {
switch self {
case .valid, .canonical:
@@ -211,18 +229,22 @@ extension HTTPField {
}
}
private static var digits: ClosedRange<UInt8> {
@inlinable
static var digits: ClosedRange<UInt8> {
UInt8(ascii: "0")...UInt8(ascii: "9")
}
private static var lowerCaseLetters: ClosedRange<UInt8> {
@inlinable
static var lowerCaseLetters: ClosedRange<UInt8> {
UInt8(ascii: "a")...UInt8(ascii: "z")
}
private static var upperCaseLetters: ClosedRange<UInt8> {
@inlinable
static var upperCaseLetters: ClosedRange<UInt8> {
UInt8(ascii: "A")...UInt8(ascii: "Z")
}
@inlinable
static func validatedCanonicalName(_ name: String) -> String? {
switch Self.tokenValidity(name) {
case .canonical:
@@ -234,20 +256,24 @@ extension HTTPField {
}
}
@inlinable
static func isValidToken(_ token: String) -> Bool {
Self.tokenValidity(token).isValid
}
@inlinable
static func isValidToken(_ token: Substring) -> Bool {
Self.tokenValidity(token).isValid
}
@inlinable
static func isValidToken(_ bytes: some Collection<UInt8>) -> Bool {
Self.tokenValidity(bytes).isValid
}
#if compiler(>=6.3) && !(os(watchOS) && _pointerBitWidth(_32))
private static func tokenValidity(_ token: String) -> TokenValidity {
@inlinable
static func tokenValidity(_ token: String) -> TokenValidity {
#if canImport(Darwin)
if #available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) {
return Self.tokenValidity(token.utf8.span)
@@ -258,7 +284,8 @@ extension HTTPField {
#endif
}
private static func tokenValidity(_ token: Substring) -> TokenValidity {
@inlinable
static func tokenValidity(_ token: Substring) -> TokenValidity {
#if canImport(Darwin)
if #available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) {
return Self.tokenValidity(token.utf8.span)
@@ -270,7 +297,8 @@ extension HTTPField {
}
@available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *)
private static func tokenValidity(_ buffer: borrowing Span<UInt8>) -> TokenValidity {
@inlinable
static func tokenValidity(_ buffer: borrowing Span<UInt8>) -> TokenValidity {
// Checks validity of token based on [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html#name-tokens)
if buffer.isEmpty {
return .invalid
@@ -294,12 +322,14 @@ extension HTTPField {
return validity
}
#else
private static func tokenValidity(_ token: some StringProtocol) -> TokenValidity {
@inlinable
static func tokenValidity(_ token: some StringProtocol) -> TokenValidity {
Self.tokenValidity(token.utf8)
}
#endif
private static func tokenValidity(_ bytes: some Collection<UInt8>) -> TokenValidity {
@inlinable
static func tokenValidity(_ bytes: some Collection<UInt8>) -> TokenValidity {
// Checks validity of token based on [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html#name-tokens)
if bytes.isEmpty {
return .invalid
+86 -7
View File
@@ -41,6 +41,7 @@ extension HTTPField {
///
/// - Parameter name: The name of the HTTP field. It can be accessed from the `rawName`
/// property.
@inlinable
public init?(_ name: String) {
guard let canonicalName = HTTPField.validatedCanonicalName(name) else {
return nil
@@ -73,11 +74,13 @@ extension HTTPField {
self.canonicalName = name
}
private init(rawName: String, canonicalName: String) {
@inlinable
init(rawName: String, canonicalName: String) {
self.rawName = rawName
self.canonicalName = canonicalName
}
@inlinable
var isPseudo: Bool {
self.rawName.utf8.first == UInt8(ascii: ":")
}
@@ -147,36 +150,41 @@ extension HTTPField.Name: Codable {
@available(HTTPTypes 1.0, *)
extension HTTPField.Name {
static var method: Self { .init(rawName: ":method", canonicalName: ":method") }
static var scheme: Self { .init(rawName: ":scheme", canonicalName: ":scheme") }
static var authority: Self { .init(rawName: ":authority", canonicalName: ":authority") }
static var path: Self { .init(rawName: ":path", canonicalName: ":path") }
static var `protocol`: Self { .init(rawName: ":protocol", canonicalName: ":protocol") }
static var status: Self { .init(rawName: ":status", canonicalName: ":status") }
@inlinable static var method: Self { .init(rawName: ":method", canonicalName: ":method") }
@inlinable static var scheme: Self { .init(rawName: ":scheme", canonicalName: ":scheme") }
@inlinable static var authority: Self { .init(rawName: ":authority", canonicalName: ":authority") }
@inlinable static var path: Self { .init(rawName: ":path", canonicalName: ":path") }
@inlinable static var `protocol`: Self { .init(rawName: ":protocol", canonicalName: ":protocol") }
@inlinable static var status: Self { .init(rawName: ":status", canonicalName: ":status") }
/// Accept
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var accept: Self { .init(rawName: "Accept", canonicalName: "accept") }
/// Accept-Encoding
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var acceptEncoding: Self { .init(rawName: "Accept-Encoding", canonicalName: "accept-encoding") }
/// Accept-Language
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var acceptLanguage: Self { .init(rawName: "Accept-Language", canonicalName: "accept-language") }
/// Accept-Ranges
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var acceptRanges: Self { .init(rawName: "Accept-Ranges", canonicalName: "accept-ranges") }
/// Access-Control-Allow-Credentials
///
/// https://fetch.spec.whatwg.org/
@inlinable
public static var accessControlAllowCredentials: Self {
.init(rawName: "Access-Control-Allow-Credentials", canonicalName: "access-control-allow-credentials")
}
@@ -184,6 +192,7 @@ extension HTTPField.Name {
/// Access-Control-Allow-Headers
///
/// https://fetch.spec.whatwg.org/
@inlinable
public static var accessControlAllowHeaders: Self {
.init(rawName: "Access-Control-Allow-Headers", canonicalName: "access-control-allow-headers")
}
@@ -191,6 +200,7 @@ extension HTTPField.Name {
/// Access-Control-Allow-Methods
///
/// https://fetch.spec.whatwg.org/
@inlinable
public static var accessControlAllowMethods: Self {
.init(rawName: "Access-Control-Allow-Methods", canonicalName: "access-control-allow-methods")
}
@@ -198,6 +208,7 @@ extension HTTPField.Name {
/// Access-Control-Allow-Origin
///
/// https://fetch.spec.whatwg.org/
@inlinable
public static var accessControlAllowOrigin: Self {
.init(rawName: "Access-Control-Allow-Origin", canonicalName: "access-control-allow-origin")
}
@@ -205,6 +216,7 @@ extension HTTPField.Name {
/// Access-Control-Expose-Headers
///
/// https://fetch.spec.whatwg.org/
@inlinable
public static var accessControlExposeHeaders: Self {
.init(rawName: "Access-Control-Expose-Headers", canonicalName: "access-control-expose-headers")
}
@@ -212,6 +224,7 @@ extension HTTPField.Name {
/// Access-Control-Max-Age
///
/// https://fetch.spec.whatwg.org/
@inlinable
public static var accessControlMaxAge: Self {
.init(rawName: "Access-Control-Max-Age", canonicalName: "access-control-max-age")
}
@@ -219,6 +232,7 @@ extension HTTPField.Name {
/// Access-Control-Request-Headers
///
/// https://fetch.spec.whatwg.org/
@inlinable
public static var accessControlRequestHeaders: Self {
.init(rawName: "Access-Control-Request-Headers", canonicalName: "access-control-request-headers")
}
@@ -226,6 +240,7 @@ extension HTTPField.Name {
/// Access-Control-Request-Method
///
/// https://fetch.spec.whatwg.org/
@inlinable
public static var accessControlRequestMethod: Self {
.init(rawName: "Access-Control-Request-Method", canonicalName: "access-control-request-method")
}
@@ -233,16 +248,19 @@ extension HTTPField.Name {
/// Age
///
/// https://www.rfc-editor.org/rfc/rfc9111.html
@inlinable
public static var age: Self { .init(rawName: "Age", canonicalName: "age") }
/// Allow
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var allow: Self { .init(rawName: "Allow", canonicalName: "allow") }
/// Authentication-Info
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var authenticationInfo: Self {
.init(rawName: "Authentication-Info", canonicalName: "authentication-info")
}
@@ -250,12 +268,14 @@ extension HTTPField.Name {
/// Authorization
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var authorization: Self { .init(rawName: "Authorization", canonicalName: "authorization") }
/// Available-Dictionary
///
/// https://www.rfc-editor.org/rfc/rfc9842.html
@available(HTTPTypes 1.6, *)
@inlinable
public static var availableDictionary: Self {
.init(rawName: "Available-Dictionary", canonicalName: "available-dictionary")
}
@@ -263,16 +283,19 @@ extension HTTPField.Name {
/// Cache-Control
///
/// https://www.rfc-editor.org/rfc/rfc9111.html
@inlinable
public static var cacheControl: Self { .init(rawName: "Cache-Control", canonicalName: "cache-control") }
/// Connection
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var connection: Self { .init(rawName: "Connection", canonicalName: "connection") }
/// Content-Disposition
///
/// https://www.rfc-editor.org/rfc/rfc6266.html
@inlinable
public static var contentDisposition: Self {
.init(rawName: "Content-Disposition", canonicalName: "content-disposition")
}
@@ -280,31 +303,37 @@ extension HTTPField.Name {
/// Content-Encoding
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var contentEncoding: Self { .init(rawName: "Content-Encoding", canonicalName: "content-encoding") }
/// Content-Language
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var contentLanguage: Self { .init(rawName: "Content-Language", canonicalName: "content-language") }
/// Content-Length
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var contentLength: Self { .init(rawName: "Content-Length", canonicalName: "content-length") }
/// Content-Location
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var contentLocation: Self { .init(rawName: "Content-Location", canonicalName: "content-location") }
/// Content-Range
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var contentRange: Self { .init(rawName: "Content-Range", canonicalName: "content-range") }
/// Content-Security-Policy
///
/// https://www.w3.org/TR/CSP/
@inlinable
public static var contentSecurityPolicy: Self {
.init(rawName: "Content-Security-Policy", canonicalName: "content-security-policy")
}
@@ -312,6 +341,7 @@ extension HTTPField.Name {
/// Content-Security-Policy-Report-Only
///
/// https://www.w3.org/TR/CSP/
@inlinable
public static var contentSecurityPolicyReportOnly: Self {
.init(rawName: "Content-Security-Policy-Report-Only", canonicalName: "content-security-policy-report-only")
}
@@ -319,16 +349,19 @@ extension HTTPField.Name {
/// Content-Type
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var contentType: Self { .init(rawName: "Content-Type", canonicalName: "content-type") }
/// Cookie
///
/// https://www.rfc-editor.org/rfc/rfc6265.html
@inlinable
public static var cookie: Self { .init(rawName: "Cookie", canonicalName: "cookie") }
/// Cross-Origin-Resource-Policy
///
/// https://fetch.spec.whatwg.org/
@inlinable
public static var crossOriginResourcePolicy: Self {
.init(rawName: "Cross-Origin-Resource-Policy", canonicalName: "cross-origin-resource-policy")
}
@@ -336,68 +369,81 @@ extension HTTPField.Name {
/// Date
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var date: Self { .init(rawName: "Date", canonicalName: "date") }
/// Dictionary-ID
///
/// https://www.rfc-editor.org/rfc/rfc9842.html
@available(HTTPTypes 1.6, *)
@inlinable
public static var dictionaryID: Self { .init(rawName: "Dictionary-ID", canonicalName: "dictionary-id") }
/// Early-Data
///
/// https://www.rfc-editor.org/rfc/rfc8470.html
@inlinable
public static var earlyData: Self { .init(rawName: "Early-Data", canonicalName: "early-data") }
/// ETag
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var eTag: Self { .init(rawName: "ETag", canonicalName: "etag") }
/// Expect
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var expect: Self { .init(rawName: "Expect", canonicalName: "expect") }
/// Expires
///
/// https://www.rfc-editor.org/rfc/rfc9111.html
@inlinable
public static var expires: Self { .init(rawName: "Expires", canonicalName: "expires") }
/// From
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var from: Self { .init(rawName: "From", canonicalName: "from") }
/// Host
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@available(*, unavailable, message: "Use HTTPRequest.authority instead")
@inlinable
public static var host: Self { .init(rawName: "Host", canonicalName: "host") }
/// If-Match
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var ifMatch: Self { .init(rawName: "If-Match", canonicalName: "if-match") }
/// If-Modified-Since
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var ifModifiedSince: Self { .init(rawName: "If-Modified-Since", canonicalName: "if-modified-since") }
/// If-None-Match
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var ifNoneMatch: Self { .init(rawName: "If-None-Match", canonicalName: "if-none-match") }
/// If-Range
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var ifRange: Self { .init(rawName: "If-Range", canonicalName: "if-range") }
/// If-Unmodified-Since
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var ifUnmodifiedSince: Self {
.init(rawName: "If-Unmodified-Since", canonicalName: "if-unmodified-since")
}
@@ -405,31 +451,37 @@ extension HTTPField.Name {
/// Last-Modified
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var lastModified: Self { .init(rawName: "Last-Modified", canonicalName: "last-modified") }
/// Location
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var location: Self { .init(rawName: "Location", canonicalName: "location") }
/// Max-Forwards
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var maxForwards: Self { .init(rawName: "Max-Forwards", canonicalName: "max-forwards") }
/// Origin
///
/// https://www.rfc-editor.org/rfc/rfc6454.html
@inlinable
public static var origin: Self { .init(rawName: "Origin", canonicalName: "origin") }
/// Priority
///
/// https://www.rfc-editor.org/rfc/rfc9218.html
@inlinable
public static var priority: Self { .init(rawName: "Priority", canonicalName: "priority") }
/// Proxy-Authenticate
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var proxyAuthenticate: Self {
.init(rawName: "Proxy-Authenticate", canonicalName: "proxy-authenticate")
}
@@ -437,6 +489,7 @@ extension HTTPField.Name {
/// Proxy-Authentication-Info
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var proxyAuthenticationInfo: Self {
.init(rawName: "Proxy-Authentication-Info", canonicalName: "proxy-authentication-info")
}
@@ -444,6 +497,7 @@ extension HTTPField.Name {
/// Proxy-Authorization
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var proxyAuthorization: Self {
.init(rawName: "Proxy-Authorization", canonicalName: "proxy-authorization")
}
@@ -452,31 +506,37 @@ extension HTTPField.Name {
///
/// https://www.rfc-editor.org/rfc/rfc9209.html
@available(HTTPTypes 1.3, *)
@inlinable
public static var proxyStatus: Self { .init(rawName: "Proxy-Status", canonicalName: "proxy-status") }
/// Range
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var range: Self { .init(rawName: "Range", canonicalName: "range") }
/// Referer
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var referer: Self { .init(rawName: "Referer", canonicalName: "referer") }
/// Retry-After
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var retryAfter: Self { .init(rawName: "Retry-After", canonicalName: "retry-after") }
/// Sec-Purpose
///
/// https://fetch.spec.whatwg.org/
@inlinable
public static var secPurpose: Self { .init(rawName: "Sec-Purpose", canonicalName: "sec-purpose") }
/// Sec-WebSocket-Accept
///
/// https://www.rfc-editor.org/rfc/rfc6455.html
@inlinable
public static var secWebSocketAccept: Self {
.init(rawName: "Sec-WebSocket-Accept", canonicalName: "sec-websocket-accept")
}
@@ -484,6 +544,7 @@ extension HTTPField.Name {
/// Sec-WebSocket-Extensions
///
/// https://www.rfc-editor.org/rfc/rfc6455.html
@inlinable
public static var secWebSocketExtensions: Self {
.init(rawName: "Sec-WebSocket-Extensions", canonicalName: "sec-websocket-extensions")
}
@@ -491,11 +552,13 @@ extension HTTPField.Name {
/// Sec-WebSocket-Key
///
/// https://www.rfc-editor.org/rfc/rfc6455.html
@inlinable
public static var secWebSocketKey: Self { .init(rawName: "Sec-WebSocket-Key", canonicalName: "sec-websocket-key") }
/// Sec-WebSocket-Protocol
///
/// https://www.rfc-editor.org/rfc/rfc6455.html
@inlinable
public static var secWebSocketProtocol: Self {
.init(rawName: "Sec-WebSocket-Protocol", canonicalName: "sec-websocket-protocol")
}
@@ -503,6 +566,7 @@ extension HTTPField.Name {
/// Sec-WebSocket-Version
///
/// https://www.rfc-editor.org/rfc/rfc6455.html
@inlinable
public static var secWebSocketVersion: Self {
.init(rawName: "Sec-WebSocket-Version", canonicalName: "sec-websocket-version")
}
@@ -510,16 +574,19 @@ extension HTTPField.Name {
/// Server
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var server: Self { .init(rawName: "Server", canonicalName: "server") }
/// Set-Cookie
///
/// https://www.rfc-editor.org/rfc/rfc6265.html
@inlinable
public static var setCookie: Self { .init(rawName: "Set-Cookie", canonicalName: "set-cookie") }
/// Strict-Transport-Security
///
/// https://www.rfc-editor.org/rfc/rfc6797.html
@inlinable
public static var strictTransportSecurity: Self {
.init(rawName: "Strict-Transport-Security", canonicalName: "strict-transport-security")
}
@@ -527,64 +594,76 @@ extension HTTPField.Name {
/// TE
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var te: Self { .init(rawName: "TE", canonicalName: "te") }
/// Traceparent
///
/// https://www.w3.org/TR/trace-context/
@available(HTTPTypes 1.6, *)
@inlinable
public static var traceparent: Self { .init(rawName: "Traceparent", canonicalName: "traceparent") }
/// Tracestate
///
/// https://www.w3.org/TR/trace-context/
@available(HTTPTypes 1.6, *)
@inlinable
public static var tracestate: Self { .init(rawName: "Tracestate", canonicalName: "tracestate") }
/// Trailer
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var trailer: Self { .init(rawName: "Trailer", canonicalName: "trailer") }
/// Transfer-Encoding
///
/// https://www.rfc-editor.org/rfc/rfc9112.html
@inlinable
public static var transferEncoding: Self { .init(rawName: "Transfer-Encoding", canonicalName: "transfer-encoding") }
/// Upgrade
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var upgrade: Self { .init(rawName: "Upgrade", canonicalName: "upgrade") }
/// Use-As-Dictionary
///
/// https://www.rfc-editor.org/rfc/rfc9842.html
@available(HTTPTypes 1.6, *)
@inlinable
public static var useAsDictionary: Self { .init(rawName: "Use-As-Dictionary", canonicalName: "use-as-dictionary") }
/// User-Agent
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var userAgent: Self { .init(rawName: "User-Agent", canonicalName: "user-agent") }
/// Vary
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var vary: Self { .init(rawName: "Vary", canonicalName: "vary") }
/// Via
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var via: Self { .init(rawName: "Via", canonicalName: "via") }
/// WWW-Authenticate
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var wwwAuthenticate: Self { .init(rawName: "WWW-Authenticate", canonicalName: "www-authenticate") }
/// X-Content-Type-Options
///
/// https://fetch.spec.whatwg.org/
@inlinable
public static var xContentTypeOptions: Self {
.init(rawName: "X-Content-Type-Options", canonicalName: "x-content-type-options")
}
+48 -21
View File
@@ -13,18 +13,23 @@
//===----------------------------------------------------------------------===//
extension HTTPField {
@usableFromInline
struct Value: Sendable {
fileprivate enum Storage: Equatable {
@usableFromInline
enum Storage: Equatable, Sendable {
case string(String)
case bytes([UInt8])
}
private let _storage: Storage
@usableFromInline
let _storage: Storage
@inlinable
init(unchecked: String) {
self._storage = .string(unchecked)
}
@inlinable
var string: String {
switch self._storage {
case .string(let string):
@@ -34,6 +39,7 @@ extension HTTPField {
}
}
@inlinable
func withUnsafeBytes<Return, Failure: Error>(
_ body: (UnsafeBufferPointer<UInt8>) throws(Failure) -> Return
) throws(Failure) -> Return {
@@ -57,6 +63,7 @@ extension HTTPField {
extension HTTPField.Value: Hashable {
@inlinable
static func == (lhs: Self, rhs: Self) -> Bool {
switch (lhs._storage, rhs._storage) {
case (.string(let lhs), .string(let rhs)):
@@ -72,6 +79,7 @@ extension HTTPField.Value: Hashable {
}
}
@inlinable
func hash(into hasher: inout Hasher) {
self.withUnsafeBytes { buffer in
for byte in buffer {
@@ -84,6 +92,7 @@ extension HTTPField.Value: Hashable {
extension HTTPField.Value {
@inlinable
init(legalize value: String) {
if Self.isValid(value) {
self._storage = .string(value)
@@ -104,6 +113,7 @@ extension HTTPField.Value {
}
}
@inlinable
init(legalize bytes: some Collection<UInt8>) {
if Self.isValid(bytes) {
self._storage = .init(from: bytes)
@@ -112,6 +122,7 @@ extension HTTPField.Value {
}
}
@inlinable
init(lenient bytes: some Collection<UInt8>) {
if Self.isLenient(bytes) {
self._storage = .init(from: bytes)
@@ -124,26 +135,30 @@ extension HTTPField.Value {
extension HTTPField.Value {
#if compiler(>=6.2) && !(os(watchOS) && _pointerBitWidth(_32))
@inlinable
static func isValid(_ string: String) -> Bool {
#if canImport(Darwin)
if #available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) {
return isLegal(string.utf8.span)
return Self.isLegal(string.utf8.span)
}
return isLegal(string.utf8)
return Self.isLegal(string.utf8)
#else
return isLegal(string.utf8.span)
return Self.isLegal(string.utf8.span)
#endif
}
#else
@inlinable
static func isValid(_ string: String) -> Bool {
isLegal(string.utf8)
Self.isLegal(string.utf8)
}
#endif
@inlinable
static func isValid(_ bytes: some Collection<UInt8>) -> Bool {
isLegal(bytes)
Self.isLegal(bytes)
}
@inlinable
var isValidToken: Bool {
switch self._storage {
case .string(let string):
@@ -180,17 +195,18 @@ extension HTTPField.Value: Codable {
#endif
extension HTTPField.Value {
fileprivate static func isLegal(_ bytes: some Sequence<UInt8>) -> Bool {
@inlinable
static func isLegal(_ bytes: some Sequence<UInt8>) -> Bool {
#if compiler(>=6.2)
#if canImport(Darwin)
if #available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) {
let optimized = bytes.withContiguousStorageIfAvailable { isLegal($0.span) }
let optimized = bytes.withContiguousStorageIfAvailable { Self.isLegal($0.span) }
if let optimized {
return optimized
}
}
#else
let optimized = bytes.withContiguousStorageIfAvailable { isLegal($0.span) }
let optimized = bytes.withContiguousStorageIfAvailable { Self.isLegal($0.span) }
if let optimized {
return optimized
}
@@ -232,7 +248,8 @@ extension HTTPField.Value {
#if compiler(>=6.2)
@available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *)
fileprivate static func isLegal(_ bytes: borrowing Span<UInt8>) -> Bool {
@inlinable
static func isLegal(_ bytes: borrowing Span<UInt8>) -> Bool {
for index in bytes.indices {
switch bytes[index] {
case 0x09, 0x20:
@@ -252,11 +269,12 @@ extension HTTPField.Value {
}
#endif
fileprivate static func isLenient(_ bytes: some Sequence<UInt8>) -> Bool {
@inlinable
static func isLenient(_ bytes: some Sequence<UInt8>) -> Bool {
#if compiler(>=6.2)
#if canImport(Darwin)
if #available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) {
let optimized = bytes.withContiguousStorageIfAvailable { isLenient($0.span) }
let optimized = bytes.withContiguousStorageIfAvailable { Self.isLenient($0.span) }
if let optimized {
return optimized
}
@@ -274,7 +292,8 @@ extension HTTPField.Value {
#if compiler(>=6.2)
@available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *)
fileprivate static func isLenient(_ bytes: Span<UInt8>) -> Bool {
@inlinable
static func isLenient(_ bytes: Span<UInt8>) -> Bool {
for index in bytes.indices {
switch bytes[index] {
case 0x00, 0x0A, 0x0D:
@@ -289,7 +308,8 @@ extension HTTPField.Value {
}
extension HTTPField.Value {
private static func legalize(from bytes: some Collection<UInt8>) -> Storage {
@inlinable
static func legalize(from bytes: some Collection<UInt8>) -> Storage {
#if compiler(>=6.2)
#if canImport(Darwin)
if #available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) {
@@ -338,7 +358,8 @@ extension HTTPField.Value {
#if compiler(>=6.2)
@available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *)
private static func legalize(from bytes: Span<UInt8>) -> Storage {
@inlinable
static func legalize(from bytes: Span<UInt8>) -> Storage {
withUnsafeTemporaryAllocation(of: UInt8.self, capacity: bytes.count) { buffer in
var index = 0
var lastValidIndex = 0
@@ -371,11 +392,12 @@ extension HTTPField.Value {
}
#endif
private static func cleanUpAsLenient(from bytes: some Collection<UInt8>) -> Storage {
@inlinable
static func cleanUpAsLenient(from bytes: some Collection<UInt8>) -> Storage {
#if compiler(>=6.2)
#if canImport(Darwin)
if #available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) {
let optimized = bytes.withContiguousStorageIfAvailable { cleanUpAsLenient(from: $0.span) }
let optimized = bytes.withContiguousStorageIfAvailable { Self.cleanUpAsLenient(from: $0.span) }
if let optimized {
return optimized
}
@@ -406,7 +428,8 @@ extension HTTPField.Value {
#if compiler(>=6.2)
@available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *)
private static func cleanUpAsLenient(from bytes: Span<UInt8>) -> Storage {
@inlinable
static func cleanUpAsLenient(from bytes: Span<UInt8>) -> Storage {
withUnsafeTemporaryAllocation(of: UInt8.self, capacity: bytes.count) { buffer in
for index in bytes.indices {
let byte = bytes[index]
@@ -425,6 +448,7 @@ extension HTTPField.Value {
}
extension HTTPField.Value.Storage {
@inlinable
init(from bytes: some Sequence<UInt8>) {
#if canImport(Darwin)
if #available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) {
@@ -444,12 +468,14 @@ extension HTTPField.Value.Storage {
}
extension Sequence where Element == UInt8 {
fileprivate var isASCII: Bool {
@inlinable
var isASCII: Bool {
allSatisfy { $0 & 0x80 == 0 }
}
}
extension HTTPField.Value {
@inlinable
var isoLatin1: String {
switch self._storage {
case .string(let string):
@@ -481,7 +507,8 @@ extension HTTPField.Value {
self._storage = .init(from: bytes)
}
private static func transcodeToISOLatin1SlowPath(from bytes: some Collection<UInt8>) -> String {
@inlinable
static func transcodeToISOLatin1SlowPath(from bytes: some Collection<UInt8>) -> String {
let scalars = bytes.lazy.map { UnicodeScalar(UInt32($0))! }
var string = ""
string.unicodeScalars.append(contentsOf: scalars)
+69 -38
View File
@@ -23,21 +23,25 @@
@available(HTTPTypes 1.0, *)
public struct HTTPFields: Sendable {
/// The fields, in the order they were added.
private var fields: [HTTPField] = []
@usableFromInline
var _fields: [HTTPField] = []
/// Create an empty list of HTTP fields
@inlinable
public init() {}
/// The position of the first field at or after `start` whose canonical name is `name`, or
/// `nil` if there is none.
private func firstIndex(ofCanonicalName name: String, from start: [HTTPField].Index = 0) -> Int? {
self.fields[start...].firstIndex(where: { $0.name.canonicalName == name })
@inlinable
func firstIndex(ofCanonicalName name: String, from start: [HTTPField].Index = 0) -> Int? {
self._fields[start...].firstIndex(where: { $0.name.canonicalName == name })
}
private mutating func append(field: HTTPField) {
@inlinable
mutating func append(field: HTTPField) {
precondition(!field.name.isPseudo, "Pseudo header field \"\(field.name)\" disallowed")
self.fields.append(field)
precondition(self.fields.count < UInt16.max, "Too many fields")
self._fields.append(field)
precondition(self._fields.count < UInt16.max, "Too many fields")
}
/// Access the field value string by name.
@@ -56,6 +60,7 @@ public struct HTTPFields: Sendable {
///
/// When setting a "Cookie" header field value, it is split into multiple "Cookie" fields by
/// semicolon.
@inlinable
public subscript(name: HTTPField.Name) -> String? {
get {
let fields = self.fields(for: name)
@@ -89,6 +94,7 @@ public struct HTTPFields: Sendable {
}
/// Access the field values by name as an array of strings. The order of fields is preserved.
@inlinable
public subscript(values name: HTTPField.Name) -> [String] {
get {
self.fields(for: name).map { $0.value }
@@ -99,6 +105,7 @@ public struct HTTPFields: Sendable {
}
/// Access the fields by name as an array. The order of fields is preserved.
@inlinable
public subscript(fields name: HTTPField.Name) -> [HTTPField] {
get {
Array(self.fields(for: name))
@@ -108,23 +115,38 @@ public struct HTTPFields: Sendable {
}
}
private struct HTTPFieldSequence: Sequence {
@usableFromInline
struct HTTPFieldSequence: Sequence {
@usableFromInline
let fields: HTTPFields
@usableFromInline
let name: HTTPField.Name
@inlinable
init(fields: HTTPFields, name: HTTPField.Name) {
self.fields = fields
self.name = name
}
@usableFromInline
struct Iterator: IteratorProtocol {
@usableFromInline
let fields: HTTPFields
@usableFromInline
let name: HTTPField.Name
/// The position to resume scanning at. Keeping it in the iterator makes reading all
/// the fields with one name a single pass over `fields`.
@usableFromInline
var index: Int
@inlinable
init(fields: HTTPFields, name: HTTPField.Name) {
self.fields = fields
self.name = name
self.index = fields.startIndex
}
@inlinable
mutating func next() -> HTTPField? {
if let index = self.fields.firstIndex(ofCanonicalName: self.name.canonicalName, from: self.index) {
defer { self.index = self.fields.index(after: index) }
@@ -134,16 +156,19 @@ public struct HTTPFields: Sendable {
}
}
@inlinable
func makeIterator() -> Iterator {
Iterator(fields: self.fields, name: self.name)
}
}
private func fields(for name: HTTPField.Name) -> HTTPFieldSequence {
@inlinable
func fields(for name: HTTPField.Name) -> HTTPFieldSequence {
HTTPFieldSequence(fields: self, name: name)
}
private mutating func setFields(_ fieldSequence: some Sequence<HTTPField>, for name: HTTPField.Name) {
@inlinable
mutating func setFields(_ fieldSequence: some Sequence<HTTPField>, for name: HTTPField.Name) {
let canonicalName = name.canonicalName
var existingIndex = self.firstIndex(ofCanonicalName: canonicalName)
var newFieldIterator = fieldSequence.makeIterator()
@@ -152,14 +177,14 @@ public struct HTTPFields: Sendable {
// place while new fields last, and the leftovers are collected for removal.
while let index = existingIndex {
if let field = newFieldIterator.next() {
self.fields[index] = field
self._fields[index] = field
} else {
toDelete.append(index)
}
existingIndex = self.firstIndex(ofCanonicalName: canonicalName, from: index + 1)
}
if !toDelete.isEmpty {
self.fields.remove(at: toDelete)
self._fields.remove(at: toDelete)
}
while let field = newFieldIterator.next() {
self.append(field: field)
@@ -169,6 +194,7 @@ public struct HTTPFields: Sendable {
/// Whether one or more field with this name exists in the fields.
/// - Parameter name: The field name.
/// - Returns: Whether a field exists.
@inlinable
public func contains(_ name: HTTPField.Name) -> Bool {
self.firstIndex(ofCanonicalName: name.canonicalName) != nil
}
@@ -190,7 +216,7 @@ extension HTTPFields: Equatable {
// 2. An approach in which we build a dictionary from one field list and then remove items
// from it based on the other one. This scales linear but has significant build costs,
// since it needs to hash every field name twice.
if lhs.fields.count != rhs.fields.count {
if lhs._fields.count != rhs._fields.count {
return false
}
@@ -200,13 +226,13 @@ extension HTTPFields: Equatable {
// the same order. After each iteration both arrays have the same length.
var pendingLeft = [Int]()
var pendingRight = [Int]()
for index in lhs.fields.indices {
for index in lhs._fields.indices {
// A direct element comparison can only be done if there are no elements in the pending
// arrays. This is to ensure correct ordering. Unpaired elements must be considered
// before the current element.
if pendingLeft.isEmpty {
if lhs.fields[index].name == rhs.fields[index].name {
if lhs.fields[index].value == rhs.fields[index].value {
if lhs._fields[index].name == rhs._fields[index].name {
if lhs._fields[index].value == rhs._fields[index].value {
continue
} else {
// Same name, different value, and no earlier candidate for either of them.
@@ -214,25 +240,25 @@ extension HTTPFields: Equatable {
}
} else {
// Disorder starts here
let remaining = lhs.fields.count - index
let remaining = lhs._fields.count - index
pendingLeft.reserveCapacity(remaining)
pendingRight.reserveCapacity(remaining)
}
}
let leftName = lhs.fields[index].name
if let match = pendingRight.firstIndex(where: { rhs.fields[$0].name == leftName }) {
let leftName = lhs._fields[index].name
if let match = pendingRight.firstIndex(where: { rhs._fields[$0].name == leftName }) {
// The n-th field of a name pairs only with the other side's n-th field.
if rhs.fields[pendingRight[match]] != lhs.fields[index] {
if rhs._fields[pendingRight[match]] != lhs._fields[index] {
return false
}
pendingRight.remove(at: match)
} else {
pendingLeft.append(index)
}
let rightName = rhs.fields[index].name
if let match = pendingLeft.firstIndex(where: { lhs.fields[$0].name == rightName }) {
if lhs.fields[pendingLeft[match]] != rhs.fields[index] {
let rightName = rhs._fields[index].name
if let match = pendingLeft.firstIndex(where: { lhs._fields[$0].name == rightName }) {
if lhs._fields[pendingLeft[match]] != rhs._fields[index] {
return false
}
pendingLeft.remove(at: match)
@@ -241,7 +267,7 @@ extension HTTPFields: Equatable {
}
if pendingLeft.count >= Self.maxPendingFieldsBeforeIndexing,
lhs.fields.count - index >= Self.minFieldsToIndexByName
lhs._fields.count - index >= Self.minFieldsToIndexByName
{
return Self.isEqualByNameIndex(lhs, rhs)
}
@@ -264,7 +290,7 @@ extension HTTPFields: Equatable {
/// index while walking `lhs`.
@_spi(HTTPTypesBenchmarking)
public static func isEqualByNameIndex(_ lhs: HTTPFields, _ rhs: HTTPFields) -> Bool {
if lhs.fields.count != rhs.fields.count {
if lhs._fields.count != rhs._fields.count {
return false
}
// The fields of `rhs`, grouped by name. Fields sharing a name have to appear in the same
@@ -272,11 +298,11 @@ extension HTTPFields: Equatable {
// another way to create a FIFO structure: By adding the fields to the dictionary in reverse
// order, we'll add later values first to the values array. This allows us, when iterating
// the lhs fields, to remove values from the end of the values array.
var remaining = [String: [HTTPField]](minimumCapacity: lhs.fields.count)
for field in rhs.fields.reversed() {
var remaining = [String: [HTTPField]](minimumCapacity: lhs._fields.count)
for field in rhs._fields.reversed() {
remaining[field.name.canonicalName, default: []].append(field)
}
for field in lhs.fields {
for field in lhs._fields {
guard let group = remaining.index(forKey: field.name.canonicalName),
let candidate = remaining.values[group].last
else {
@@ -293,7 +319,7 @@ extension HTTPFields: Equatable {
extension HTTPFields: Hashable {
public func hash(into hasher: inout Hasher) {
for field in self.fields {
for field in self._fields {
hasher.combine(field)
}
}
@@ -316,36 +342,40 @@ extension HTTPFields: RangeReplaceableCollection, RandomAccessCollection, Mutabl
public typealias Element = HTTPField
public typealias Index = Int
@inlinable
public var startIndex: Int {
self.fields.startIndex
self._fields.startIndex
}
@inlinable
public var endIndex: Int {
self.fields.endIndex
self._fields.endIndex
}
@inlinable
public var isEmpty: Bool {
self.fields.isEmpty
self._fields.isEmpty
}
@inlinable
public subscript(position: Int) -> HTTPField {
get {
guard position >= self.startIndex, position < self.endIndex else {
preconditionFailure("getter position: \(position) out of range in HTTPFields")
}
return self.fields[position]
return self._fields[position]
}
set {
guard position >= self.startIndex, position < self.endIndex else {
preconditionFailure("setter position: \(position) out of range in HTTPFields")
}
if self.fields[position] == newValue {
if self._fields[position] == newValue {
return
}
if newValue.name != self.fields[position].name {
if newValue.name != self._fields[position].name {
precondition(!newValue.name.isPseudo, "Pseudo header field \"\(newValue.name)\" disallowed")
}
self.fields[position] = newValue
self._fields[position] = newValue
}
}
@@ -357,7 +387,7 @@ extension HTTPFields: RangeReplaceableCollection, RandomAccessCollection, Mutabl
self.append(field: field)
}
} else {
self.fields.replaceSubrange(
self._fields.replaceSubrange(
subrange,
with: newElements.lazy.map { field in
precondition(!field.name.isPseudo, "Pseudo header field \"\(field.name)\" disallowed")
@@ -369,7 +399,7 @@ extension HTTPFields: RangeReplaceableCollection, RandomAccessCollection, Mutabl
}
public mutating func reserveCapacity(_ capacity: Int) {
self.fields.reserveCapacity(capacity)
self._fields.reserveCapacity(capacity)
}
}
@@ -378,7 +408,7 @@ extension HTTPFields: RangeReplaceableCollection, RandomAccessCollection, Mutabl
@available(HTTPTypes 1.0, *)
extension HTTPFields: CustomDebugStringConvertible {
public var debugDescription: String {
self.fields.description
self._fields.description
}
}
@@ -411,6 +441,7 @@ extension HTTPFields: Codable {
extension Array {
// `removalIndices` must be ordered.
@inlinable
mutating func remove(at removalIndices: some Sequence<Index>) {
var offset = 0
var iterator = removalIndices.makeIterator()
+15 -1
View File
@@ -33,6 +33,7 @@ public struct HTTPRequest: Sendable, Hashable {
/// https://www.rfc-editor.org/rfc/rfc9110.html#name-methods
///
/// - Parameter method: The method string. It can be accessed from the `rawValue` property.
@inlinable
public init?(_ method: String) {
guard HTTPField.isValidToken(method) else {
return nil
@@ -40,14 +41,17 @@ public struct HTTPRequest: Sendable, Hashable {
self.rawValue = method
}
@inlinable
public init?(rawValue: String) {
self.init(rawValue)
}
fileprivate init(unchecked: String) {
@inlinable
init(unchecked: String) {
self.rawValue = unchecked
}
@inlinable
public var description: String {
self.rawValue
}
@@ -463,51 +467,61 @@ extension HTTPRequest.Method {
/// GET
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var get: Self { .init(unchecked: "GET") }
/// HEAD
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var head: Self { .init(unchecked: "HEAD") }
/// POST
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var post: Self { .init(unchecked: "POST") }
/// PUT
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var put: Self { .init(unchecked: "PUT") }
/// DELETE
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var delete: Self { .init(unchecked: "DELETE") }
/// CONNECT
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var connect: Self { .init(unchecked: "CONNECT") }
/// OPTIONS
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var options: Self { .init(unchecked: "OPTIONS") }
/// TRACE
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var trace: Self { .init(unchecked: "TRACE") }
/// PATCH
///
/// https://www.rfc-editor.org/rfc/rfc5789.html
@inlinable
public static var patch: Self { .init(unchecked: "PATCH") }
/// QUERY
///
/// https://www.rfc-editor.org/rfc/rfc10008.html
@available(HTTPTypes 1.7, *)
@inlinable
public static var query: Self { .init(unchecked: "QUERY") }
/// CONNECT-UDP
+51 -1
View File
@@ -39,7 +39,8 @@ public struct HTTPResponse: Sendable, Hashable {
self.reasonPhrase = Self.legalizingReasonPhrase(reasonPhrase)
}
fileprivate init(uncheckedCode: Int, reasonPhrase: String) {
@inlinable
init(uncheckedCode: Int, reasonPhrase: String) {
self.code = uncheckedCode
self.reasonPhrase = reasonPhrase
}
@@ -353,16 +354,19 @@ extension HTTPResponse.Status {
/// 100 Continue
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var `continue`: Self { .init(uncheckedCode: 100, reasonPhrase: "Continue") }
/// 101 Switching Protocols
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var switchingProtocols: Self { .init(uncheckedCode: 101, reasonPhrase: "Switching Protocols") }
/// 103 Early Hints
///
/// https://www.rfc-editor.org/rfc/rfc8297.html
@inlinable
public static var earlyHints: Self { .init(uncheckedCode: 103, reasonPhrase: "Early Hints") }
// MARK: 2xx
@@ -370,21 +374,25 @@ extension HTTPResponse.Status {
/// 200 OK
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var ok: Self { .init(uncheckedCode: 200, reasonPhrase: "OK") }
/// 201 Created
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var created: Self { .init(uncheckedCode: 201, reasonPhrase: "Created") }
/// 202 Accepted
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var accepted: Self { .init(uncheckedCode: 202, reasonPhrase: "Accepted") }
/// 203 Non-Authoritative Information
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var nonAuthoritativeInformation: Self {
.init(uncheckedCode: 203, reasonPhrase: "Non-Authoritative Information")
}
@@ -392,16 +400,19 @@ extension HTTPResponse.Status {
/// 204 No Content
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var noContent: Self { .init(uncheckedCode: 204, reasonPhrase: "No Content") }
/// 205 Reset Content
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var resetContent: Self { .init(uncheckedCode: 205, reasonPhrase: "Reset Content") }
/// 206 Partial Content
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var partialContent: Self { .init(uncheckedCode: 206, reasonPhrase: "Partial Content") }
// MARK: 3xx
@@ -409,36 +420,43 @@ extension HTTPResponse.Status {
/// 300 Multiple Choices
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var multipleChoices: Self { .init(uncheckedCode: 300, reasonPhrase: "Multiple Choices") }
/// 301 Moved Permanently
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var movedPermanently: Self { .init(uncheckedCode: 301, reasonPhrase: "Moved Permanently") }
/// 302 Found
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var found: Self { .init(uncheckedCode: 302, reasonPhrase: "Found") }
/// 303 See Other
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var seeOther: Self { .init(uncheckedCode: 303, reasonPhrase: "See Other") }
/// 304 Not Modified
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var notModified: Self { .init(uncheckedCode: 304, reasonPhrase: "Not Modified") }
/// 307 Temporary Redirect
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var temporaryRedirect: Self { .init(uncheckedCode: 307, reasonPhrase: "Temporary Redirect") }
/// 308 Permanent Redirect
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var permanentRedirect: Self { .init(uncheckedCode: 308, reasonPhrase: "Permanent Redirect") }
// MARK: 4xx
@@ -446,36 +464,43 @@ extension HTTPResponse.Status {
/// 400 Bad Request
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var badRequest: Self { .init(uncheckedCode: 400, reasonPhrase: "Bad Request") }
/// 401 Unauthorized
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var unauthorized: Self { .init(uncheckedCode: 401, reasonPhrase: "Unauthorized") }
/// 403 Forbidden
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var forbidden: Self { .init(uncheckedCode: 403, reasonPhrase: "Forbidden") }
/// 404 Not Found
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var notFound: Self { .init(uncheckedCode: 404, reasonPhrase: "Not Found") }
/// 405 Method Not Allowed
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var methodNotAllowed: Self { .init(uncheckedCode: 405, reasonPhrase: "Method Not Allowed") }
/// 406 Not Acceptable
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var notAcceptable: Self { .init(uncheckedCode: 406, reasonPhrase: "Not Acceptable") }
/// 407 Proxy Authentication Required
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var proxyAuthenticationRequired: Self {
.init(uncheckedCode: 407, reasonPhrase: "Proxy Authentication Required")
}
@@ -483,84 +508,101 @@ extension HTTPResponse.Status {
/// 408 Request Timeout
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var requestTimeout: Self { .init(uncheckedCode: 408, reasonPhrase: "Request Timeout") }
/// 409 Conflict
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var conflict: Self { .init(uncheckedCode: 409, reasonPhrase: "Conflict") }
/// 410 Gone
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var gone: Self { .init(uncheckedCode: 410, reasonPhrase: "Gone") }
/// 411 Length Required
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var lengthRequired: Self { .init(uncheckedCode: 411, reasonPhrase: "Length Required") }
/// 412 Precondition Failed
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var preconditionFailed: Self { .init(uncheckedCode: 412, reasonPhrase: "Precondition Failed") }
/// 413 Content Too Large
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var contentTooLarge: Self { .init(uncheckedCode: 413, reasonPhrase: "Content Too Large") }
/// 414 URI Too Long
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var uriTooLong: Self { .init(uncheckedCode: 414, reasonPhrase: "URI Too Long") }
/// 415 Unsupported Media Type
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var unsupportedMediaType: Self { .init(uncheckedCode: 415, reasonPhrase: "Unsupported Media Type") }
/// 416 Range Not Satisfiable
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var rangeNotSatisfiable: Self { .init(uncheckedCode: 416, reasonPhrase: "Range Not Satisfiable") }
/// 417 Expectation Failed
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var expectationFailed: Self { .init(uncheckedCode: 417, reasonPhrase: "Expectation Failed") }
/// 421 Misdirected Request
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var misdirectedRequest: Self { .init(uncheckedCode: 421, reasonPhrase: "Misdirected Request") }
/// 422 Unprocessable Content
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var unprocessableContent: Self { .init(uncheckedCode: 422, reasonPhrase: "Unprocessable Content") }
/// 425 Too Early
@inlinable
public static var tooEarly: Self { .init(uncheckedCode: 425, reasonPhrase: "Too Early") }
/// 426 Upgrade Required
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var upgradeRequired: Self { .init(uncheckedCode: 426, reasonPhrase: "Upgrade Required") }
/// 428 Precondition Required
///
/// https://www.rfc-editor.org/rfc/rfc6585.html
@inlinable
public static var preconditionRequired: Self { .init(uncheckedCode: 428, reasonPhrase: "Precondition Required") }
/// 429 Too Many Requests
///
/// https://www.rfc-editor.org/rfc/rfc6585.html
@inlinable
public static var tooManyRequests: Self { .init(uncheckedCode: 429, reasonPhrase: "Too Many Requests") }
/// 431 Request Header Fields Too Large
///
/// https://www.rfc-editor.org/rfc/rfc6585.html
@inlinable
public static var requestHeaderFieldsTooLarge: Self {
.init(uncheckedCode: 431, reasonPhrase: "Request Header Fields Too Large")
}
@@ -568,6 +610,7 @@ extension HTTPResponse.Status {
/// 451 Unavailable For Legal Reasons
///
/// https://www.rfc-editor.org/rfc/rfc7725.html
@inlinable
public static var unavailableForLegalReasons: Self {
.init(uncheckedCode: 451, reasonPhrase: "Unavailable For Legal Reasons")
}
@@ -577,31 +620,37 @@ extension HTTPResponse.Status {
/// 500 Internal Server Error
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var internalServerError: Self { .init(uncheckedCode: 500, reasonPhrase: "Internal Server Error") }
/// 501 Not Implemented
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var notImplemented: Self { .init(uncheckedCode: 501, reasonPhrase: "Not Implemented") }
/// 502 Bad Gateway
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var badGateway: Self { .init(uncheckedCode: 502, reasonPhrase: "Bad Gateway") }
/// 503 Service Unavailable
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var serviceUnavailable: Self { .init(uncheckedCode: 503, reasonPhrase: "Service Unavailable") }
/// 504 Gateway Timeout
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var gatewayTimeout: Self { .init(uncheckedCode: 504, reasonPhrase: "Gateway Timeout") }
/// 505 HTTP Version Not Supported
///
/// https://www.rfc-editor.org/rfc/rfc9110.html
@inlinable
public static var httpVersionNotSupported: Self {
.init(uncheckedCode: 505, reasonPhrase: "HTTP Version Not Supported")
}
@@ -609,6 +658,7 @@ extension HTTPResponse.Status {
/// 511 Network Authentication Required
///
/// https://www.rfc-editor.org/rfc/rfc6585.html
@inlinable
public static var networkAuthenticationRequired: Self {
.init(uncheckedCode: 511, reasonPhrase: "Network Authentication Required")
}