@@ -33,13 +33,13 @@ class Http1ServerStageSpec extends Http4sSpec {
3333
3434 def runRequest (
3535 req : Seq [String ],
36- service : HttpService [IO ],
36+ routes : HttpRoutes [IO ],
3737 maxReqLine : Int = 4 * 1024 ,
3838 maxHeaders : Int = 16 * 1024 ): Future [ByteBuffer ] = {
3939 val head = new SeqTestHead (
4040 req.map(s => ByteBuffer .wrap(s.getBytes(StandardCharsets .ISO_8859_1 ))))
4141 val httpStage = Http1ServerStage [IO ](
42- service ,
42+ routes ,
4343 AttributeMap .empty,
4444 testExecutionContext,
4545 enableWebSockets = true ,
@@ -55,19 +55,19 @@ class Http1ServerStageSpec extends Http4sSpec {
5555 " Http1ServerStage: Invalid Lengths" should {
5656 val req = " GET /foo HTTP/1.1\r\n header: value\r\n\r\n "
5757
58- val service = HttpService [IO ] {
58+ val routes = HttpRoutes .of [IO ] {
5959 case _ => Ok (" foo!" )
6060 }
6161
6262 " fail on too long of a request line" in {
63- val buff = Await .result(runRequest(Seq (req), service , maxReqLine = 1 ), 5 .seconds)
63+ val buff = Await .result(runRequest(Seq (req), routes , maxReqLine = 1 ), 5 .seconds)
6464 val str = StandardCharsets .ISO_8859_1 .decode(buff.duplicate()).toString
6565 // make sure we don't have signs of chunked encoding.
6666 str.contains(" 400 Bad Request" ) must_== true
6767 }
6868
6969 " fail on too long of a header" in {
70- val buff = Await .result(runRequest(Seq (req), service , maxHeaders = 1 ), 5 .seconds)
70+ val buff = Await .result(runRequest(Seq (req), routes , maxHeaders = 1 ), 5 .seconds)
7171 val str = StandardCharsets .ISO_8859_1 .decode(buff.duplicate()).toString
7272 // make sure we don't have signs of chunked encoding.
7373 str.contains(" 400 Bad Request" ) must_== true
@@ -90,7 +90,7 @@ class Http1ServerStageSpec extends Http4sSpec {
9090 }
9191
9292 " Http1ServerStage: Errors" should {
93- val exceptionService = HttpService [IO ] {
93+ val exceptionService = HttpRoutes .of [IO ] {
9494 case GET -> Root / " sync" => sys.error(" Synchronous error!" )
9595 case GET -> Root / " async" => IO .raiseError(new Exception (" Asynchronous error!" ))
9696 case GET -> Root / " sync" / " 422" =>
@@ -148,7 +148,7 @@ class Http1ServerStageSpec extends Http4sSpec {
148148
149149 " Http1ServerStage: routes" should {
150150 " Do not send `Transfer-Encoding: identity` response" in {
151- val service = HttpService [IO ] {
151+ val routes = HttpRoutes .of [IO ] {
152152 case _ =>
153153 val headers = Headers (H .`Transfer-Encoding`(TransferCoding .identity))
154154 IO .pure(
@@ -159,7 +159,7 @@ class Http1ServerStageSpec extends Http4sSpec {
159159 // The first request will get split into two chunks, leaving the last byte off
160160 val req = " GET /foo HTTP/1.1\r\n\r\n "
161161
162- val buff = Await .result(runRequest(Seq (req), service ), 5 .seconds)
162+ val buff = Await .result(runRequest(Seq (req), routes ), 5 .seconds)
163163
164164 val str = StandardCharsets .ISO_8859_1 .decode(buff.duplicate()).toString
165165 // make sure we don't have signs of chunked encoding.
@@ -171,7 +171,7 @@ class Http1ServerStageSpec extends Http4sSpec {
171171 }
172172
173173 " Do not send an entity or entity-headers for a status that doesn't permit it" in {
174- val service : HttpService [IO ] = HttpService [IO ] {
174+ val routes : HttpRoutes [IO ] = HttpRoutes .of [IO ] {
175175 case _ =>
176176 IO .pure(
177177 Response [IO ](status = Status .NotModified )
@@ -181,7 +181,7 @@ class Http1ServerStageSpec extends Http4sSpec {
181181
182182 val req = " GET /foo HTTP/1.1\r\n\r\n "
183183
184- val buf = Await .result(runRequest(Seq (req), service ), 5 .seconds)
184+ val buf = Await .result(runRequest(Seq (req), routes ), 5 .seconds)
185185 val (status, hs, body) = ResponseParser .parseBuffer(buf)
186186
187187 val hss = Headers (hs.toList)
@@ -191,14 +191,14 @@ class Http1ServerStageSpec extends Http4sSpec {
191191 }
192192
193193 " Add a date header" in {
194- val service = HttpService [IO ] {
194+ val routes = HttpRoutes .of [IO ] {
195195 case req => IO .pure(Response (body = req.body))
196196 }
197197
198198 // The first request will get split into two chunks, leaving the last byte off
199199 val req1 = " POST /sync HTTP/1.1\r\n Connection:keep-alive\r\n Content-Length: 4\r\n\r\n done"
200200
201- val buff = Await .result(runRequest(Seq (req1), service ), 5 .seconds)
201+ val buff = Await .result(runRequest(Seq (req1), routes ), 5 .seconds)
202202
203203 // Both responses must succeed
204204 val (_, hdrs, _) = ResponseParser .apply(buff)
@@ -207,14 +207,14 @@ class Http1ServerStageSpec extends Http4sSpec {
207207
208208 " Honor an explicitly added date header" in {
209209 val dateHeader = Date (HttpDate .Epoch )
210- val service = HttpService [IO ] {
210+ val routes = HttpRoutes .of [IO ] {
211211 case req => IO .pure(Response (body = req.body).replaceAllHeaders(dateHeader))
212212 }
213213
214214 // The first request will get split into two chunks, leaving the last byte off
215215 val req1 = " POST /sync HTTP/1.1\r\n Connection:keep-alive\r\n Content-Length: 4\r\n\r\n done"
216216
217- val buff = Await .result(runRequest(Seq (req1), service ), 5 .seconds)
217+ val buff = Await .result(runRequest(Seq (req1), routes ), 5 .seconds)
218218
219219 // Both responses must succeed
220220 val (_, hdrs, _) = ResponseParser .apply(buff)
@@ -223,22 +223,22 @@ class Http1ServerStageSpec extends Http4sSpec {
223223 }
224224
225225 " Handle routes that echos full request body for non-chunked" in {
226- val service = HttpService [IO ] {
226+ val routes = HttpRoutes .of [IO ] {
227227 case req => IO .pure(Response (body = req.body))
228228 }
229229
230230 // The first request will get split into two chunks, leaving the last byte off
231231 val req1 = " POST /sync HTTP/1.1\r\n Connection:keep-alive\r\n Content-Length: 4\r\n\r\n done"
232232 val (r11, r12) = req1.splitAt(req1.length - 1 )
233233
234- val buff = Await .result(runRequest(Seq (r11, r12), service ), 5 .seconds)
234+ val buff = Await .result(runRequest(Seq (r11, r12), routes ), 5 .seconds)
235235
236236 // Both responses must succeed
237237 parseAndDropDate(buff) must_== ((Ok , Set (H .`Content-Length`.unsafeFromLong(4 )), " done" ))
238238 }
239239
240240 " Handle routes that consumes the full request body for non-chunked" in {
241- val service = HttpService [IO ] {
241+ val routes = HttpRoutes .of [IO ] {
242242 case req =>
243243 req.as[String ].map { s =>
244244 Response ().withEntity(" Result: " + s)
@@ -249,7 +249,7 @@ class Http1ServerStageSpec extends Http4sSpec {
249249 val req1 = " POST /sync HTTP/1.1\r\n Connection:keep-alive\r\n Content-Length: 4\r\n\r\n done"
250250 val (r11, r12) = req1.splitAt(req1.length - 1 )
251251
252- val buff = Await .result(runRequest(Seq (r11, r12), service ), 5 .seconds)
252+ val buff = Await .result(runRequest(Seq (r11, r12), routes ), 5 .seconds)
253253
254254 // Both responses must succeed
255255 parseAndDropDate(buff) must_== (
@@ -263,15 +263,15 @@ class Http1ServerStageSpec extends Http4sSpec {
263263
264264 " Maintain the connection if the body is ignored but was already read to completion by the Http1Stage" in {
265265
266- val service = HttpService [IO ] {
266+ val routes = HttpRoutes .of [IO ] {
267267 case _ => IO .pure(Response ().withEntity(" foo" ))
268268 }
269269
270270 // The first request will get split into two chunks, leaving the last byte off
271271 val req1 = " POST /sync HTTP/1.1\r\n Connection:keep-alive\r\n Content-Length: 4\r\n\r\n done"
272272 val req2 = " POST /sync HTTP/1.1\r\n Connection:keep-alive\r\n Content-Length: 5\r\n\r\n total"
273273
274- val buff = Await .result(runRequest(Seq (req1, req2), service ), 5 .seconds)
274+ val buff = Await .result(runRequest(Seq (req1, req2), routes ), 5 .seconds)
275275
276276 val hs = Set (
277277 H .`Content-Type`(MediaType .`text/plain`, Charset .`UTF-8`),
@@ -283,7 +283,7 @@ class Http1ServerStageSpec extends Http4sSpec {
283283
284284 " Drop the connection if the body is ignored and was not read to completion by the Http1Stage" in {
285285
286- val service = HttpService [IO ] {
286+ val routes = HttpRoutes .of [IO ] {
287287 case _ => IO .pure(Response ().withEntity(" foo" ))
288288 }
289289
@@ -293,7 +293,7 @@ class Http1ServerStageSpec extends Http4sSpec {
293293
294294 val req2 = " POST /sync HTTP/1.1\r\n Connection:keep-alive\r\n Content-Length: 5\r\n\r\n total"
295295
296- val buff = Await .result(runRequest(Seq (r11, r12, req2), service ), 5 .seconds)
296+ val buff = Await .result(runRequest(Seq (r11, r12, req2), routes ), 5 .seconds)
297297
298298 val hs = Set (
299299 H .`Content-Type`(MediaType .`text/plain`, Charset .`UTF-8`),
@@ -305,7 +305,7 @@ class Http1ServerStageSpec extends Http4sSpec {
305305
306306 " Handle routes that runs the request body for non-chunked" in {
307307
308- val service = HttpService [IO ] {
308+ val routes = HttpRoutes .of [IO ] {
309309 case req => req.body.compile.drain *> IO .pure(Response ().withEntity(" foo" ))
310310 }
311311
@@ -314,7 +314,7 @@ class Http1ServerStageSpec extends Http4sSpec {
314314 val (r11, r12) = req1.splitAt(req1.length - 1 )
315315 val req2 = " POST /sync HTTP/1.1\r\n Connection:keep-alive\r\n Content-Length: 5\r\n\r\n total"
316316
317- val buff = Await .result(runRequest(Seq (r11, r12, req2), service ), 5 .seconds)
317+ val buff = Await .result(runRequest(Seq (r11, r12, req2), routes ), 5 .seconds)
318318
319319 val hs = Set (
320320 H .`Content-Type`(MediaType .`text/plain`, Charset .`UTF-8`),
@@ -327,7 +327,7 @@ class Http1ServerStageSpec extends Http4sSpec {
327327 // Think of this as drunk HTTP pipelining
328328 " Not die when two requests come in back to back" in {
329329
330- val service = HttpService [IO ] {
330+ val routes = HttpRoutes .of [IO ] {
331331 case req =>
332332 IO .pure(Response (body = req.body))
333333 }
@@ -336,7 +336,7 @@ class Http1ServerStageSpec extends Http4sSpec {
336336 val req1 = " POST /sync HTTP/1.1\r\n Connection:keep-alive\r\n Content-Length: 4\r\n\r\n done"
337337 val req2 = " POST /sync HTTP/1.1\r\n Connection:keep-alive\r\n Content-Length: 5\r\n\r\n total"
338338
339- val buff = Await .result(runRequest(Seq (req1 + req2), service ), 5 .seconds)
339+ val buff = Await .result(runRequest(Seq (req1 + req2), routes ), 5 .seconds)
340340
341341 // Both responses must succeed
342342 dropDate(ResponseParser .parseBuffer(buff)) must_== (
@@ -353,15 +353,15 @@ class Http1ServerStageSpec extends Http4sSpec {
353353
354354 " Handle using the request body as the response body" in {
355355
356- val service = HttpService [IO ] {
356+ val routes = HttpRoutes .of [IO ] {
357357 case req => IO .pure(Response (body = req.body))
358358 }
359359
360360 // The first request will get split into two chunks, leaving the last byte off
361361 val req1 = " POST /sync HTTP/1.1\r\n Connection:keep-alive\r\n Content-Length: 4\r\n\r\n done"
362362 val req2 = " POST /sync HTTP/1.1\r\n Connection:keep-alive\r\n Content-Length: 5\r\n\r\n total"
363363
364- val buff = Await .result(runRequest(Seq (req1, req2), service ), 5 .seconds)
364+ val buff = Await .result(runRequest(Seq (req1, req2), routes ), 5 .seconds)
365365
366366 // Both responses must succeed
367367 dropDate(ResponseParser .parseBuffer(buff)) must_== (
@@ -384,7 +384,7 @@ class Http1ServerStageSpec extends Http4sSpec {
384384 " 0\r\n " +
385385 " Foo:Bar\r\n\r\n "
386386
387- val service = HttpService [IO ] {
387+ val routes = HttpRoutes .of [IO ] {
388388 case req if req.pathInfo == " /foo" =>
389389 for {
390390 _ <- req.body.compile.drain
@@ -402,15 +402,15 @@ class Http1ServerStageSpec extends Http4sSpec {
402402 }
403403
404404 " Handle trailing headers" in {
405- val buff = Await .result(runRequest(Seq (req(" foo" )), service ), 5 .seconds)
405+ val buff = Await .result(runRequest(Seq (req(" foo" )), routes ), 5 .seconds)
406406
407407 val results = dropDate(ResponseParser .parseBuffer(buff))
408408 results._1 must_== Ok
409409 results._3 must_== " Foo: Bar"
410410 }
411411
412412 " Fail if you use the trailers before they have resolved" in {
413- val buff = Await .result(runRequest(Seq (req(" bar" )), service ), 5 .seconds)
413+ val buff = Await .result(runRequest(Seq (req(" bar" )), routes ), 5 .seconds)
414414
415415 val results = dropDate(ResponseParser .parseBuffer(buff))
416416 results._1 must_== InternalServerError
0 commit comments