@@ -20,28 +20,32 @@ public struct HTTPField: Sendable, Hashable {
20
20
/// The strategy for whether the field is indexed in the HPACK or QPACK dynamic table.
21
21
public struct DynamicTableIndexingStrategy : Sendable , Hashable {
22
22
/// Default strategy.
23
+ @inlinable
23
24
public static var automatic : Self { . init( uncheckedValue: 0 ) }
24
25
25
26
/// Always put this field in the dynamic table if possible.
27
+ @inlinable
26
28
public static var prefer : Self { . init( uncheckedValue: 1 ) }
27
29
28
30
/// Don't put this field in the dynamic table.
31
+ @inlinable
29
32
public static var avoid : Self { . init( uncheckedValue: 2 ) }
30
33
31
34
/// Don't put this field in the dynamic table, and set a flag to disallow intermediaries to
32
35
/// index this field.
36
+ @inlinable
33
37
public static var disallow : Self { . init( uncheckedValue: 3 ) }
34
38
35
- fileprivate let rawValue : UInt8
39
+ /* fileprivate but */ @ usableFromInline let rawValue : UInt8
36
40
37
- private static let maxRawValue : UInt8 = 3
41
+ /* private but */ @ usableFromInline static let maxRawValue : UInt8 = 3
38
42
39
- private init ( uncheckedValue: UInt8 ) {
43
+ /* private but */ @ inlinable init ( uncheckedValue: UInt8 ) {
40
44
assert ( uncheckedValue <= Self . maxRawValue)
41
45
self . rawValue = uncheckedValue
42
46
}
43
47
44
- fileprivate init ? ( rawValue: UInt8 ) {
48
+ /* fileprivate but */ @ inlinable init ? ( rawValue: UInt8 ) {
45
49
if rawValue > Self . maxRawValue {
46
50
return nil
47
51
}
@@ -54,6 +58,7 @@ public struct HTTPField: Sendable, Hashable {
54
58
/// - name: The HTTP field name.
55
59
/// - value: The HTTP field value is initialized from the UTF-8 encoded bytes of the string.
56
60
/// Invalid bytes are converted into space characters.
61
+ @inlinable
57
62
public init ( name: Name , value: String ) {
58
63
self . name = name
59
64
self . rawValue = Self . legalizeValue ( ISOLatin1String ( value) )
@@ -63,6 +68,7 @@ public struct HTTPField: Sendable, Hashable {
63
68
/// - Parameters:
64
69
/// - name: The HTTP field name.
65
70
/// - value: The HTTP field value. Invalid bytes are converted into space characters.
71
+ @inlinable
66
72
public init ( name: Name , value: some Collection < UInt8 > ) {
67
73
self . name = name
68
74
self . rawValue = Self . legalizeValue ( ISOLatin1String ( value) )
@@ -73,11 +79,13 @@ public struct HTTPField: Sendable, Hashable {
73
79
/// - name: The HTTP field name.
74
80
/// - lenientValue: The HTTP field value. Newlines and NULs are converted into space
75
81
/// characters.
82
+ @inlinable
76
83
public init ( name: Name , lenientValue: some Collection < UInt8 > ) {
77
84
self . name = name
78
85
self . rawValue = Self . lenientLegalizeValue ( ISOLatin1String ( lenientValue) )
79
86
}
80
87
88
+ @inlinable
81
89
init ( name: Name , uncheckedValue: ISOLatin1String ) {
82
90
self . name = name
83
91
self . rawValue = uncheckedValue
@@ -94,6 +102,7 @@ public struct HTTPField: Sendable, Hashable {
94
102
///
95
103
/// If the field is not UTF-8 encoded, `withUnsafeBytesOfValue` can be used to access the
96
104
/// underlying bytes of the field value.
105
+ @inlinable
97
106
public var value : String {
98
107
get {
99
108
self . rawValue. string
@@ -112,6 +121,7 @@ public struct HTTPField: Sendable, Hashable {
112
121
///
113
122
/// - Parameter body: The closure to be invoked with the buffer.
114
123
/// - Returns: Result of the `body` closure.
124
+ @inlinable
115
125
public func withUnsafeBytesOfValue< Result> (
116
126
_ body: ( UnsafeBufferPointer < UInt8 > ) throws -> Result
117
127
) rethrows -> Result {
@@ -121,9 +131,10 @@ public struct HTTPField: Sendable, Hashable {
121
131
/// The strategy for whether the field is indexed in the HPACK or QPACK dynamic table.
122
132
public var indexingStrategy : DynamicTableIndexingStrategy = . automatic
123
133
134
+ @usableFromInline
124
135
var rawValue : ISOLatin1String
125
136
126
- private static func _isValidValue( _ bytes: some Sequence < UInt8 > ) -> Bool {
137
+ /* private but */ @ inlinable static func _isValidValue( _ bytes: some Sequence < UInt8 > ) -> Bool {
127
138
var iterator = bytes. makeIterator ( )
128
139
guard var byte = iterator. next ( ) else {
129
140
// Empty string is allowed.
@@ -155,6 +166,7 @@ public struct HTTPField: Sendable, Hashable {
155
166
return true
156
167
}
157
168
169
+ @inlinable
158
170
static func legalizeValue( _ value: ISOLatin1String ) -> ISOLatin1String {
159
171
if self . _isValidValue ( value. _storage. utf8) {
160
172
return value
@@ -176,6 +188,7 @@ public struct HTTPField: Sendable, Hashable {
176
188
}
177
189
}
178
190
191
+ @inlinable
179
192
static func lenientLegalizeValue( _ value: ISOLatin1String ) -> ISOLatin1String {
180
193
if value. _storage. utf8. allSatisfy ( { $0 != 0x00 && $0 != 0x0A && $0 != 0x0D } ) {
181
194
return value
@@ -198,6 +211,7 @@ public struct HTTPField: Sendable, Hashable {
198
211
///
199
212
/// - Parameter value: The string to validate.
200
213
/// - Returns: Whether the string is valid.
214
+ @inlinable
201
215
public static func isValidValue( _ value: String ) -> Bool {
202
216
self . _isValidValue ( value. utf8)
203
217
}
@@ -208,30 +222,35 @@ public struct HTTPField: Sendable, Hashable {
208
222
///
209
223
/// - Parameter value: The byte collection to validate.
210
224
/// - Returns: Whether the byte collection is valid.
225
+ @inlinable
211
226
public static func isValidValue( _ value: some Collection < UInt8 > ) -> Bool {
212
227
self . _isValidValue ( value)
213
228
}
214
229
}
215
230
216
231
extension HTTPField : CustomStringConvertible {
232
+ @inlinable
217
233
public var description : String {
218
234
" \( self . name) : \( self . value) "
219
235
}
220
236
}
221
237
222
238
extension HTTPField : CustomPlaygroundDisplayConvertible {
239
+ @inlinable
223
240
public var playgroundDescription : Any {
224
241
self . description
225
242
}
226
243
}
227
244
228
245
extension HTTPField : Codable {
246
+ @usableFromInline
229
247
enum CodingKeys : String , CodingKey {
230
248
case name
231
249
case value
232
250
case indexingStrategy
233
251
}
234
252
253
+ @inlinable
235
254
public func encode( to encoder: Encoder ) throws {
236
255
var container = encoder. container ( keyedBy: CodingKeys . self)
237
256
try container. encode ( self . name, forKey: . name)
@@ -241,6 +260,7 @@ extension HTTPField: Codable {
241
260
}
242
261
}
243
262
263
+ @inlinable
244
264
public init ( from decoder: Decoder ) throws {
245
265
let container = try decoder. container ( keyedBy: CodingKeys . self)
246
266
let name = try container. decode ( Name . self, forKey: . name)
@@ -262,6 +282,7 @@ extension HTTPField: Codable {
262
282
}
263
283
264
284
extension HTTPField {
285
+ @inlinable
265
286
static func isValidToken( _ token: some StringProtocol ) -> Bool {
266
287
!token. isEmpty
267
288
&& token. utf8. allSatisfy {
0 commit comments