@@ -38,7 +38,7 @@ struct HTTPDecoderTests {
38
38
39
39
@Test
40
40
func GETMethod_IsParsed( ) async throws {
41
- let request = try await HTTPDecoder ( ) . decodeRequestFromString (
41
+ let request = try await HTTPDecoder . make ( ) . decodeRequestFromString (
42
42
"""
43
43
GET /hello HTTP/1.1 \r
44
44
\r
@@ -52,7 +52,7 @@ struct HTTPDecoderTests {
52
52
53
53
@Test
54
54
func POSTMethod_IsParsed( ) async throws {
55
- let request = try await HTTPDecoder ( ) . decodeRequestFromString (
55
+ let request = try await HTTPDecoder . make ( ) . decodeRequestFromString (
56
56
"""
57
57
POST /hello HTTP/1.1 \r
58
58
\r
@@ -66,7 +66,7 @@ struct HTTPDecoderTests {
66
66
67
67
@Test
68
68
func CUSTOMMethod_IsParsed( ) async throws {
69
- let request = try await HTTPDecoder ( ) . decodeRequestFromString (
69
+ let request = try await HTTPDecoder . make ( ) . decodeRequestFromString (
70
70
"""
71
71
FISH /hello HTTP/1.1 \r
72
72
\r
@@ -80,7 +80,7 @@ struct HTTPDecoderTests {
80
80
81
81
@Test
82
82
func path_IsParsed( ) async throws {
83
- let request = try await HTTPDecoder ( ) . decodeRequestFromString (
83
+ let request = try await HTTPDecoder . make ( ) . decodeRequestFromString (
84
84
"""
85
85
GET /hello/world?fish=Chips&with=Mushy%20Peas HTTP/1.1 \r
86
86
\r
@@ -101,7 +101,7 @@ struct HTTPDecoderTests {
101
101
102
102
@Test
103
103
func naughtyPath_IsParsed( ) async throws {
104
- let request = try await HTTPDecoder ( ) . decodeRequestFromString (
104
+ let request = try await HTTPDecoder . make ( ) . decodeRequestFromString (
105
105
"""
106
106
GET /../a/b/../c/./d.html?fish=Chips&with=Mushy%20Peas HTTP/1.1 \r
107
107
\r
@@ -128,7 +128,7 @@ struct HTTPDecoderTests {
128
128
129
129
@Test
130
130
func headers_AreParsed( ) async throws {
131
- let request = try await HTTPDecoder ( ) . decodeRequestFromString (
131
+ let request = try await HTTPDecoder . make ( ) . decodeRequestFromString (
132
132
"""
133
133
GET /hello HTTP/1.1 \r
134
134
Fish: Chips \r
@@ -149,7 +149,7 @@ struct HTTPDecoderTests {
149
149
150
150
@Test
151
151
func body_IsNotParsed_WhenContentLength_IsNotProvided( ) async throws {
152
- let request = try await HTTPDecoder ( ) . decodeRequestFromString (
152
+ let request = try await HTTPDecoder . make ( ) . decodeRequestFromString (
153
153
"""
154
154
GET /hello HTTP/1.1 \r
155
155
\r
@@ -164,7 +164,7 @@ struct HTTPDecoderTests {
164
164
165
165
@Test
166
166
func body_IsParsed_WhenContentLength_IsProvided( ) async throws {
167
- let request = try await HTTPDecoder ( ) . decodeRequestFromString (
167
+ let request = try await HTTPDecoder . make ( ) . decodeRequestFromString (
168
168
"""
169
169
GET /hello HTTP/1.1 \r
170
170
Content-Length: 5 \r
@@ -181,7 +181,7 @@ struct HTTPDecoderTests {
181
181
@Test
182
182
func invalidStatusLine_ThrowsError( ) async {
183
183
await #expect( throws: HTTPDecoder . Error. self) {
184
- try await HTTPDecoder ( ) . decodeRequestFromString (
184
+ try await HTTPDecoder . make ( ) . decodeRequestFromString (
185
185
"""
186
186
GET/hello HTTP/1.1 \r
187
187
\r
@@ -193,50 +193,55 @@ struct HTTPDecoderTests {
193
193
@Test
194
194
func body_ThrowsError_WhenSequenceEnds( ) async throws {
195
195
await #expect( throws: SocketError . self) {
196
- try await HTTPDecoder ( ) . readBody ( from: AsyncBufferedEmptySequence ( completeImmediately: true ) , length: " 100 " ) . get ( )
196
+ try await HTTPDecoder . make ( sharedRequestReplaySize: 1024 ) . readBody ( from: AsyncBufferedEmptySequence ( completeImmediately: true ) , length: " 100 " ) . get ( )
197
+ }
198
+ await #expect( throws: SocketError . self) {
199
+ try await HTTPDecoder . make ( sharedRequestBufferSize: 1024 ) . readBody ( from: AsyncBufferedEmptySequence ( completeImmediately: true ) , length: " 100 " ) . get ( )
197
200
}
198
201
}
199
202
200
203
@Test
201
204
func bodySequence_CanReplay_WhenSizeIsLessThanMax( ) async throws {
202
- let sequence = try await HTTPDecoder ( sharedRequestReplaySize: 100 ) . readBodyFromString ( " Fish & Chips " )
205
+ let decoder = HTTPDecoder . make ( sharedRequestBufferSize: 1 , sharedRequestReplaySize: 100 )
206
+ let sequence = try await decoder. readBodyFromString ( " Fish & Chips " )
203
207
#expect( sequence. count == 12 )
204
208
#expect( sequence. canReplay)
205
209
}
206
210
207
211
@Test
208
212
func bodySequence_CanNotReplay_WhenSizeIsGreaterThanMax( ) async throws {
209
- let sequence = try await HTTPDecoder ( sharedRequestReplaySize: 2 ) . readBodyFromString ( " Fish & Chips " )
213
+ let decoder = HTTPDecoder . make ( sharedRequestBufferSize: 1 , sharedRequestReplaySize: 2 )
214
+ let sequence = try await decoder. readBodyFromString ( " Fish & Chips " )
210
215
#expect( sequence. count == 12 )
211
216
#expect( !sequence. canReplay)
212
217
}
213
218
214
219
@Test
215
220
func invalidPathDecodes( ) {
216
- let comps = HTTPDecoder ( ) . makeComponents ( from: nil )
221
+ let comps = HTTPDecoder . make ( ) . makeComponents ( from: nil )
217
222
#expect( comps. path == " " )
218
223
#expect( comps. query == [ ] )
219
224
}
220
225
221
226
@Test
222
227
func percentEncodedPathDecodes( ) {
223
228
#expect(
224
- HTTPDecoder ( ) . readComponents ( from: " /fish%20chips " ) . path == " /fish chips "
229
+ HTTPDecoder . make ( ) . readComponents ( from: " /fish%20chips " ) . path == " /fish chips "
225
230
)
226
231
#expect(
227
- HTTPDecoder ( ) . readComponents ( from: " /ocean/fish%20and%20chips " ) . path == " /ocean/fish and chips "
232
+ HTTPDecoder . make ( ) . readComponents ( from: " /ocean/fish%20and%20chips " ) . path == " /ocean/fish and chips "
228
233
)
229
234
}
230
235
231
236
@Test
232
237
func percentQueryStringDecodes( ) {
233
238
#expect(
234
- HTTPDecoder ( ) . readComponents ( from: " /?fish=%F0%9F%90%9F " ) . query == [
239
+ HTTPDecoder . make ( ) . readComponents ( from: " /?fish=%F0%9F%90%9F " ) . query == [
235
240
. init( name: " fish " , value: " 🐟 " )
236
241
]
237
242
)
238
243
#expect(
239
- HTTPDecoder ( ) . readComponents ( from: " ?%F0%9F%90%A1=chips " ) . query == [
244
+ HTTPDecoder . make ( ) . readComponents ( from: " ?%F0%9F%90%A1=chips " ) . query == [
240
245
. init( name: " 🐡 " , value: " chips " )
241
246
]
242
247
)
@@ -248,7 +253,7 @@ struct HTTPDecoderTests {
248
253
urlComps. queryItems = [ . init( name: " name " , value: nil ) ]
249
254
250
255
#expect(
251
- HTTPDecoder ( ) . makeComponents ( from: urlComps) . query == [
256
+ HTTPDecoder . make ( ) . makeComponents ( from: urlComps) . query == [
252
257
. init( name: " name " , value: " " )
253
258
]
254
259
)
@@ -257,7 +262,7 @@ struct HTTPDecoderTests {
257
262
@Test
258
263
func responseInvalidStatusLine_ThrowsErrorM( ) async throws {
259
264
await #expect( throws: HTTPDecoder . Error. self) {
260
- try await HTTPDecoder ( ) . decodeRequestFromString (
265
+ try await HTTPDecoder . make ( ) . decodeRequestFromString (
261
266
"""
262
267
HTTP/1.1 \r
263
268
\r
@@ -268,7 +273,7 @@ struct HTTPDecoderTests {
268
273
269
274
@Test
270
275
func responseBody_IsNotParsed_WhenContentLength_IsNotProvided( ) async throws {
271
- let response = try await HTTPDecoder ( ) . decodeResponseFromString (
276
+ let response = try await HTTPDecoder . make ( ) . decodeResponseFromString (
272
277
"""
273
278
HTTP/1.1 202 OK \r
274
279
\r
@@ -283,7 +288,7 @@ struct HTTPDecoderTests {
283
288
284
289
@Test
285
290
func responseBody_IsParsed_WhenContentLength_IsProvided( ) async throws {
286
- let response = try await HTTPDecoder ( ) . decodeResponseFromString (
291
+ let response = try await HTTPDecoder . make ( ) . decodeResponseFromString (
287
292
"""
288
293
HTTP/1.1 202 OK \r
289
294
Content-Length: 5 \r
@@ -316,10 +321,3 @@ private extension HTTPDecoder {
316
321
)
317
322
}
318
323
}
319
-
320
- private extension HTTPDecoder {
321
-
322
- init ( ) {
323
- self . init ( sharedRequestReplaySize: 1024 )
324
- }
325
- }
0 commit comments