Skip to content

Commit

Permalink
Merge pull request #738 from http4s/update/main/http4s-core-1.0.0-M37
Browse files Browse the repository at this point in the history
Update http4s-client, ... to 1.0.0-M37 in main
  • Loading branch information
amesgen authored Sep 20, 2022
2 parents 4882655 + d135093 commit d03620f
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 103 deletions.
17 changes: 12 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ val catsV = "2.8.0"
val catsEffectV = "3.3.14"
val fs2V = "3.3.0"
val scodecV = "1.1.34"
val http4sV = "1.0.0-M36"
val http4sV = "1.0.0-M37"
val reactiveStreamsV = "1.0.4"
val vaultV = "3.3.0"
val caseInsensitiveV = "1.3.0"

val http4sBlazeV = "1.0-37710b7-SNAPSHOT"
val munitV = "0.7.29"
val munitCatsEffectV = "1.0.7"
val http4sBlazeV = "1.0.0-M36"
val munitV = "1.0.0-M6"
val munitCatsEffectV = "2.0.0-M3"
val javaWebsocketV = "1.5.3"

val blazeServer = Seq(
Expand All @@ -70,7 +70,7 @@ val coreDeps = Seq(
"org.http4s" %% "http4s-client-testkit" % http4sV,
"org.java-websocket" % "Java-WebSocket" % javaWebsocketV,
"org.scalameta" %% "munit" % munitV,
"org.typelevel" %% "munit-cats-effect-3" % munitCatsEffectV
"org.typelevel" %% "munit-cats-effect" % munitCatsEffectV
)).map(_ % Test)

val scala213 = "2.13.8"
Expand All @@ -91,6 +91,13 @@ ThisBuild / tlSitePublishBranch := Some("main")

ThisBuild / resolvers += "SOSSS".at("https://s01.oss.sonatype.org/content/repositories/snapshots")

ThisBuild / libraryDependencySchemes ++= Seq(
"org.http4s" %% "http4s-core" % "always",
"org.http4s" %% "http4s-server" % "always",
"org.http4s" %% "http4s-blaze-core" % "always",
"org.http4s" %% "http4s-blaze-server" % "always"
)

