@@ -38,7 +38,7 @@ struct HTTPDecoderTests {
3838
3939 @Test
4040 func GETMethod_IsParsed( ) async throws {
41- let request = try await HTTPDecoder ( ) . decodeRequestFromString (
41+ let request = try await HTTPDecoder . make ( ) . decodeRequestFromString (
4242 """
4343 GET /hello HTTP/1.1 \r
4444 \r
@@ -52,7 +52,7 @@ struct HTTPDecoderTests {
5252
5353 @Test
5454 func POSTMethod_IsParsed( ) async throws {
55- let request = try await HTTPDecoder ( ) . decodeRequestFromString (
55+ let request = try await HTTPDecoder . make ( ) . decodeRequestFromString (
5656 """
5757 POST /hello HTTP/1.1 \r
5858 \r
@@ -66,7 +66,7 @@ struct HTTPDecoderTests {
6666
6767 @Test
6868 func CUSTOMMethod_IsParsed( ) async throws {
69- let request = try await HTTPDecoder ( ) . decodeRequestFromString (
69+ let request = try await HTTPDecoder . make ( ) . decodeRequestFromString (
7070 """
7171 FISH /hello HTTP/1.1 \r
7272 \r
@@ -80,7 +80,7 @@ struct HTTPDecoderTests {
8080
8181 @Test
8282 func path_IsParsed( ) async throws {
83- let request = try await HTTPDecoder ( ) . decodeRequestFromString (
83+ let request = try await HTTPDecoder . make ( ) . decodeRequestFromString (
8484 """
8585 GET /hello/world?fish=Chips&with=Mushy%20Peas HTTP/1.1 \r
8686 \r
@@ -101,7 +101,7 @@ struct HTTPDecoderTests {
101101
102102 @Test
103103 func naughtyPath_IsParsed( ) async throws {
104- let request = try await HTTPDecoder ( ) . decodeRequestFromString (
104+ let request = try await HTTPDecoder . make ( ) . decodeRequestFromString (
105105 """
106106 GET /../a/b/../c/./d.html?fish=Chips&with=Mushy%20Peas HTTP/1.1 \r
107107 \r
@@ -128,7 +128,7 @@ struct HTTPDecoderTests {
128128
129129 @Test
130130 func headers_AreParsed( ) async throws {
131- let request = try await HTTPDecoder ( ) . decodeRequestFromString (
131+ let request = try await HTTPDecoder . make ( ) . decodeRequestFromString (
132132 """
133133 GET /hello HTTP/1.1 \r
134134 Fish: Chips \r
@@ -149,7 +149,7 @@ struct HTTPDecoderTests {
149149
150150 @Test
151151 func body_IsNotParsed_WhenContentLength_IsNotProvided( ) async throws {
152- let request = try await HTTPDecoder ( ) . decodeRequestFromString (
152+ let request = try await HTTPDecoder . make ( ) . decodeRequestFromString (
153153 """
154154 GET /hello HTTP/1.1 \r
155155 \r
@@ -164,7 +164,7 @@ struct HTTPDecoderTests {
164164
165165 @Test
166166 func body_IsParsed_WhenContentLength_IsProvided( ) async throws {
167- let request = try await HTTPDecoder ( ) . decodeRequestFromString (
167+ let request = try await HTTPDecoder . make ( ) . decodeRequestFromString (
168168 """
169169 GET /hello HTTP/1.1 \r
170170 Content-Length: 5 \r
@@ -181,7 +181,7 @@ struct HTTPDecoderTests {
181181 @Test
182182 func invalidStatusLine_ThrowsError( ) async {
183183 await #expect( throws: HTTPDecoder . Error. self) {
184- try await HTTPDecoder ( ) . decodeRequestFromString (
184+ try await HTTPDecoder . make ( ) . decodeRequestFromString (
185185 """
186186 GET/hello HTTP/1.1 \r
187187 \r
@@ -193,50 +193,55 @@ struct HTTPDecoderTests {
193193 @Test
194194 func body_ThrowsError_WhenSequenceEnds( ) async throws {
195195 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 ( )
197200 }
198201 }
199202
200203 @Test
201204 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 " )
203207 #expect( sequence. count == 12 )
204208 #expect( sequence. canReplay)
205209 }
206210
207211 @Test
208212 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 " )
210215 #expect( sequence. count == 12 )
211216 #expect( !sequence. canReplay)
212217 }
213218
214219 @Test
215220 func invalidPathDecodes( ) {
216- let comps = HTTPDecoder ( ) . makeComponents ( from: nil )
221+ let comps = HTTPDecoder . make ( ) . makeComponents ( from: nil )
217222 #expect( comps. path == " " )
218223 #expect( comps. query == [ ] )
219224 }
220225
221226 @Test
222227 func percentEncodedPathDecodes( ) {
223228 #expect(
224- HTTPDecoder ( ) . readComponents ( from: " /fish%20chips " ) . path == " /fish chips "
229+ HTTPDecoder . make ( ) . readComponents ( from: " /fish%20chips " ) . path == " /fish chips "
225230 )
226231 #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 "
228233 )
229234 }
230235
231236 @Test
232237 func percentQueryStringDecodes( ) {
233238 #expect(
234- HTTPDecoder ( ) . readComponents ( from: " /?fish=%F0%9F%90%9F " ) . query == [
239+ HTTPDecoder . make ( ) . readComponents ( from: " /?fish=%F0%9F%90%9F " ) . query == [
235240 . init( name: " fish " , value: " 🐟 " )
236241 ]
237242 )
238243 #expect(
239- HTTPDecoder ( ) . readComponents ( from: " ?%F0%9F%90%A1=chips " ) . query == [
244+ HTTPDecoder . make ( ) . readComponents ( from: " ?%F0%9F%90%A1=chips " ) . query == [
240245 . init( name: " 🐡 " , value: " chips " )
241246 ]
242247 )
@@ -248,7 +253,7 @@ struct HTTPDecoderTests {
248253 urlComps. queryItems = [ . init( name: " name " , value: nil ) ]
249254
250255 #expect(
251- HTTPDecoder ( ) . makeComponents ( from: urlComps) . query == [
256+ HTTPDecoder . make ( ) . makeComponents ( from: urlComps) . query == [
252257 . init( name: " name " , value: " " )
253258 ]
254259 )
@@ -257,7 +262,7 @@ struct HTTPDecoderTests {
257262 @Test
258263 func responseInvalidStatusLine_ThrowsErrorM( ) async throws {
259264 await #expect( throws: HTTPDecoder . Error. self) {
260- try await HTTPDecoder ( ) . decodeRequestFromString (
265+ try await HTTPDecoder . make ( ) . decodeRequestFromString (
261266 """
262267 HTTP/1.1 \r
263268 \r
@@ -268,7 +273,7 @@ struct HTTPDecoderTests {
268273
269274 @Test
270275 func responseBody_IsNotParsed_WhenContentLength_IsNotProvided( ) async throws {
271- let response = try await HTTPDecoder ( ) . decodeResponseFromString (
276+ let response = try await HTTPDecoder . make ( ) . decodeResponseFromString (
272277 """
273278 HTTP/1.1 202 OK \r
274279 \r
@@ -283,7 +288,7 @@ struct HTTPDecoderTests {
283288
284289 @Test
285290 func responseBody_IsParsed_WhenContentLength_IsProvided( ) async throws {
286- let response = try await HTTPDecoder ( ) . decodeResponseFromString (
291+ let response = try await HTTPDecoder . make ( ) . decodeResponseFromString (
287292 """
288293 HTTP/1.1 202 OK \r
289294 Content-Length: 5 \r
@@ -316,10 +321,3 @@ private extension HTTPDecoder {
316321 )
317322 }
318323}
319-
320- private extension HTTPDecoder {
321-
322- init ( ) {
323- self . init ( sharedRequestReplaySize: 1024 )
324- }
325- }
0 commit comments