Skip to content

Commit 0bd20db

Browse files
committed
Clean up the deprecation warnings
1 parent e5f503f commit 0bd20db

File tree

109 files changed

+630
-637
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+630
-637
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Scala's answer to Ruby's Rack, Python's WSGI, Haskell's WAI, and Java's
55
Servlets.
66

77
```scala
8-
val service = HttpService {
9-
case GET -> Root / "hello" =>
10-
Ok("Hello, better world.")
11-
}
8+
val http = HttpRoutes.of {
9+
case GET -> Root / "hello" =>
10+
Ok("Hello, better world.")
11+
}
1212
```
1313

1414
Learn more at [http4s.org](http://http4s.org/).

blaze-server/src/main/scala/org/http4s/server/blaze/BlazeBuilder.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class BlazeBuilder[F[_]](
124124

125125
def enableHttp2(enabled: Boolean): Self = copy(http2Support = enabled)
126126

127-
override def mountService(service: HttpService[F], prefix: String): Self = {
127+
override def mountService(service: HttpRoutes[F], prefix: String): Self = {
128128
val prefixedService =
129129
if (prefix.isEmpty || prefix == "/") service
130130
else {
@@ -310,4 +310,4 @@ object BlazeBuilder {
310310
)
311311
}
312312

313-
private final case class ServiceMount[F[_]](service: HttpService[F], prefix: String)
313+
private final case class ServiceMount[F[_]](service: HttpRoutes[F], prefix: String)

blaze-server/src/main/scala/org/http4s/server/blaze/Http1ServerStage.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import scala.util.{Either, Failure, Left, Right, Success, Try}
2323
private[blaze] object Http1ServerStage {
2424

2525
def apply[F[_]: Effect](
26-
service: HttpService[F],
26+
routes: HttpRoutes[F],
2727
attributes: AttributeMap,
2828
executionContext: ExecutionContext,
2929
enableWebSockets: Boolean,
@@ -32,15 +32,15 @@ private[blaze] object Http1ServerStage {
3232
serviceErrorHandler: ServiceErrorHandler[F]): Http1ServerStage[F] =
3333
if (enableWebSockets)
3434
new Http1ServerStage(
35-
service,
35+
routes,
3636
attributes,
3737
executionContext,
3838
maxRequestLineLen,
3939
maxHeadersLen,
4040
serviceErrorHandler) with WebSocketSupport[F]
4141
else
4242
new Http1ServerStage(
43-
service,
43+
routes,
4444
attributes,
4545
executionContext,
4646
maxRequestLineLen,
@@ -49,7 +49,7 @@ private[blaze] object Http1ServerStage {
4949
}
5050

5151
private[blaze] class Http1ServerStage[F[_]](
52-
service: HttpService[F],
52+
routes: HttpRoutes[F],
5353
requestAttrs: AttributeMap,
5454
implicit protected val executionContext: ExecutionContext,
5555
maxRequestLineLen: Int,
@@ -58,8 +58,8 @@ private[blaze] class Http1ServerStage[F[_]](
5858
extends Http1Stage[F]
5959
with TailStage[ByteBuffer] {
6060

61-
// micro-optimization: unwrap the service and call its .run directly
62-
private[this] val serviceFn = service.run
61+
// micro-optimization: unwrap the routes and call its .run directly
62+
private[this] val routesFn = routes.run
6363

6464
// both `parser` and `isClosed` are protected by synchronization on `parser`
6565
private[this] val parser = new Http1ServerParser[F](logger, maxRequestLineLen, maxHeadersLen)
@@ -142,7 +142,7 @@ private[blaze] class Http1ServerStage[F[_]](
142142
executionContext.execute(new Runnable {
143143
def run(): Unit =
144144
F.runAsync {
145-
try serviceFn(req)
145+
try routesFn(req)
146146
.getOrElse(Response.notFound)
147147
.handleErrorWith(serviceErrorHandler(req))
148148
catch serviceErrorHandler(req)

blaze-server/src/main/scala/org/http4s/server/blaze/Http2NodeStage.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private class Http2NodeStage[F[_]](
2626
timeout: Duration,
2727
implicit private val executionContext: ExecutionContext,
2828
attributes: AttributeMap,
29-
service: HttpService[F],
29+
service: HttpRoutes[F],
3030
serviceErrorHandler: ServiceErrorHandler[F])(implicit F: Effect[F])
3131
extends TailStage[NodeMsg.Http2Msg] {
3232

blaze-server/src/main/scala/org/http4s/server/blaze/ProtocolSelector.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import scala.concurrent.duration.Duration
1414
private[blaze] object ProtocolSelector {
1515
def apply[F[_]: Effect](
1616
engine: SSLEngine,
17-
service: HttpService[F],
17+
routes: HttpRoutes[F],
1818
maxRequestLineLen: Int,
1919
maxHeadersLen: Int,
2020
requestAttributes: AttributeMap,
@@ -30,7 +30,7 @@ private[blaze] object ProtocolSelector {
3030
Duration.Inf,
3131
executionContext,
3232
requestAttributes,
33-
service,
33+
routes,
3434
serviceErrorHandler))
3535
}
3636

@@ -46,7 +46,7 @@ private[blaze] object ProtocolSelector {
4646

4747
def http1Stage(): TailStage[ByteBuffer] =
4848
Http1ServerStage[F](
49-
service,
49+
routes,
5050
requestAttributes,
5151
executionContext,
5252
enableWebSockets = false,

blaze-server/src/test/scala/org/http4s/server/blaze/Http1ServerStageSpec.scala

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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\nheader: 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\nConnection:keep-alive\r\nContent-Length: 4\r\n\r\ndone"
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\nConnection:keep-alive\r\nContent-Length: 4\r\n\r\ndone"
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\nConnection:keep-alive\r\nContent-Length: 4\r\n\r\ndone"
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\nConnection:keep-alive\r\nContent-Length: 4\r\n\r\ndone"
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\nConnection:keep-alive\r\nContent-Length: 4\r\n\r\ndone"
272272
val req2 = "POST /sync HTTP/1.1\r\nConnection:keep-alive\r\nContent-Length: 5\r\n\r\ntotal"
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\nConnection:keep-alive\r\nContent-Length: 5\r\n\r\ntotal"
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\nConnection:keep-alive\r\nContent-Length: 5\r\n\r\ntotal"
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\nConnection:keep-alive\r\nContent-Length: 4\r\n\r\ndone"
337337
val req2 = "POST /sync HTTP/1.1\r\nConnection:keep-alive\r\nContent-Length: 5\r\n\r\ntotal"
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\nConnection:keep-alive\r\nContent-Length: 4\r\n\r\ndone"
362362
val req2 = "POST /sync HTTP/1.1\r\nConnection:keep-alive\r\nContent-Length: 5\r\n\r\ntotal"
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

Comments
 (0)