lazy val docsSettings =
Seq(
tlSiteApiModule := Some((core / projectID).value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ class JdkHttpClientSpec extends ClientRouteTestBattery("JdkHttpClient") {

// regression test for https://github.com/http4s/http4s-jdk-http-client/issues/395
test("Don't error with empty body and explicit Content-Length: 0") {
serverClient().flatMap { case (server, client) =>
val address = server().addresses.head
val path = GetRoutes.SimplePath
val uri = Uri.fromString(s"http://$address$path").toOption.get
val req: Request[IO] = Request(uri = uri)
.putHeaders(Header.Raw(ci"Content-Length", "0"))
val body = client().expect[String](req)
body.assertEquals("simple path")
}
val address = server().addresses.head
val path = GetRoutes.SimplePath
val uri = Uri.fromString(s"http://$address$path").toOption.get
val req: Request[IO] = Request(uri = uri)
.putHeaders(Header.Raw(ci"Content-Length", "0"))
val body = client().expect[String](req)
body.assertEquals("simple path")
}
}
177 changes: 88 additions & 89 deletions core/src/test/scala/org/http4s/jdkhttpclient/JdkWSClientSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import cats.effect._
import cats.implicits._
import fs2.Stream
import munit.CatsEffectSuite
import munit.catseffect.IOFixture
import org.http4s._
import org.http4s.blaze.server.BlazeServerBuilder
import org.http4s.client.websocket._
Expand All @@ -38,104 +39,102 @@ import scala.concurrent.duration._

class JdkWSClientSpec extends CatsEffectSuite {

val webSocket: Resource[IO, WSClient[IO]] = JdkWSClient.simple[IO]
val echoServer: Resource[IO, Uri] =
BlazeServerBuilder[IO]
.bindAny()
.withHttpWebSocketApp(wsb =>
HttpRoutes
.of[IO] { case GET -> Root => wsb.build(identity) }
.orNotFound
)
.resource
.map(s => httpToWsUri(s.baseUri))
val webSocket: IOFixture[WSClient[IO]] =
ResourceSuiteLocalFixture("webSocket", JdkWSClient.simple[IO])
val echoServerUri: IOFixture[Uri] =
ResourceSuiteLocalFixture(
"echoServerUri",
BlazeServerBuilder[IO]
.bindAny()
.withHttpWebSocketApp { wsb =>
HttpRoutes
.of[IO] { case GET -> Root => wsb.build(identity) }
.orNotFound
}
.resource
.map(s => httpToWsUri(s.baseUri))
)

val webSocketFixture: SyncIO[FunFixture[WSClient[IO]]] =
ResourceFixture(webSocket)
val webSocketEchoFixture: SyncIO[FunFixture[(WSClient[IO], Uri)]] =
ResourceFixture((webSocket, echoServer).tupled)
override def munitFixtures: Seq[IOFixture[_]] = List(webSocket, echoServerUri)

webSocketEchoFixture.test("send and receive frames in low-level mode") {
case (webSocket, echoUri) =>
webSocket
.connect(WSRequest(echoUri))
.use { conn =>
for {
_ <- conn.send(WSFrame.Text("bar"))
_ <- conn.sendMany(List(WSFrame.Binary(ByteVector(3, 99, 12)), WSFrame.Text("foo")))
_ <- conn.send(WSFrame.Close(1000, "goodbye"))
recv <- conn.receiveStream.compile.toList
} yield recv
}
.assertEquals(
List(
WSFrame.Text("bar"),
WSFrame.Binary(ByteVector(3, 99, 12)),
WSFrame.Text("foo"),
WSFrame.Close(1000, "goodbye")
)
test("send and receive frames in low-level mode") {
webSocket()
.connect(WSRequest(echoServerUri()))
.use { conn =>
for {
_ <- conn.send(WSFrame.Text("bar"))
_ <- conn.sendMany(List(WSFrame.Binary(ByteVector(3, 99, 12)), WSFrame.Text("foo")))
_ <- conn.send(WSFrame.Close(1000, "goodbye"))
recv <- conn.receiveStream.compile.toList
} yield recv
}
.assertEquals(
List(
WSFrame.Text("bar"),
WSFrame.Binary(ByteVector(3, 99, 12)),
WSFrame.Text("foo"),
WSFrame.Close(1000, "goodbye")
)
)
}

webSocketEchoFixture.test("send and receive frames in high-level mode") {
case (webSocket, echoUri) =>
webSocket
.connectHighLevel(WSRequest(echoUri))
.use { conn =>
for {
_ <- conn.send(WSFrame.Binary(ByteVector(15, 2, 3)))
_ <- conn.sendMany(List(WSFrame.Text("foo"), WSFrame.Text("bar")))
recv <- conn.receiveStream.take(3).compile.toList
} yield recv
}
.assertEquals(
List(
WSFrame.Binary(ByteVector(15, 2, 3)),
WSFrame.Text("foo"),
WSFrame.Text("bar")
)
test("send and receive frames in high-level mode") {
webSocket()
.connectHighLevel(WSRequest(echoServerUri()))
.use { conn =>
for {
_ <- conn.send(WSFrame.Binary(ByteVector(15, 2, 3)))
_ <- conn.sendMany(List(WSFrame.Text("foo"), WSFrame.Text("bar")))
recv <- conn.receiveStream.take(3).compile.toList
} yield recv
}
.assertEquals(
List(
WSFrame.Binary(ByteVector(15, 2, 3)),
WSFrame.Text("foo"),
WSFrame.Text("bar")
)
)
}

webSocketEchoFixture.test("group frames by their `last` attribute in high-level mode") {
case (webSocket, echoUri) =>
webSocket
.connectHighLevel(WSRequest(echoUri))
.use { conn =>
for {
_ <- conn.sendMany(
List(
WSFrame.Text("1", last = false),
WSFrame.Text("2", last = false),
WSFrame.Text("3"),
WSFrame.Binary(ByteVector(1)),
WSFrame.Binary(ByteVector(2), last = false),
WSFrame.Binary(ByteVector(3), last = false),
WSFrame.Binary(ByteVector(4)),
WSFrame.Text("4", last = false),
WSFrame.Text("5"),
WSFrame.Binary(ByteVector(5), last = false),
WSFrame.Binary(ByteVector(6)),
WSFrame.Text("6"),
WSFrame.Binary(ByteVector(7), last = false)
)
test("group frames by their `last` attribute in high-level mode") {
webSocket()
.connectHighLevel(WSRequest(echoServerUri()))
.use { conn =>
for {
_ <- conn.sendMany(
List(
WSFrame.Text("1", last = false),
WSFrame.Text("2", last = false),
WSFrame.Text("3"),
WSFrame.Binary(ByteVector(1)),
WSFrame.Binary(ByteVector(2), last = false),
WSFrame.Binary(ByteVector(3), last = false),
WSFrame.Binary(ByteVector(4)),
WSFrame.Text("4", last = false),
WSFrame.Text("5"),
WSFrame.Binary(ByteVector(5), last = false),
WSFrame.Binary(ByteVector(6)),
WSFrame.Text("6"),
WSFrame.Binary(ByteVector(7), last = false)
)
recv <- conn.receiveStream.take(6).compile.toList
} yield recv
}
.assertEquals(
List(
WSFrame.Text("123"),
WSFrame.Binary(ByteVector(1)),
WSFrame.Binary(ByteVector(2, 3, 4)),
WSFrame.Text("45"),
WSFrame.Binary(ByteVector(5, 6)),
WSFrame.Text("6")
)
recv <- conn.receiveStream.take(6).compile.toList
} yield recv
}
.assertEquals(
List(
WSFrame.Text("123"),
WSFrame.Binary(ByteVector(1)),
WSFrame.Binary(ByteVector(2, 3, 4)),
WSFrame.Text("45"),
WSFrame.Binary(ByteVector(5, 6)),
WSFrame.Text("6")
)
)
}

webSocketFixture.test("automatically close the connection") { webSocket =>
test("automatically close the connection") {
val frames = for {
ref <- Ref[IO].of(List.empty[WebSocketFrame])
finished <- Deferred[IO, Unit]
Expand All @@ -154,9 +153,9 @@ class JdkWSClientSpec extends CatsEffectSuite {
override def onStart() = {
val req = WSRequest(uri"ws://localhost:8080")
val p = for {
_ <- webSocket.connect(req).use(conn => conn.send(WSFrame.Text("hi blaze")))
_ <- webSocket().connect(req).use(conn => conn.send(WSFrame.Text("hi blaze")))
_ <- IO.sleep(1.seconds)
_ <- webSocket.connectHighLevel(req).use { conn =>
_ <- webSocket().connectHighLevel(req).use { conn =>
conn.send(WSFrame.Text("hey blaze"))
}
_ <- IO.sleep(1.seconds)
Expand All @@ -178,7 +177,7 @@ class JdkWSClientSpec extends CatsEffectSuite {
)
}

webSocketFixture.test("send headers") { webSocket =>
test("send headers") {
val sentHeaders = Headers(
Header.Raw(ci"foo", "bar"),
Header.Raw(ci"Sec-Websocket-Protocol", "proto"),
Expand All @@ -198,7 +197,7 @@ class JdkWSClientSpec extends CatsEffectSuite {
}
.resource
.use { server =>
webSocket
webSocket()
.connect(WSRequest(httpToWsUri(server.baseUri)).withHeaders(sentHeaders))
.use(_ => IO.unit)
} *> ref.get
Expand Down

0 comments on commit d03620f

Please sign in to comment.