Skip to content

Commit bbbbd46

Browse files
committed
Update to Http4s 0.23.0-RC1
1 parent 339de5d commit bbbbd46

File tree

21 files changed

+65
-61
lines changed

21 files changed

+65
-61
lines changed

Diff for: core/src/main/scala/org/http4s/rho/CompileRoutes.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ object CompileRoutes {
4040
* @param routes `Seq` of routes to bundle into a service.
4141
* @return An `HttpRoutes`
4242
*/
43-
def foldRoutes[F[_]: Defer: Monad](routes: Seq[RhoRoute.Tpe[F]]): HttpRoutes[F] = {
43+
def foldRoutes[F[_]: Monad](routes: Seq[RhoRoute.Tpe[F]]): HttpRoutes[F] = {
4444
val tree = routes.foldLeft(PathTree[F]())((t, r) => t.appendRoute(r))
4545
HttpRoutes((req: Request[F]) => tree.getResult(req).toResponse)
4646
}

Diff for: core/src/main/scala/org/http4s/rho/RhoRoutes.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import shapeless.{HList, HNil}
2323
*
2424
* @param routes Routes to prepend before elements in the constructor.
2525
*/
26-
class RhoRoutes[F[_]: Defer: Monad](routes: Seq[RhoRoute[F, _ <: HList]] = Vector.empty)
26+
class RhoRoutes[F[_]: Monad](routes: Seq[RhoRoute[F, _ <: HList]] = Vector.empty)
2727
extends bits.MethodAliases
2828
with bits.ResponseGeneratorInstances[F]
2929
with RoutePrependable[F, RhoRoutes[F]]

Diff for: core/src/main/scala/org/http4s/rho/RoutesBuilder.scala

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import org.http4s._
99
import scala.collection.compat._
1010

1111
/** CompileRoutes which accumulates routes and can build a `HttpRoutes` */
12-
final class RoutesBuilder[F[_]: Defer: Monad] private (
13-
internalRoutes: VectorBuilder[RhoRoute.Tpe[F]])
12+
final class RoutesBuilder[F[_]: Monad] private (internalRoutes: VectorBuilder[RhoRoute.Tpe[F]])
1413
extends CompileRoutes[F, RhoRoute.Tpe[F]] {
1514

1615
/** Turn the accumulated routes into an `HttpRoutes`
@@ -51,10 +50,10 @@ final class RoutesBuilder[F[_]: Defer: Monad] private (
5150
object RoutesBuilder {
5251

5352
/** Constructor method for new `RoutesBuilder` instances */
54-
def apply[F[_]: Defer: Monad](): RoutesBuilder[F] = apply(Seq.empty)
53+
def apply[F[_]: Monad](): RoutesBuilder[F] = apply(Seq.empty)
5554

5655
/** Constructor method for new `RoutesBuilder` instances with existing routes */
57-
def apply[F[_]: Defer: Monad](routes: Seq[RhoRoute.Tpe[F]]): RoutesBuilder[F] = {
56+
def apply[F[_]: Monad](routes: Seq[RhoRoute.Tpe[F]]): RoutesBuilder[F] = {
5857
val builder = new VectorBuilder[RhoRoute.Tpe[F]]
5958
builder ++= routes
6059

Diff for: core/src/test/scala/org/http4s/rho/ApiTest.scala

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.http4s.Uri.uri
1313
import org.specs2.matcher.MatchResult
1414
import org.specs2.mutable._
1515
import shapeless.{HList, HNil}
16+
import cats.effect.unsafe.implicits.global
1617
import scala.util.control.NoStackTrace
1718
import org.http4s.headers.Accept
1819

Diff for: core/src/test/scala/org/http4s/rho/AuthedContextSpec.scala

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ object MyRoutes extends RhoRoutes[IO] {
4444
}
4545

4646
class AuthedContextSpec extends Specification {
47+
import cats.effect.unsafe.implicits.global
4748

4849
val routes = Auth.authenticated(MyAuth.toService(MyRoutes.toRoutes()))
4950

Diff for: core/src/test/scala/org/http4s/rho/CodecRouterSpec.scala

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.specs2.mutable.Specification
88
import scala.collection.compat.immutable.ArraySeq
99

1010
class CodecRouterSpec extends Specification {
11+
import cats.effect.unsafe.implicits.global
1112

1213
def bodyAndStatus(resp: Response[IO]): (String, Status) = {
1314
val rbody = new String(

Diff for: core/src/test/scala/org/http4s/rho/ParamDefaultValueSpec.scala

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import scala.collection.immutable.Seq
55

66
import cats.effect.IO
77
import org.specs2.mutable.Specification
8+
import cats.effect.unsafe.implicits.global
89

910
class ParamDefaultValueSpec extends Specification {
1011

Diff for: core/src/test/scala/org/http4s/rho/RequestRunner.scala

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.http4s.rho
33
import cats.effect.IO
44
import org.http4s._
55
import org.http4s.HttpRoutes
6+
import cats.effect.unsafe.implicits.global
67

78
/** Helper for collecting a the body from a `RhoRoutes` */
89
trait RequestRunner {

Diff for: core/src/test/scala/org/http4s/rho/ResultSpec.scala

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.http4s.headers._
66
import org.http4s.rho.io._
77
import org.http4s.HttpDate
88
import org.specs2.mutable.Specification
9+
import cats.effect.unsafe.implicits.global
910

1011
class ResultSpec extends Specification {
1112

Diff for: core/src/test/scala/org/http4s/rho/RhoRoutesSpec.scala

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.http4s.headers.{`Content-Length`, `Content-Type`}
1111
import org.http4s.rho.io._
1212
import org.http4s.Uri.uri
1313
import org.specs2.mutable.Specification
14+
import cats.effect.unsafe.implicits.global
1415
import org.http4s.Uri.Path
1516
import org.typelevel.ci.CIString
1617
import scala.util.control.NoStackTrace

Diff for: core/src/test/scala/org/http4s/rho/bits/HListToFuncSpec.scala

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package bits
44

55
import cats.effect.IO
66
import org.specs2.mutable.Specification
7+
import cats.effect.unsafe.implicits.global
78

89
class HListToFuncSpec extends Specification {
910
def getBody(b: EntityBody[IO]): String =

Diff for: core/src/test/scala/org/http4s/rho/bits/PathTreeSpec.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import java.nio.charset.StandardCharsets
66

77
import cats.effect.IO
88
import org.specs2.mutable.Specification
9-
import org.http4s.Uri._
9+
import org.http4s.Uri.uri
1010
import org.http4s.server.middleware.TranslateUri
1111
import org.http4s.server.Router
12+
import cats.effect.unsafe.implicits.global
1213

1314
class PathTreeSpec extends Specification {
1415
object pathTree extends PathTreeOps[IO]

Diff for: core/src/test/scala/org/http4s/rho/bits/ResponseGeneratorSpec.scala

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import org.http4s.rho.io._
77
import org.specs2.mutable.Specification
88

99
class ResponseGeneratorSpec extends Specification {
10+
import cats.effect.unsafe.implicits.global
11+
1012
"ResponseGenerator" should {
1113
"Build a response with a body" in {
1214
val result = Ok("Foo").unsafeRunSync()

Diff for: core/src/test/scala/org/http4s/rho/bits/ResultMatcherSpec.scala

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import shapeless.HList
1313
import scala.reflect.runtime.universe._
1414

1515
class ResultMatcherSpec extends Specification {
16+
import cats.effect.unsafe.implicits.global
1617

1718
class TRhoRoutes[F[_]] extends bits.MethodAliases {
1819
var statuses: Set[(Status, Type)] = Set.empty
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.http4s.rho.swagger.demo
22

3-
import cats.effect.{Blocker, ExitCode, IO, IOApp}
3+
import cats.effect.{ExitCode, IO, IOApp}
44
import com.http4s.rho.swagger.ui.SwaggerUi
55
import org.http4s.implicits._
66
import org.http4s.rho.swagger.SwaggerMetadata
@@ -20,23 +20,22 @@ object Main extends IOApp {
2020

2121
logger.info(s"Starting Swagger example on '$port'")
2222

23-
def run(args: List[String]): IO[ExitCode] =
24-
Blocker[IO].use { blocker =>
25-
val metadata = SwaggerMetadata(
26-
apiInfo = Info(title = "Rho demo", version = "1.2.3"),
27-
tags = List(Tag(name = "hello", description = Some("These are the hello routes.")))
28-
)
29-
30-
val swaggerUiRhoMiddleware =
31-
SwaggerUi[IO].createRhoMiddleware(blocker, swaggerMetadata = metadata)
32-
val myRoutes = new MyRoutes[IO](ioSwagger).toRoutes(swaggerUiRhoMiddleware)
33-
34-
BlazeServerBuilder[IO](global)
35-
.withHttpApp(myRoutes.orNotFound)
36-
.bindLocal(port)
37-
.serve
38-
.compile
39-
.drain
40-
.as(ExitCode.Success)
41-
}
23+
def run(args: List[String]): IO[ExitCode] = {
24+
val metadata = SwaggerMetadata(
25+
apiInfo = Info(title = "Rho demo", version = "1.2.3"),
26+
tags = List(Tag(name = "hello", description = Some("These are the hello routes.")))
27+
)
28+
29+
val swaggerUiRhoMiddleware =
30+
SwaggerUi[IO].createRhoMiddleware(swaggerMetadata = metadata)
31+
val myRoutes = new MyRoutes[IO](ioSwagger).toRoutes(swaggerUiRhoMiddleware)
32+
33+
BlazeServerBuilder[IO](global)
34+
.withHttpApp(myRoutes.orNotFound)
35+
.bindLocal(port)
36+
.serve
37+
.compile
38+
.drain
39+
.as(ExitCode.Success)
40+
}
4241
}

Diff for: examples/src/main/scala/com/http4s/rho/swagger/demo/MyRoutes.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.http4s.rho.swagger.demo
22

3-
import cats.Monad
3+
import cats._
44
import cats.effect._
55
import cats.implicits._
66
import com.http4s.rho.swagger.demo.MyRoutes._
@@ -13,9 +13,10 @@ import shapeless.HNil
1313
import org.http4s.circe.CirceEntityEncoder
1414
import org.http4s.implicits._
1515

16-
class MyRoutes[F[+_]: Effect](swaggerSyntax: SwaggerSyntax[F])
16+
class MyRoutes[F[+_]: Async](swaggerSyntax: SwaggerSyntax[F])
1717
extends RhoRoutes[F]
1818
with CirceEntityEncoder {
19+
1920
import swaggerSyntax._
2021

2122
val requireCookie: TypedHeader[F, HNil] = H[headers.Cookie].existsAndR { cookie =>
@@ -54,7 +55,7 @@ class MyRoutes[F[+_]: Effect](swaggerSyntax: SwaggerSyntax[F])
5455
}
5556

5657
// Normally this would be part of the constructor since its creation is 'unsafe'
57-
private val counterRef = cats.effect.concurrent.Ref.unsafe[F, Int](0)
58+
private val counterRef = cats.effect.Ref.unsafe[F, Int](0)
5859

5960
"This uses a simple counter for the number of times this route has been requested" **
6061
POST / "counter" |>> { () =>
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.http4s.rho.swagger.demo
22

3-
import cats.effect.{Blocker, ContextShift, IO}
3+
import cats.effect.{IO}
44
import org.http4s.dsl.io._
55
import org.http4s.rho.RhoRoutes
66
import org.http4s.{HttpRoutes, Request, Response, StaticFile}
@@ -11,27 +11,26 @@ object StaticContentService {
1111
/** Routes for getting static resources. These might be served more efficiently by apache2 or nginx,
1212
* but its nice to keep it self contained.
1313
*/
14-
def routes(blocker: Blocker)(implicit cs: ContextShift[IO]): HttpRoutes[IO] = new RhoRoutes[IO] {
14+
def routes: HttpRoutes[IO] = new RhoRoutes[IO] {
1515
// Swagger User Interface
1616
GET / "css" / * |>> { (req: Request[IO], _: List[String]) =>
17-
fetchResource(swaggerUiDir + req.pathInfo, req, blocker)
17+
fetchResource(swaggerUiDir + req.pathInfo, req)
1818
}
1919
GET / "images" / * |>> { (req: Request[IO], _: List[String]) =>
20-
fetchResource(swaggerUiDir + req.pathInfo, req, blocker)
20+
fetchResource(swaggerUiDir + req.pathInfo, req)
2121
}
2222
GET / "lib" / * |>> { (req: Request[IO], _: List[String]) =>
23-
fetchResource(swaggerUiDir + req.pathInfo, req, blocker)
23+
fetchResource(swaggerUiDir + req.pathInfo, req)
2424
}
2525
GET / "swagger-ui" |>> { req: Request[IO] =>
26-
fetchResource(swaggerUiDir + "/index.html", req, blocker)
26+
fetchResource(swaggerUiDir + "/index.html", req)
2727
}
2828
GET / "swagger-ui.js" |>> { req: Request[IO] =>
29-
fetchResource(swaggerUiDir + "/swagger-ui.min.js", req, blocker)
29+
fetchResource(swaggerUiDir + "/swagger-ui.min.js", req)
3030
}
3131
}.toRoutes()
3232

33-
private def fetchResource(path: String, req: Request[IO], blocker: Blocker)(implicit
34-
cs: ContextShift[IO]): IO[Response[IO]] =
35-
StaticFile.fromResource(path, blocker, Some(req)).getOrElseF(NotFound())
33+
private def fetchResource(path: String, req: Request[IO]): IO[Response[IO]] =
34+
StaticFile.fromResource(path, Some(req)).getOrElseF(NotFound())
3635

3736
}

Diff for: project/Dependencies.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Keys._
33

44
// format: off
55
object Dependencies {
6-
val http4sVersion = "0.22.0-RC1"
6+
val http4sVersion = "0.23.0-RC1"
77
val specs2Version = "4.10.6"
88
val circeVersion = "0.14.1"
99

Diff for: swagger-ui/src/main/scala/com/http4s/rho/swagger/ui/SwaggerUi.scala

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.http4s.rho.swagger.ui
22

3-
import cats.effect.{Blocker, ContextShift, Sync}
3+
import cats.effect.{Sync}
44
import org.http4s.rho.bits.PathAST.{PathMatch, TypedPath}
55
import org.http4s.rho.swagger.models._
66
import org.http4s.rho.swagger.{
@@ -18,15 +18,12 @@ import scala.collection.immutable.Seq
1818
import scala.reflect.runtime.universe.WeakTypeTag
1919

2020
object SwaggerUi {
21-
def apply[F[_]: Sync: ContextShift](implicit etag: WeakTypeTag[F[_]]): SwaggerUi[F] =
22-
new SwaggerUi[F]()
21+
def apply[F[_]: Sync](implicit etag: WeakTypeTag[F[_]]): SwaggerUi[F] = new SwaggerUi[F]()
2322
}
2423

25-
class SwaggerUi[F[_]: Sync: ContextShift](implicit etag: WeakTypeTag[F[_]])
26-
extends SwaggerSyntax[F] {
24+
class SwaggerUi[F[_]: Sync](implicit etag: WeakTypeTag[F[_]]) extends SwaggerSyntax[F] {
2725

2826
def createRhoMiddleware(
29-
blocker: Blocker,
3027
swaggerFormats: SwaggerFormats = swagger.DefaultSwaggerFormats,
3128
swaggerSpecJsonPath: String = "swagger.json",
3229
swaggerSpecYamlPath: String = "swagger.yaml",
@@ -56,8 +53,7 @@ class SwaggerUi[F[_]: Sync: ContextShift](implicit etag: WeakTypeTag[F[_]])
5653
val relativeSwaggerSpecPath =
5754
("../" * s"$cleanSwaggerUiPath/".count(_ == '/')) + cleanSwaggerSpecPath
5855

59-
val swaggerUiRoutes =
60-
SwaggerUiRoutes[F](swaggerUiPath, relativeSwaggerSpecPath, blocker).getRoutes
56+
val swaggerUiRoutes = SwaggerUiRoutes[F](swaggerUiPath, relativeSwaggerSpecPath).getRoutes
6157

6258
routes ++ swaggerSpecRoute ++ swaggerUiRoutes
6359
}

Diff for: swagger-ui/src/main/scala/com/http4s/rho/swagger/ui/SwaggerUiRoutes.scala

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package com.http4s.rho.swagger.ui
22

3-
import cats.effect.{Blocker, ContextShift, Sync}
3+
import cats.effect.{Sync}
44
import cats.implicits._
55
import org.http4s.headers.`Content-Type`
66
import org.http4s.rho.RhoRoutes
77
import org.http4s.rho.bits.PathAST.CaptureTail
88
import org.http4s.rho.swagger.ui.BuildInfo
99
import org.http4s._
1010

11-
class SwaggerUiRoutes[F[_]: Sync: ContextShift](
11+
class SwaggerUiRoutes[F[_]: Sync](
1212
swaggerUiPath: String,
1313
swaggerUiResourcesPath: String,
14-
indexHtml: String,
15-
blocker: Blocker)
14+
indexHtml: String)
1615
extends RhoRoutes[F] {
1716

1817
private val htmlEncoder: EntityEncoder[F, String] =
@@ -35,20 +34,19 @@ class SwaggerUiRoutes[F[_]: Sync: ContextShift](
3534
}
3635

3736
private def fetchResource(path: String, req: Request[F]): F[Response[F]] =
38-
StaticFile.fromResource[F](path, blocker, Some(req)).getOrElseF(NotFound(()).map(_.resp))
37+
StaticFile.fromResource[F](path, Some(req)).getOrElseF(NotFound(()).map(_.resp))
3938

4039
}
4140

4241
object SwaggerUiRoutes {
4342

44-
def apply[F[_]: Sync: ContextShift](
43+
def apply[F[_]: Sync](
4544
swaggerUiPath: String,
46-
swaggerSpecRelativePath: String,
47-
blocker: Blocker): SwaggerUiRoutes[F] = {
45+
swaggerSpecRelativePath: String): SwaggerUiRoutes[F] = {
4846
val swaggerUiResourcesPath =
4947
s"/META-INF/resources/webjars/swagger-ui/${BuildInfo.swaggerUiVersion}/"
5048
val indexHtml = defaultIndexHtml(swaggerSpecRelativePath)
51-
new SwaggerUiRoutes[F](swaggerUiPath, swaggerUiResourcesPath, indexHtml, blocker)
49+
new SwaggerUiRoutes[F](swaggerUiPath, swaggerUiResourcesPath, indexHtml)
5250
}
5351

5452
def defaultIndexHtml(swaggerUrl: String): String =

Diff for: swagger/src/main/scala/org/http4s/rho/swagger/SwaggerSupport.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package rho
33
package swagger
44

55
import _root_.io.swagger.util.{Json, Yaml}
6-
import cats.effect.Sync
6+
import cats._
77
import org.http4s.headers.`Content-Type`
88
import org.http4s.rho.bits.PathAST.{PathMatch, TypedPath}
99
import org.http4s.rho.swagger.models._
@@ -13,11 +13,11 @@ import scala.reflect.runtime.universe._
1313
import scala.collection.immutable.Seq
1414

1515
object SwaggerSupport {
16-
def apply[F[_]: Sync](implicit etag: WeakTypeTag[F[_]]): SwaggerSupport[F] =
16+
def apply[F[_]: Monad](implicit etag: WeakTypeTag[F[_]]): SwaggerSupport[F] =
1717
new SwaggerSupport[F] {}
1818
}
1919

20-
abstract class SwaggerSupport[F[_]](implicit F: Sync[F], etag: WeakTypeTag[F[_]])
20+
abstract class SwaggerSupport[F[_]: Monad](implicit etag: WeakTypeTag[F[_]])
2121
extends SwaggerSyntax[F] {
2222

2323
/** Create a RhoMiddleware adding a route to get the Swagger JSON/YAML files

0 commit comments

Comments
 (0)