diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c09327d44..7d2ac391f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,15 +34,18 @@ jobs: runs-on: ${{ matrix.os }} timeout-minutes: 60 steps: + - name: Install sbt + uses: sbt/setup-sbt@v1 + - name: Checkout current branch (full) - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup Java (temurin@8) id: setup-java-temurin-8 if: matrix.java == 'temurin@8' - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: temurin java-version: 8 @@ -91,7 +94,7 @@ jobs: - name: Upload target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }} path: targets.tar @@ -106,15 +109,18 @@ jobs: java: [temurin@8] runs-on: ${{ matrix.os }} steps: + - name: Install sbt + uses: sbt/setup-sbt@v1 + - name: Checkout current branch (full) - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup Java (temurin@8) id: setup-java-temurin-8 if: matrix.java == 'temurin@8' - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: temurin java-version: 8 @@ -125,7 +131,7 @@ jobs: run: sbt +update - name: Download target directories (3) - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: target-${{ matrix.os }}-${{ matrix.java }}-3 @@ -135,7 +141,7 @@ jobs: rm targets.tar - name: Download target directories (2.13) - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: target-${{ matrix.os }}-${{ matrix.java }}-2.13 @@ -149,7 +155,7 @@ jobs: env: PGP_SECRET: ${{ secrets.PGP_SECRET }} PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} - run: echo $PGP_SECRET | base64 -di | gpg --import + run: echo $PGP_SECRET | base64 -d -i - | gpg --import - name: Import signing key and strip passphrase if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE != '' @@ -157,7 +163,7 @@ jobs: PGP_SECRET: ${{ secrets.PGP_SECRET }} PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} run: | - echo "$PGP_SECRET" | base64 -di > /tmp/signing-key.gpg + echo "$PGP_SECRET" | base64 -d -i - > /tmp/signing-key.gpg echo "$PGP_PASSPHRASE" | gpg --pinentry-mode loopback --passphrase-fd 0 --import /tmp/signing-key.gpg (echo "$PGP_PASSPHRASE"; echo; echo) | gpg --command-fd 0 --pinentry-mode loopback --change-passphrase $(gpg --list-secret-keys --with-colons 2> /dev/null | grep '^sec:' | cut --delimiter ':' --fields 5 | tail -n 1) @@ -170,22 +176,25 @@ jobs: dependency-submission: name: Submit Dependencies - if: github.event_name != 'pull_request' + if: github.event.repository.fork == false && github.event_name != 'pull_request' strategy: matrix: os: [ubuntu-latest] java: [temurin@8] runs-on: ${{ matrix.os }} steps: + - name: Install sbt + uses: sbt/setup-sbt@v1 + - name: Checkout current branch (full) - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup Java (temurin@8) id: setup-java-temurin-8 if: matrix.java == 'temurin@8' - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: temurin java-version: 8 @@ -210,12 +219,12 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout current branch (fast) - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Java (temurin@11) id: setup-java-temurin-11 if: matrix.java == 'temurin@11' - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: temurin java-version: 11 diff --git a/blaze-client/src/main/scala/org/http4s/blaze/client/Http1Connection.scala b/blaze-client/src/main/scala/org/http4s/blaze/client/Http1Connection.scala index 919cae4db..a4714d8be 100644 --- a/blaze-client/src/main/scala/org/http4s/blaze/client/Http1Connection.scala +++ b/blaze-client/src/main/scala/org/http4s/blaze/client/Http1Connection.scala @@ -31,6 +31,7 @@ import org.http4s.Uri.RegName import org.http4s.blaze.core.Http1Stage import org.http4s.blaze.core.IdleTimeoutStage import org.http4s.blaze.core.util.Http1Writer +import org.http4s.blaze.core.util.NullWriter import org.http4s.blaze.pipeline.Command.EOF import org.http4s.client.RequestKey import org.http4s.headers.Host @@ -200,10 +201,8 @@ private final class Http1Connection[F[_]]( if (userAgent.nonEmpty && !req.headers.contains[`User-Agent`]) rr << userAgent.get << "\r\n" - val mustClose: Boolean = req.headers.get[HConnection] match { - case Some(conn) => checkCloseConnection(conn, rr) - case None => getHttpMinor(req) == 0 - } + val mustClose: Boolean = + checkRequestCloseConnection(req.headers.get[HConnection], getHttpMinor(req), NullWriter) val writeRequest: F[Boolean] = getChunkEncoder(req, mustClose, rr) .write(rr, req.entity) diff --git a/blaze-client/src/test/scala/org/http4s/blaze/client/BlazeClientBase.scala b/blaze-client/src/test/scala/org/http4s/blaze/client/BlazeClientBase.scala index 9fdcb82a2..609a42fff 100644 --- a/blaze-client/src/test/scala/org/http4s/blaze/client/BlazeClientBase.scala +++ b/blaze-client/src/test/scala/org/http4s/blaze/client/BlazeClientBase.scala @@ -20,7 +20,6 @@ package client import cats.effect._ import cats.effect.kernel.Resource import cats.effect.std.Dispatcher -import cats.implicits.catsSyntaxApplicativeId import cats.syntax.all._ import fs2.Stream import io.netty.channel.ChannelHandlerContext @@ -141,9 +140,9 @@ trait BlazeClientBase extends CatsEffectSuite { ) val server: IOFixture[ServerScaffold[IO]] = - ResourceSuiteLocalFixture("http", makeScaffold(2, false)) + ResourceSuiteLocalFixture("http", makeScaffold(2, secure = false)) val secureServer: IOFixture[ServerScaffold[IO]] = - ResourceSuiteLocalFixture("https", makeScaffold(1, true)) + ResourceSuiteLocalFixture("https", makeScaffold(1, secure = true)) override val munitFixtures = List( server, diff --git a/blaze-client/src/test/scala/org/http4s/blaze/client/BlazeClientSuite.scala b/blaze-client/src/test/scala/org/http4s/blaze/client/BlazeClientSuite.scala index 75bb7c412..e09d4f440 100644 --- a/blaze-client/src/test/scala/org/http4s/blaze/client/BlazeClientSuite.scala +++ b/blaze-client/src/test/scala/org/http4s/blaze/client/BlazeClientSuite.scala @@ -317,7 +317,7 @@ class BlazeClientSuite extends BlazeClientBase { } override def onRequestEnd(ctx: ChannelHandlerContext, request: HttpRequest): Unit = () }) - ServerScaffold[IO](1, false, HandlersToNettyAdapter[IO](handlers)).use { server => + ServerScaffold[IO](1, secure = false, HandlersToNettyAdapter[IO](handlers)).use { server => val address = server.addresses.head val name = address.host val port = address.port @@ -343,7 +343,7 @@ class BlazeClientSuite extends BlazeClientBase { } override def onRequestEnd(ctx: ChannelHandlerContext, request: HttpRequest): Unit = () }) - ServerScaffold[IO](1, false, HandlersToNettyAdapter[IO](handlers)).use { server => + ServerScaffold[IO](1, secure = false, HandlersToNettyAdapter[IO](handlers)).use { server => val address = server.addresses.head val name = address.host val port = address.port @@ -366,7 +366,7 @@ class BlazeClientSuite extends BlazeClientBase { } override def onRequestEnd(ctx: ChannelHandlerContext, request: HttpRequest): Unit = () }) - ServerScaffold[IO](1, false, HandlersToNettyAdapter[IO](handlers)).use { server => + ServerScaffold[IO](1, secure = false, HandlersToNettyAdapter[IO](handlers)).use { server => val address = server.addresses.head val name = address.host val port = address.port diff --git a/blaze-client/src/test/scala/org/http4s/blaze/client/Http1ClientStageSuite.scala b/blaze-client/src/test/scala/org/http4s/blaze/client/Http1ClientStageSuite.scala index 513499d33..bdc5af5c2 100644 --- a/blaze-client/src/test/scala/org/http4s/blaze/client/Http1ClientStageSuite.scala +++ b/blaze-client/src/test/scala/org/http4s/blaze/client/Http1ClientStageSuite.scala @@ -22,7 +22,6 @@ import cats.effect._ import cats.effect.kernel.Deferred import cats.effect.std.Dispatcher import cats.effect.std.Queue -import cats.syntax.all._ import fs2.Stream import munit.CatsEffectSuite import org.http4s.BuildInfo diff --git a/blaze-core/src/main/scala/org/http4s/blaze/core/Http1Stage.scala b/blaze-core/src/main/scala/org/http4s/blaze/core/Http1Stage.scala index bb8b00aa4..56880aaef 100644 --- a/blaze-core/src/main/scala/org/http4s/blaze/core/Http1Stage.scala +++ b/blaze-core/src/main/scala/org/http4s/blaze/core/Http1Stage.scala @@ -67,6 +67,7 @@ private[blaze] trait Http1Stage[F[_]] { self: TailStage[ByteBuffer] => protected def contentComplete(): Boolean /** Check Connection header and add applicable headers to response */ + @deprecated("Use checkConnectionPersistence(Option[Connection], Int, Writer) instead", "0.23.17") protected final def checkCloseConnection(conn: Connection, rr: StringWriter): Boolean = if (conn.hasKeepAlive) { // connection, look to the request logger.trace("Found Keep-Alive header") @@ -83,6 +84,42 @@ private[blaze] trait Http1Stage[F[_]] { self: TailStage[ByteBuffer] => true } + /** Checks whether the connection should be closed per the request's Connection header + * and the HTTP version. + * + * As a side effect, writes a "Connection: close" header to the StringWriter if + * the request explicitly requests the connection is closed. + * + * @see [[https://datatracker.ietf.org/doc/html/rfc9112#name-persistence RFC 9112, Section 9.3, Persistence]] + */ + private[http4s] final def checkRequestCloseConnection( + conn: Option[Connection], + minorVersion: Int, + rr: Writer, + ): Boolean = + if (conn.fold(false)(_.hasClose)) { + logger.trace(s"Closing ${conn} due to explicit close option in request's Connection header") + // This side effect doesn't really belong here, but is relied + // upon in multiple places as we look for the encoder. The + // related problem of writing the keep-alive header in HTTP/1.0 + // is handled elsewhere. + if (minorVersion >= 1) { + rr << "Connection: close\r\n" + } + true + } else if (minorVersion >= 1) { + logger.trace(s"Keeping ${conn} alive per default behavior of HTTP >= 1.1") + false + } else if (conn.fold(false)(_.hasKeepAlive)) { + logger.trace( + s"Keeping ${conn} alive due to explicit keep-alive option in request's Connection header" + ) + false + } else { + logger.trace(s"Closing ${conn} per default behavior of HTTP/1.0") + true + } + /** Get the proper body encoder based on the request */ protected final def getEncoder( req: Request[F], diff --git a/blaze-core/src/main/scala/org/http4s/blaze/core/util/CachingChunkWriter.scala b/blaze-core/src/main/scala/org/http4s/blaze/core/util/CachingChunkWriter.scala index 138f9fe03..e927fb172 100644 --- a/blaze-core/src/main/scala/org/http4s/blaze/core/util/CachingChunkWriter.scala +++ b/blaze-core/src/main/scala/org/http4s/blaze/core/util/CachingChunkWriter.scala @@ -103,7 +103,7 @@ private[blaze] class CachingChunkWriter[F[_]]( pipe.channelWrite(hbuff) } } else if (!chunk.isEmpty) { - writeBodyChunk(chunk, true).flatMap { _ => + writeBodyChunk(chunk, flush = true).flatMap { _ => writeTrailer(pipe, trailer) } } else { diff --git a/blaze-core/src/main/scala/org/http4s/blaze/core/util/FlushingChunkWriter.scala b/blaze-core/src/main/scala/org/http4s/blaze/core/util/FlushingChunkWriter.scala index d3a78d9d1..1f37104e5 100644 --- a/blaze-core/src/main/scala/org/http4s/blaze/core/util/FlushingChunkWriter.scala +++ b/blaze-core/src/main/scala/org/http4s/blaze/core/util/FlushingChunkWriter.scala @@ -40,7 +40,7 @@ private[blaze] class FlushingChunkWriter[F[_]](pipe: TailStage[ByteBuffer], trai else pipe.channelWrite(encodeChunk(chunk, Nil)) protected def writeEnd(chunk: Chunk[Byte]): Future[Boolean] = { - if (!chunk.isEmpty) writeBodyChunk(chunk, true).flatMap { _ => + if (!chunk.isEmpty) writeBodyChunk(chunk, flush = true).flatMap { _ => writeTrailer(pipe, trailer) } else writeTrailer(pipe, trailer) diff --git a/blaze-core/src/main/scala/org/http4s/blaze/core/util/NullWriter.scala b/blaze-core/src/main/scala/org/http4s/blaze/core/util/NullWriter.scala new file mode 100644 index 000000000..48f708a7c --- /dev/null +++ b/blaze-core/src/main/scala/org/http4s/blaze/core/util/NullWriter.scala @@ -0,0 +1,27 @@ +/* + * Copyright 2014 http4s.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.http4s +package blaze.core.util + +import org.http4s.util.Writer + +/** A writer that does not write. Not to be confused with an + * [[EntityBodyWriter]]. + */ +private[http4s] object NullWriter extends Writer { + def append(s: String): NullWriter.type = NullWriter +} diff --git a/blaze-core/src/test/scala/org/http4s/blaze/core/util/Http1WriterSpec.scala b/blaze-core/src/test/scala/org/http4s/blaze/core/util/Http1WriterSpec.scala index 65f3340e4..19dd86c85 100644 --- a/blaze-core/src/test/scala/org/http4s/blaze/core/util/Http1WriterSpec.scala +++ b/blaze-core/src/test/scala/org/http4s/blaze/core/util/Http1WriterSpec.scala @@ -133,13 +133,25 @@ class Http1WriterSpec extends CatsEffectSuite with DispatcherIOFixture { runNonChunkedTests( "CachingChunkWriter", implicit dispatcher => - tail => new CachingChunkWriter[IO](tail, IO.pure(Headers.empty), 1024 * 1024, false), + tail => + new CachingChunkWriter[IO]( + tail, + IO.pure(Headers.empty), + 1024 * 1024, + omitEmptyContentLength = false, + ), ) runNonChunkedTests( "CachingStaticWriter", implicit dispatcher => - tail => new CachingChunkWriter[IO](tail, IO.pure(Headers.empty), 1024 * 1024, false), + tail => + new CachingChunkWriter[IO]( + tail, + IO.pure(Headers.empty), + 1024 * 1024, + omitEmptyContentLength = false, + ), ) def builder(tail: TailStage[ByteBuffer])(implicit D: Dispatcher[IO]): FlushingChunkWriter[IO] = diff --git a/blaze-server/src/main/scala/org/http4s/blaze/server/Http1ServerStage.scala b/blaze-server/src/main/scala/org/http4s/blaze/server/Http1ServerStage.scala index f17124bf5..202f41ecd 100644 --- a/blaze-server/src/main/scala/org/http4s/blaze/server/Http1ServerStage.scala +++ b/blaze-server/src/main/scala/org/http4s/blaze/server/Http1ServerStage.scala @@ -245,12 +245,9 @@ private[blaze] class Http1ServerStage[F[_]]( // Need to decide which encoder and if to close on finish val closeOnFinish = respConn .map(_.hasClose) - .orElse { - req.headers.get[Connection].map(checkCloseConnection(_, rr)) - } .getOrElse( - parser.minorVersion() == 0 - ) // Finally, if nobody specifies, http 1.0 defaults to close + checkRequestCloseConnection(req.headers.get[Connection], parser.minorVersion(), rr) + ) // choose a body encoder. Will add a Transfer-Encoding header if necessary val bodyEncoder: Http1Writer[F] = @@ -289,7 +286,7 @@ private[blaze] class Http1ServerStage[F[_]]( rr, parser.minorVersion(), closeOnFinish, - false, + omitEmptyContentLength = false, ) // TODO: pool shifting: https://github.com/http4s/http4s/blob/main/core/src/main/scala/org/http4s/internal/package.scala#L45 diff --git a/blaze-server/src/main/scala/org/http4s/blaze/server/WebSocketSupport.scala b/blaze-server/src/main/scala/org/http4s/blaze/server/WebSocketSupport.scala index 296138180..c636e9a4d 100644 --- a/blaze-server/src/main/scala/org/http4s/blaze/server/WebSocketSupport.scala +++ b/blaze-server/src/main/scala/org/http4s/blaze/server/WebSocketSupport.scala @@ -116,7 +116,7 @@ private[http4s] trait WebSocketSupport[F[_]] extends Http1ServerStage[F] { .prepend(new WSFrameAggregator) .prepend(new WebSocketDecoder(maxBufferSize.getOrElse(0))) - this.replaceTail(segment, true) + this.replaceTail(segment, startup = true) case Failure(t) => fatalError(t, "Error writing Websocket upgrade response") }(executionContext) diff --git a/blaze-server/src/test/scala/org/http4s/blaze/server/BlazeServerMtlsSpec.scala b/blaze-server/src/test/scala/org/http4s/blaze/server/BlazeServerMtlsSpec.scala index 73f2da046..e409d6bb6 100644 --- a/blaze-server/src/test/scala/org/http4s/blaze/server/BlazeServerMtlsSpec.scala +++ b/blaze-server/src/test/scala/org/http4s/blaze/server/BlazeServerMtlsSpec.scala @@ -153,23 +153,26 @@ class BlazeServerMtlsSpec extends CatsEffectSuite { */ blazeServer(TLSParameters(needClientAuth = true).toSSLParameters) .test("Server should send mTLS request correctly") { server => - assertEquals(get(server, "/dummy", true), "CN=Test,OU=Test,O=Test,L=CA,ST=CA,C=US") + assertEquals(get(server, "/dummy"), "CN=Test,OU=Test,O=Test,L=CA,ST=CA,C=US") } blazeServer(TLSParameters(needClientAuth = true).toSSLParameters) .test("Server should fail for invalid client auth") { server => - assertNotEquals(get(server, "/dummy", false), "CN=Test,OU=Test,O=Test,L=CA,ST=CA,C=US") + assertNotEquals( + get(server, "/dummy", clientAuth = false), + "CN=Test,OU=Test,O=Test,L=CA,ST=CA,C=US", + ) } /** Test "requested" auth mode */ blazeServer(TLSParameters(wantClientAuth = true).toSSLParameters) .test("Server should send mTLS request correctly with optional auth") { server => - assertEquals(get(server, "/dummy", true), "CN=Test,OU=Test,O=Test,L=CA,ST=CA,C=US") + assertEquals(get(server, "/dummy"), "CN=Test,OU=Test,O=Test,L=CA,ST=CA,C=US") } blazeServer(TLSParameters(wantClientAuth = true).toSSLParameters) .test("Server should send mTLS request correctly without clientAuth") { server => - assertEquals(get(server, "/noauth", false), "success") + assertEquals(get(server, "/noauth", clientAuth = false), "success") } } diff --git a/blaze-server/src/test/scala/org/http4s/blaze/server/BlazeServerSuite.scala b/blaze-server/src/test/scala/org/http4s/blaze/server/BlazeServerSuite.scala index afda90fdb..2efd9251e 100644 --- a/blaze-server/src/test/scala/org/http4s/blaze/server/BlazeServerSuite.scala +++ b/blaze-server/src/test/scala/org/http4s/blaze/server/BlazeServerSuite.scala @@ -56,7 +56,7 @@ class BlazeServerSuite extends CatsEffectSuite { val s = new ScheduledThreadPoolExecutor( 2, - threadFactory(i => s"blaze-server-suite-scheduler-$i", true), + threadFactory(i => s"blaze-server-suite-scheduler-$i", daemon = true), ) s.setKeepAliveTime(10L, TimeUnit.SECONDS) s.allowCoreThreadTimeOut(true) diff --git a/blaze-server/src/test/scala/org/http4s/blaze/server/Http1ServerStageSpec.scala b/blaze-server/src/test/scala/org/http4s/blaze/server/Http1ServerStageSpec.scala index fcd9e0b88..9e9694aab 100644 --- a/blaze-server/src/test/scala/org/http4s/blaze/server/Http1ServerStageSpec.scala +++ b/blaze-server/src/test/scala/org/http4s/blaze/server/Http1ServerStageSpec.scala @@ -279,8 +279,8 @@ class Http1ServerStageSpec extends CatsEffectSuite { fixture.test("Http1ServerStage: routes should Add a date header") { tw => val routes = HttpRoutes - .of[IO] { case req => - IO.pure(Response(entity = req.entity)) + .of[IO] { case r => + IO.pure(Response(entity = r.entity)) } .orNotFound @@ -297,8 +297,8 @@ class Http1ServerStageSpec extends CatsEffectSuite { fixture.test("Http1ServerStage: routes should Honor an explicitly added date header") { tw => val dateHeader = Date(HttpDate.Epoch) val routes = HttpRoutes - .of[IO] { case req => - IO.pure(Response(entity = req.entity).withHeaders(dateHeader)) + .of[IO] { case r => + IO.pure(Response(entity = r.entity).withHeaders(dateHeader)) } .orNotFound @@ -318,8 +318,8 @@ class Http1ServerStageSpec extends CatsEffectSuite { "Http1ServerStage: routes should Handle routes that echos full request body for non-chunked" ) { tw => val routes = HttpRoutes - .of[IO] { case req => - IO.pure(Response(entity = req.entity)) + .of[IO] { case r => + IO.pure(Response(entity = r.entity)) } .orNotFound @@ -340,8 +340,8 @@ class Http1ServerStageSpec extends CatsEffectSuite { "Http1ServerStage: routes should Handle routes that consumes the full request body for non-chunked" ) { tw => val routes = HttpRoutes - .of[IO] { case req => - req.as[String].map { s => + .of[IO] { case r => + r.as[String].map { s => Response().withEntity("Result: " + s) } } @@ -421,8 +421,8 @@ class Http1ServerStageSpec extends CatsEffectSuite { "Http1ServerStage: routes should Handle routes that runs the request body for non-chunked" ) { tw => val routes = HttpRoutes - .of[IO] { case req => - req.body.compile.drain *> IO.pure(Response().withEntity("foo")) + .of[IO] { case r => + r.body.compile.drain *> IO.pure(Response().withEntity("foo")) } .orNotFound @@ -446,8 +446,8 @@ class Http1ServerStageSpec extends CatsEffectSuite { fixture.test("Http1ServerStage: routes should Not die when two requests come in back to back") { tw => val routes = HttpRoutes - .of[IO] { case req => - IO.pure(Response(entity = req.entity)) + .of[IO] { case r => + IO.pure(Response(entity = r.entity)) } .orNotFound @@ -472,8 +472,8 @@ class Http1ServerStageSpec extends CatsEffectSuite { "Http1ServerStage: routes should Handle using the request body as the response body" ) { tw => val routes = HttpRoutes - .of[IO] { case req => - IO.pure(Response(entity = req.entity)) + .of[IO] { case r => + IO.pure(Response(entity = r.entity)) } .orNotFound @@ -503,17 +503,17 @@ class Http1ServerStageSpec extends CatsEffectSuite { private val routes2 = HttpRoutes .of[IO] { - case req if req.pathInfo === path"/foo" => + case r if r.pathInfo === path"/foo" => for { - _ <- req.body.compile.drain - hs <- req.trailerHeaders + _ <- r.body.compile.drain + hs <- r.trailerHeaders resp <- Ok(hs.headers.mkString) } yield resp - case req if req.pathInfo === path"/bar" => + case r if r.pathInfo === path"/bar" => for { // Don't run the body - hs <- req.trailerHeaders + hs <- r.trailerHeaders resp <- Ok(hs.headers.mkString) } yield resp } @@ -605,7 +605,7 @@ class Http1ServerStageSpec extends CatsEffectSuite { cancelableStarted <- Deferred[IO, Unit] cancelableCanceled <- Deferred[IO, Unit] app = HttpApp[IO] { - case req if req.pathInfo === path"/uncancelable" => + case r if r.pathInfo === path"/uncancelable" => uncancelableStarted.complete(()) *> IO.uncancelable { poll => poll(uncancelableCanceled.complete(())) *> diff --git a/blaze-server/src/test/scala/org/http4s/blaze/server/ServerTestRoutes.scala b/blaze-server/src/test/scala/org/http4s/blaze/server/ServerTestRoutes.scala index 832001d32..c81bff726 100644 --- a/blaze-server/src/test/scala/org/http4s/blaze/server/ServerTestRoutes.scala +++ b/blaze-server/src/test/scala/org/http4s/blaze/server/ServerTestRoutes.scala @@ -57,13 +57,19 @@ object ServerTestRoutes extends Http4sDsl[IO] { // /////////////////////////////// ( "GET /get HTTP/1.0\r\nConnection:close\r\n\r\n", - (Status.Ok, Set(length(3), textPlain, connClose), "get"), + (Status.Ok, Set(length(3), textPlain), "get"), ), // /////////////////////////////// ( "GET /get HTTP/1.1\r\nConnection:close\r\n\r\n", (Status.Ok, Set(length(3), textPlain, connClose), "get"), ), + // /////////////////////////////// + // Don't close connection on an unrecognized Connection header + ( + "GET /get HTTP/1.1\r\nConnection: fiddle-faddle\r\n\r\n", + (Status.Ok, Set(length(3), textPlain), "get"), + ), ("GET /chunked HTTP/1.1\r\n\r\n", (Status.Ok, Set(textPlain, chunked), "chunk")), // /////////////////////////////// ( @@ -75,7 +81,7 @@ object ServerTestRoutes extends Http4sDsl[IO] { // /////////////////////////////// ( "GET /chunked HTTP/1.0\r\nConnection:Close\r\n\r\n", - (Status.Ok, Set(textPlain, connClose), "chunk"), + (Status.Ok, Set(textPlain), "chunk"), ), // ////////////////////////////// Requests with a body ////////////////////////////////////// ( @@ -90,7 +96,7 @@ object ServerTestRoutes extends Http4sDsl[IO] { // /////////////////////////////// ( "POST /post HTTP/1.0\r\nConnection:close\r\nContent-Length:3\r\n\r\nfoo", - (Status.Ok, Set(textPlain, length(4), connClose), "post"), + (Status.Ok, Set(textPlain, length(4)), "post"), ), // /////////////////////////////// ( @@ -119,7 +125,7 @@ object ServerTestRoutes extends Http4sDsl[IO] { // /////////////////////////////// Check corner cases ////////////////// ( "GET /twocodings HTTP/1.0\r\nConnection:Close\r\n\r\n", - (Status.Ok, Set(textPlain, length(3), connClose), "Foo"), + (Status.Ok, Set(textPlain, length(3)), "Foo"), ), // /////////////// Work with examples that don't have a body ////////////////////// ("GET /notmodified HTTP/1.1\r\n\r\n", (Status.NotModified, Set(), "")), diff --git a/build.sbt b/build.sbt index a94ad32db..d2aabd6ce 100644 --- a/build.sbt +++ b/build.sbt @@ -1,8 +1,8 @@ import Dependencies._ -val Scala213 = "2.13.11" -val Scala3 = "3.3.1" -val http4sVersion = "1.0.0-M43" +val Scala213 = "2.13.15" +val Scala3 = "3.3.4" +val http4sVersion = "1.0.0-M44" val log4catsVersion = "2.7.0" val munitCatsEffectVersion = "2.0.0" @@ -147,7 +147,7 @@ lazy val examples = Project("blaze-examples", file("examples")) libraryDependencies ++= Seq( "org.http4s" %% "http4s-dsl" % http4sVersion, "org.http4s" %% "http4s-circe" % http4sVersion, - "io.circe" %% "circe-generic" % "0.14.6", + "io.circe" %% "circe-generic" % "0.14.10", "org.typelevel" %% "log4cats-slf4j" % log4catsVersion, ), Test / scalafixConfig := Some(file(".scalafix.test.conf")), diff --git a/core/src/test/scala/org/http4s/blaze/util/BufferToolsSuite.scala b/core/src/test/scala/org/http4s/blaze/util/BufferToolsSuite.scala index 6b2e8a6b7..5cfee8d40 100644 --- a/core/src/test/scala/org/http4s/blaze/util/BufferToolsSuite.scala +++ b/core/src/test/scala/org/http4s/blaze/util/BufferToolsSuite.scala @@ -325,9 +325,9 @@ class BufferToolsSuite extends FunSuite { assert(BufferTools.areDirectOrEmpty(buffs)) } - private def getBuffers(count: Int): Array[ByteBuffer] = getBuffersBase(count, false) + private def getBuffers(count: Int): Array[ByteBuffer] = getBuffersBase(count, direct = false) - private def getDirect(count: Int): Array[ByteBuffer] = getBuffersBase(count, true) + private def getDirect(count: Int): Array[ByteBuffer] = getBuffersBase(count, direct = true) private def getBuffersBase(count: Int, direct: Boolean): Array[ByteBuffer] = (0 until count).map { _ => diff --git a/examples/src/main/scala/com/example/http4s/blaze/demo/client/StreamClient.scala b/examples/src/main/scala/com/example/http4s/blaze/demo/client/StreamClient.scala index d01ca4aa1..2a61a058d 100644 --- a/examples/src/main/scala/com/example/http4s/blaze/demo/client/StreamClient.scala +++ b/examples/src/main/scala/com/example/http4s/blaze/demo/client/StreamClient.scala @@ -38,7 +38,7 @@ object StreamClient extends IOApp { class HttpClient[F[_]](implicit F: Async[F], S: StreamUtils[F], lf: LoggerFactory[F]) { implicit val jsonFacade: Facade[Json] = - new io.circe.jawn.CirceSupportParser(None, false).facade + new io.circe.jawn.CirceSupportParser(None, allowDuplicateKeys = false).facade def run: F[Unit] = BlazeClientBuilder[F].stream diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/HeaderAggregatingFrameListener.scala b/http/src/main/scala/org/http4s/blaze/http/http2/HeaderAggregatingFrameListener.scala index bd9d217ba..90d4097cd 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/HeaderAggregatingFrameListener.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/HeaderAggregatingFrameListener.scala @@ -109,7 +109,7 @@ private abstract class HeaderAggregatingFrameListener( else if (buffer.remaining > localSettings.maxHeaderListSize) headerSizeError(buffer.remaining, streamId) else if (endHeaders) { - val r = headerDecoder.decode(buffer, streamId, true) + val r = headerDecoder.decode(buffer, streamId, endHeaders = true) if (!r.success) r else { val hs = headerDecoder.finish() @@ -129,7 +129,7 @@ private abstract class HeaderAggregatingFrameListener( if (localSettings.maxHeaderListSize < buffer.remaining) headerSizeError(buffer.remaining, streamId) else if (endHeaders) { - val r = headerDecoder.decode(buffer, streamId, true) + val r = headerDecoder.decode(buffer, streamId, endHeaders = true) if (!r.success) r else { val hs = headerDecoder.finish() @@ -157,7 +157,7 @@ private abstract class HeaderAggregatingFrameListener( val newBuffer = BufferTools.concatBuffers(hInfo.buffer, buffer) if (endHeaders) { - val r = headerDecoder.decode(newBuffer, streamId, true) + val r = headerDecoder.decode(newBuffer, streamId, endHeaders = true) if (!r.success) r else { val hs = headerDecoder.finish() diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/server/ALPNServerSelector.scala b/http/src/main/scala/org/http4s/blaze/http/http2/server/ALPNServerSelector.scala index 322f4d5b4..9d0cc6448 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/server/ALPNServerSelector.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/server/ALPNServerSelector.scala @@ -69,7 +69,7 @@ final class ALPNServerSelector( try { val protocol = Option(engine.getApplicationProtocol()).getOrElse(selector(Set.empty)) val b = builder(protocol) - this.replaceTail(b, true) + this.replaceTail(b, startup = true) () } catch { case NonFatal(t) => diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/server/ServerPriorKnowledgeHandshaker.scala b/http/src/main/scala/org/http4s/blaze/http/http2/server/ServerPriorKnowledgeHandshaker.scala index 21eba12d1..07a2dfbca 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/server/ServerPriorKnowledgeHandshaker.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/server/ServerPriorKnowledgeHandshaker.scala @@ -74,7 +74,7 @@ final class ServerPriorKnowledgeHandshaker( // We may have some extra data that we need to inject into the pipeline newTail = newTail.prepend(new OneMessageStage[ByteBuffer](remainder)) - this.replaceTail(newTail, true) + this.replaceTail(newTail, startup = true) // The session starts itself up and drives the pipeline new ConnectionImpl( diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/ConnectionImplSuite.scala b/http/src/test/scala/org/http4s/blaze/http/http2/ConnectionImplSuite.scala index c8510154a..7841d4325 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/ConnectionImplSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/ConnectionImplSuite.scala @@ -100,7 +100,7 @@ class ConnectionImplSuite extends BlazeTestSuite { val stream = connection.newOutboundStream() val tail = new BasicTail[StreamFrame]("tail") LeafBuilder(tail).base(stream) - tail.channelWrite(HeadersFrame(Priority.NoPriority, true, Seq.empty)) + tail.channelWrite(HeadersFrame(Priority.NoPriority, endStream = true, Seq.empty)) assertEquals(connection.quality, 0.5) } @@ -242,7 +242,7 @@ class ConnectionImplSuite extends BlazeTestSuite { connection.invokeGoAway(connection.idManager.lastOutboundStream, err) head.consumeOutboundByteBuf() // need to consume the GOAWAY - val w2 = basicStage.channelWrite(DataFrame(true, BufferTools.emptyBuffer)) + val w2 = basicStage.channelWrite(DataFrame(endStream = true, BufferTools.emptyBuffer)) assertEquals(w2.value, Some(Success(()))) } @@ -255,7 +255,7 @@ class ConnectionImplSuite extends BlazeTestSuite { val stage = connection.newOutboundStream() val basicStage = new BasicTail[StreamFrame]("") LeafBuilder(basicStage).base(stage) - val f = basicStage.channelWrite(HeadersFrame(Priority.NoPriority, true, Seq.empty)) + val f = basicStage.channelWrite(HeadersFrame(Priority.NoPriority, endStream = true, Seq.empty)) f.value match { case Some(Failure(t: Http2StreamException)) => @@ -299,7 +299,7 @@ class ConnectionImplSuite extends BlazeTestSuite { connection.invokeDrain(4.seconds) head.consumeOutboundByteBuf() // need to consume the GOAWAY - val w2 = basicStage.channelWrite(DataFrame(true, BufferTools.emptyBuffer)) + val w2 = basicStage.channelWrite(DataFrame(endStream = true, BufferTools.emptyBuffer)) assertEquals(w2.value, Some(Success(()))) } @@ -312,7 +312,7 @@ class ConnectionImplSuite extends BlazeTestSuite { val stage = connection.newOutboundStream() val basicStage = new BasicTail[StreamFrame]("") LeafBuilder(basicStage).base(stage) - val f = basicStage.channelWrite(HeadersFrame(Priority.NoPriority, true, Seq.empty)) + val f = basicStage.channelWrite(HeadersFrame(Priority.NoPriority, endStream = true, Seq.empty)) f.value match { case Some(Failure(t: Http2StreamException)) => assertEquals(t.code, Http2Exception.REFUSED_STREAM.code) diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/FrameDecoderSuite.scala b/http/src/test/scala/org/http4s/blaze/http/http2/FrameDecoderSuite.scala index 0c00b59b0..c24859812 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/FrameDecoderSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/FrameDecoderSuite.scala @@ -28,7 +28,7 @@ class FrameDecoderSuite extends BlazeTestSuite { def buffer(data: Byte*): ByteBuffer = ByteBuffer.wrap(data.toArray) - private class DataListener extends MockFrameListener(false) { + private class DataListener extends MockFrameListener(inHeaders = false) { var streamId: Option[Int] = None var endStream: Option[Boolean] = None var data: ByteBuffer = null @@ -232,7 +232,7 @@ class FrameDecoderSuite extends BlazeTestSuite { } } - private class HeadersListener extends MockFrameListener(false) { + private class HeadersListener extends MockFrameListener(inHeaders = false) { // For handling unknown stream frames var streamId: Option[Int] = None var priority: Option[Priority] = None @@ -312,7 +312,7 @@ class FrameDecoderSuite extends BlazeTestSuite { assertEquals(dec.decodeBuffer(testData), Continue) assertEquals(listener.streamId, Some(1)) - assertEquals(listener.priority, Some(Priority.Dependent(2, true, 256))) + assertEquals(listener.priority, Some(Priority.Dependent(2, exclusive = true, 256))) assertEquals(listener.endHeaders, Some(false)) assertEquals(listener.endStream, Some(false)) assertEquals(listener.buffer, ByteBuffer.wrap(new Array(3))) @@ -376,7 +376,7 @@ class FrameDecoderSuite extends BlazeTestSuite { assertEquals(dec.decodeBuffer(testData), Continue) assertEquals(listener.streamId, Some(1)) - assertEquals(listener.priority, Some(Priority.Dependent(2, false, 3))) + assertEquals(listener.priority, Some(Priority.Dependent(2, exclusive = false, 3))) assertEquals(listener.endHeaders, Some(false)) assertEquals(listener.endStream, Some(false)) assertEquals(listener.buffer, buffer(0x00)) @@ -487,7 +487,7 @@ class FrameDecoderSuite extends BlazeTestSuite { assertEquals(dec.decodeBuffer(testData), Continue) } - private class PriorityListener extends MockFrameListener(false) { + private class PriorityListener extends MockFrameListener(inHeaders = false) { var streamId: Option[Int] = None var priority: Option[Dependent] = None override def onPriorityFrame(streamId: Int, priority: Dependent): Result = { @@ -515,7 +515,7 @@ class FrameDecoderSuite extends BlazeTestSuite { assertEquals(dec.decodeBuffer(testData), Continue) assertEquals(listener.streamId, Some(1)) - assertEquals(listener.priority, Some(Priority.Dependent(2, false, 1))) + assertEquals(listener.priority, Some(Priority.Dependent(2, exclusive = false, 1))) } test("PRIORITY. Simple PRIORITY frame with exclusive") { @@ -541,7 +541,7 @@ class FrameDecoderSuite extends BlazeTestSuite { assertEquals(dec.decodeBuffer(testData), Continue) assertEquals(listener.streamId, Some(1)) - assertEquals(listener.priority, Some(Priority.Dependent(2, true, 1))) + assertEquals(listener.priority, Some(Priority.Dependent(2, exclusive = true, 1))) } test("PRIORITY. Frame with dependent stream being itself") { @@ -597,7 +597,7 @@ class FrameDecoderSuite extends BlazeTestSuite { } } - private class RstListener extends MockFrameListener(false) { + private class RstListener extends MockFrameListener(inHeaders = false) { var streamId: Option[Int] = None var code: Option[Long] = None override def onRstStreamFrame(streamId: Int, code: Long): Result = { @@ -682,7 +682,7 @@ class FrameDecoderSuite extends BlazeTestSuite { } } - private class SettingsListener extends MockFrameListener(false) { + private class SettingsListener extends MockFrameListener(inHeaders = false) { var settings: Option[Option[Seq[Setting]]] = None override def onSettingsFrame(settings: Option[Seq[Setting]]): Result = { this.settings = Some(settings) @@ -817,7 +817,7 @@ class FrameDecoderSuite extends BlazeTestSuite { } } - private class PushListener extends MockFrameListener(false) { + private class PushListener extends MockFrameListener(inHeaders = false) { var streamId: Option[Int] = None var promisedId: Option[Int] = None var endHeaders: Option[Boolean] = None @@ -1011,7 +1011,7 @@ class FrameDecoderSuite extends BlazeTestSuite { } } - private class PingListener extends MockFrameListener(false) { + private class PingListener extends MockFrameListener(inHeaders = false) { var ack: Option[Boolean] = None var data: Option[Array[Byte]] = None @@ -1137,7 +1137,7 @@ class FrameDecoderSuite extends BlazeTestSuite { } } - private class GoAwayListener extends MockFrameListener(false) { + private class GoAwayListener extends MockFrameListener(inHeaders = false) { var lastStream: Option[Int] = None var errorCode: Option[Long] = None var debugData: Option[Array[Byte]] = None @@ -1219,7 +1219,7 @@ class FrameDecoderSuite extends BlazeTestSuite { } } - private class WindowListener extends MockFrameListener(false) { + private class WindowListener extends MockFrameListener(inHeaders = false) { var streamId: Option[Int] = None var sizeIncrement: Option[Int] = None override def onWindowUpdateFrame(streamId: Int, sizeIncrement: Int): Result = { @@ -1358,7 +1358,7 @@ class FrameDecoderSuite extends BlazeTestSuite { // body 0x01 // increment ) - val listener = new ContinuationListener(true) + val listener = new ContinuationListener(inseq = true) val dec = new FrameDecoder(Http2Settings.default, listener) assertEquals(dec.decodeBuffer(testData), Continue) @@ -1377,7 +1377,7 @@ class FrameDecoderSuite extends BlazeTestSuite { // body 0x01 // increment ) - val listener = new ContinuationListener(true) + val listener = new ContinuationListener(inseq = true) val dec = new FrameDecoder(Http2Settings.default, listener) dec.decodeBuffer(testData) match { @@ -1401,7 +1401,7 @@ class FrameDecoderSuite extends BlazeTestSuite { // body 0x01 // increment ) - val listener = new ContinuationListener(true) + val listener = new ContinuationListener(inseq = true) val dec = new FrameDecoder(Http2Settings.default, listener) assertEquals(dec.decodeBuffer(testData), Continue) @@ -1425,7 +1425,7 @@ class FrameDecoderSuite extends BlazeTestSuite { // body 0x01 // increment ) - val listener = new ContinuationListener(false) + val listener = new ContinuationListener(inseq = false) val dec = new FrameDecoder(Http2Settings.default, listener) dec.decodeBuffer(testData) match { @@ -1445,7 +1445,7 @@ class FrameDecoderSuite extends BlazeTestSuite { 0x00, 0x00, 0x00, 0x00, // streamId 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00) - val listener = new MockFrameListener(false) + val listener = new MockFrameListener(inHeaders = false) var data: ByteBuffer = null var code: Option[Byte] = None var flags: Option[Byte] = None diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/FrameEncoderSuite.scala b/http/src/test/scala/org/http4s/blaze/http/http2/FrameEncoderSuite.scala index 48eb66bb9..4ded7d6e5 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/FrameEncoderSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/FrameEncoderSuite.scala @@ -76,7 +76,7 @@ class FrameEncoderSuite extends BlazeTestSuite { Error(Http2Exception.errorGenerator(id.toLong + 25L).goaway()) test("An Http2FrameEncoder should not fragment data frames if they fit into a single frame") { - val tools = new MockTools(true) + val tools = new MockTools(isClient = true) val zeroBuffer15 = zeroBuffer(15) val listener = mockListener { @@ -89,18 +89,20 @@ class FrameEncoderSuite extends BlazeTestSuite { tools.remoteSettings.maxFrameSize = 15 // technically an illegal size... // Frame 1 `endStream = true` - val data1 = BufferTools.joinBuffers(tools.frameEncoder.dataFrame(1, true, zeroBuffer(15))) + val data1 = + BufferTools.joinBuffers(tools.frameEncoder.dataFrame(1, endStream = true, zeroBuffer(15))) assertEquals(decoder.decodeBuffer(data1), ReturnTag(1)) // Frame 2 `endStream = false` - val data2 = BufferTools.joinBuffers(tools.frameEncoder.dataFrame(1, false, zeroBuffer(15))) + val data2 = + BufferTools.joinBuffers(tools.frameEncoder.dataFrame(1, endStream = false, zeroBuffer(15))) assertEquals(decoder.decodeBuffer(data2), ReturnTag(2)) } test( "An Http2FrameEncoder should fragments data frames if they exceed the localSettings.maxFrameSize" ) { - val tools = new MockTools(true) + val tools = new MockTools(isClient = true) val zeroBuffer5 = zeroBuffer(5) val zeroBuffer10 = zeroBuffer(10) val listener = mockListener(onDataFrameMock = { @@ -113,7 +115,8 @@ class FrameEncoderSuite extends BlazeTestSuite { tools.remoteSettings.maxFrameSize = 10 // technically an illegal size... // `endStream = true` - val data1 = BufferTools.joinBuffers(tools.frameEncoder.dataFrame(1, true, zeroBuffer(15))) + val data1 = + BufferTools.joinBuffers(tools.frameEncoder.dataFrame(1, endStream = true, zeroBuffer(15))) // Frame 1 assertEquals(remoteDecoder.decodeBuffer(data1), ReturnTag(1)) @@ -122,7 +125,8 @@ class FrameEncoderSuite extends BlazeTestSuite { assertEquals(remoteDecoder.decodeBuffer(data1), ReturnTag(2)) // `endStream = false` - val data2 = BufferTools.joinBuffers(tools.frameEncoder.dataFrame(1, false, zeroBuffer(15))) + val data2 = + BufferTools.joinBuffers(tools.frameEncoder.dataFrame(1, endStream = false, zeroBuffer(15))) val listener2 = mockListener(onDataFrameMock = { case (1, false, `zeroBuffer10`, 10) => ReturnTag(3) @@ -139,7 +143,7 @@ class FrameEncoderSuite extends BlazeTestSuite { } test("An Http2FrameEncoder should not fragment headers if they fit into a single frame") { - val tools = new MockTools(true) { + val tools = new MockTools(isClient = true) { override lazy val headerEncoder: HeaderEncoder = new HeaderEncoder(100) { override def encodeHeaders(hs: Headers): ByteBuffer = zeroBuffer(15) } @@ -156,19 +160,21 @@ class FrameEncoderSuite extends BlazeTestSuite { tools.remoteSettings.maxFrameSize = 15 // technically an illegal size... // `endStream = true` val data1 = - BufferTools.joinBuffers(tools.frameEncoder.headerFrame(1, Priority.NoPriority, true, Nil)) + BufferTools.joinBuffers( + tools.frameEncoder.headerFrame(1, Priority.NoPriority, endStream = true, Nil)) assertEquals(decoder.decodeBuffer(data1), ReturnTag(1)) // `endStream = false` val data2 = - BufferTools.joinBuffers(tools.frameEncoder.headerFrame(1, Priority.NoPriority, false, Nil)) + BufferTools.joinBuffers( + tools.frameEncoder.headerFrame(1, Priority.NoPriority, endStream = false, Nil)) assertEquals(decoder.decodeBuffer(data2), ReturnTag(2)) } test("An Http2FrameEncoder should fragment headers if they don't fit into one frame") { - val tools = new MockTools(true) { + val tools = new MockTools(isClient = true) { override lazy val headerEncoder: HeaderEncoder = new HeaderEncoder(100) { override def encodeHeaders(hs: Headers): ByteBuffer = zeroBuffer(15) } @@ -186,7 +192,8 @@ class FrameEncoderSuite extends BlazeTestSuite { tools.remoteSettings.maxFrameSize = 10 // technically an illegal size... val data = - BufferTools.joinBuffers(tools.frameEncoder.headerFrame(1, Priority.NoPriority, true, Nil)) + BufferTools.joinBuffers( + tools.frameEncoder.headerFrame(1, Priority.NoPriority, endStream = true, Nil)) assertEquals(decoder1.decodeBuffer(data), ReturnTag(1)) @@ -207,14 +214,14 @@ class FrameEncoderSuite extends BlazeTestSuite { } test("An Http2FrameEncoder should fragmenting HEADERS frames considers priority info size") { - val tools = new MockTools(true) { + val tools = new MockTools(isClient = true) { override lazy val headerEncoder: HeaderEncoder = new HeaderEncoder(100) { override def encodeHeaders(hs: Headers): ByteBuffer = zeroBuffer(10) } } val zeroBuffer5 = zeroBuffer(5) - val p = Priority.Dependent(2, true, 12) + val p = Priority.Dependent(2, exclusive = true, 12) val listener1 = mockListener( onHeadersFrameMock = { @@ -226,7 +233,7 @@ class FrameEncoderSuite extends BlazeTestSuite { tools.remoteSettings.maxFrameSize = 10 // technically an illegal size... - val data = BufferTools.joinBuffers(tools.frameEncoder.headerFrame(1, p, true, Nil)) + val data = BufferTools.joinBuffers(tools.frameEncoder.headerFrame(1, p, endStream = true, Nil)) assertEquals(decoder1.decodeBuffer(data), ReturnTag(1)) diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/FrameSerializerSuite.scala b/http/src/test/scala/org/http4s/blaze/http/http2/FrameSerializerSuite.scala index c74dbb654..219b3f741 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/FrameSerializerSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/FrameSerializerSuite.scala @@ -54,7 +54,7 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { ) def dec(dataFrame: DataFrame): TestFrameDecoder = - decoder(new MockFrameListener(false) { + decoder(new MockFrameListener(inHeaders = false) { override def onDataFrame( streamId: Int, isLast: Boolean, @@ -88,8 +88,8 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { test("DATA frame should decode padded buffers") { assert((0 to 256).forall { (i: Int) => def dat = mkData(20) - val frame = joinBuffers(FrameSerializer.mkDataFrame(3, false, i, dat)) - dec(DataFrame(3, false, dat, i)).decodeBuffer(frame) == Continue + val frame = joinBuffers(FrameSerializer.mkDataFrame(3, endStream = false, i, dat)) + dec(DataFrame(3, endStream = false, dat, i)).decodeBuffer(frame) == Continue }) } @@ -121,7 +121,7 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { def dat = mkData(20) def dec(headerFrame: HeadersFrame) = - decoder(new MockFrameListener(false) { + decoder(new MockFrameListener(inHeaders = false) { override def onHeadersFrame( streamId: Int, priority: Priority, @@ -159,27 +159,40 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { test("HEADERS frame should make round trip") { val buff1 = - joinBuffers(FrameSerializer.mkHeaderFrame(1, Priority.NoPriority, true, true, 0, dat)) + joinBuffers( + FrameSerializer + .mkHeaderFrame(1, Priority.NoPriority, endHeaders = true, endStream = true, 0, dat)) assertEquals( - dec(HeadersFrame(1, Priority.NoPriority, true, true, dat, 0)) + dec(HeadersFrame(1, Priority.NoPriority, endHeaders = true, endStream = true, dat, 0)) .decodeBuffer(buff1), Continue ) assertEquals(buff1.remaining(), 0) - val priority = Priority.Dependent(3, false, 6) - val buff2 = joinBuffers(FrameSerializer.mkHeaderFrame(2, priority, true, false, 0, dat)) - assertEquals(dec(HeadersFrame(2, priority, true, false, dat, 0)).decodeBuffer(buff2), Continue) + val priority = Priority.Dependent(3, exclusive = false, 6) + val buff2 = joinBuffers( + FrameSerializer.mkHeaderFrame(2, priority, endHeaders = true, endStream = false, 0, dat)) + assertEquals( + dec(HeadersFrame(2, priority, endHeaders = true, endStream = false, dat, 0)) + .decodeBuffer(buff2), + Continue) assertEquals(buff2.remaining(), 0) } test("HEADERS frame should handle padding") { val paddingSize = 10 val buff = joinBuffers( - FrameSerializer.mkHeaderFrame(1, Priority.NoPriority, true, true, paddingSize, dat) + FrameSerializer.mkHeaderFrame( + 1, + Priority.NoPriority, + endHeaders = true, + endStream = true, + paddingSize, + dat) ) assertEquals( - dec(HeadersFrame(1, Priority.NoPriority, true, true, dat, paddingSize)) + dec( + HeadersFrame(1, Priority.NoPriority, endHeaders = true, endStream = true, dat, paddingSize)) .decodeBuffer(buff), Continue ) @@ -188,21 +201,21 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { test("HEADERS frame should fail on bad stream ID") { intercept[Throwable]( FrameSerializer - .mkHeaderFrame(0, Priority.NoPriority, true, true, 0, dat) + .mkHeaderFrame(0, Priority.NoPriority, endHeaders = true, endStream = true, 0, dat) ) } test("HEADERS frame should fail on bad padding") { intercept[Throwable]( FrameSerializer - .mkHeaderFrame(1, Priority.NoPriority, true, true, -10, dat) + .mkHeaderFrame(1, Priority.NoPriority, endHeaders = true, endStream = true, -10, dat) ) } case class PriorityFrame(streamId: Int, priority: Priority.Dependent) def dec(priorityFrame: PriorityFrame) = - decoder(new MockFrameListener(false) { + decoder(new MockFrameListener(inHeaders = false) { override def onPriorityFrame( streamId: Int, priority: Priority.Dependent @@ -229,16 +242,17 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { } test("PRIORITY frame should fail to make a bad dependent Priority") { - intercept[Throwable](Priority.Dependent(1, true, 500)) - intercept[Throwable](Priority.Dependent(1, true, -500)) + intercept[Throwable](Priority.Dependent(1, exclusive = true, 500)) + intercept[Throwable](Priority.Dependent(1, exclusive = true, -500)) } test("PRIORITY frame should fail on bad streamId") { - intercept[Throwable](FrameSerializer.mkPriorityFrame(0, Priority.Dependent(1, true, 0))) + intercept[Throwable]( + FrameSerializer.mkPriorityFrame(0, Priority.Dependent(1, exclusive = true, 0))) } test("PRIORITY frame should fail on bad stream dependency") { - intercept[Throwable](Priority.Dependent(0, true, 0)) + intercept[Throwable](Priority.Dependent(0, exclusive = true, 0)) } case class RstFrame(streamId: Int, code: Long) @@ -251,7 +265,7 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { ) def dec(rstFrame: RstFrame) = - decoder(new MockFrameListener(false) { + decoder(new MockFrameListener(inHeaders = false) { override def onRstStreamFrame( streamId: Int, code: Long @@ -275,7 +289,7 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { } def dec(settingsFrame: SettingsFrame) = - decoder(new MockFrameListener(false) { + decoder(new MockFrameListener(inHeaders = false) { override def onSettingsFrame( settings: Option[Seq[Setting]] ): org.http4s.blaze.http.http2.Result = { diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/HeaderAggregatingFrameListenerSuite.scala b/http/src/test/scala/org/http4s/blaze/http/http2/HeaderAggregatingFrameListenerSuite.scala index aca262087..1ecc93c87 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/HeaderAggregatingFrameListenerSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/HeaderAggregatingFrameListenerSuite.scala @@ -52,10 +52,16 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { val hs = Seq("foo" -> "bar", "biz" -> "baz") val hsBuf = encodeHeaders(hs) - val bs = FrameSerializer.mkHeaderFrame(1, Priority.NoPriority, true, true, 0, hsBuf) + val bs = FrameSerializer.mkHeaderFrame( + 1, + Priority.NoPriority, + endHeaders = true, + endStream = true, + 0, + hsBuf) assertEquals( - mkDecoder(1, Priority.NoPriority, true, hs).decodeBuffer(BufferTools.joinBuffers(bs)), + mkDecoder(1, Priority.NoPriority, es = true, hs).decodeBuffer(BufferTools.joinBuffers(bs)), Halt ) } @@ -64,16 +70,22 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { val hs = Seq("foo" -> "bar", "biz" -> "baz") val hsBuf = encodeHeaders(hs) val first = BufferTools.takeSlice(hsBuf, hsBuf.remaining() - 1) - val bs = FrameSerializer.mkHeaderFrame(1, Priority.NoPriority, false, true, 0, first) + val bs = FrameSerializer.mkHeaderFrame( + 1, + Priority.NoPriority, + endHeaders = false, + endStream = true, + 0, + first) - val decoder = mkDecoder(1, Priority.NoPriority, true, hs) + val decoder = mkDecoder(1, Priority.NoPriority, es = true, hs) assertEquals(decoder.listener.inHeaderSequence, false) assertEquals(decoder.decodeBuffer(BufferTools.joinBuffers(bs)), Continue) assert(decoder.listener.inHeaderSequence) - val bs2 = FrameSerializer.mkContinuationFrame(1, true, hsBuf) + val bs2 = FrameSerializer.mkContinuationFrame(1, endHeaders = true, hsBuf) assertEquals(decoder.decodeBuffer(BufferTools.joinBuffers(bs2)), Halt) assertEquals(decoder.listener.inHeaderSequence, false) } @@ -81,16 +93,22 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { test("HEADERS frame with compressors should make a round trip with a continuation frame") { val hs = Seq("foo" -> "bar", "biz" -> "baz") val bs = - FrameSerializer.mkHeaderFrame(1, Priority.NoPriority, false, true, 0, BufferTools.emptyBuffer) + FrameSerializer.mkHeaderFrame( + 1, + Priority.NoPriority, + endHeaders = false, + endStream = true, + 0, + BufferTools.emptyBuffer) - val decoder = mkDecoder(1, Priority.NoPriority, true, hs) + val decoder = mkDecoder(1, Priority.NoPriority, es = true, hs) assertEquals(decoder.listener.inHeaderSequence, false) assertEquals(decoder.decodeBuffer(BufferTools.joinBuffers(bs)), Continue) assert(decoder.listener.inHeaderSequence) - val bs2 = FrameSerializer.mkContinuationFrame(1, true, encodeHeaders(hs)) + val bs2 = FrameSerializer.mkContinuationFrame(1, endHeaders = true, encodeHeaders(hs)) assertEquals(decoder.decodeBuffer(BufferTools.joinBuffers(bs2)), Halt) assertEquals(decoder.listener.inHeaderSequence, false) } @@ -99,32 +117,44 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { val hs1 = Seq("foo" -> "bar") val hs2 = Seq("biz" -> "baz") val bs = - FrameSerializer.mkHeaderFrame(1, Priority.NoPriority, false, true, 0, encodeHeaders(hs1)) + FrameSerializer.mkHeaderFrame( + 1, + Priority.NoPriority, + endHeaders = false, + endStream = true, + 0, + encodeHeaders(hs1)) - val decoder = mkDecoder(1, Priority.NoPriority, true, hs1 ++ hs2) + val decoder = mkDecoder(1, Priority.NoPriority, es = true, hs1 ++ hs2) assertEquals(decoder.listener.inHeaderSequence, false) assertEquals(decoder.decodeBuffer(BufferTools.joinBuffers(bs)), Continue) assert(decoder.listener.inHeaderSequence) - val bs2 = FrameSerializer.mkContinuationFrame(1, true, encodeHeaders(hs2)) + val bs2 = FrameSerializer.mkContinuationFrame(1, endHeaders = true, encodeHeaders(hs2)) assertEquals(decoder.decodeBuffer(BufferTools.joinBuffers(bs2)), Halt) assertEquals(decoder.listener.inHeaderSequence, false) } test("HEADERS frame with compressors should fail on invalid frame sequence (bad streamId)") { val bs = - FrameSerializer.mkHeaderFrame(1, Priority.NoPriority, false, true, 0, BufferTools.emptyBuffer) + FrameSerializer.mkHeaderFrame( + 1, + Priority.NoPriority, + endHeaders = false, + endStream = true, + 0, + BufferTools.emptyBuffer) - val decoder = mkDecoder(1, Priority.NoPriority, true, Seq()) + val decoder = mkDecoder(1, Priority.NoPriority, es = true, Seq()) assertEquals(decoder.listener.inHeaderSequence, false) assertEquals(decoder.decodeBuffer(BufferTools.joinBuffers(bs)), Continue) assert(decoder.listener.inHeaderSequence) - val bs2 = FrameSerializer.mkContinuationFrame(2, true, BufferTools.emptyBuffer) + val bs2 = FrameSerializer.mkContinuationFrame(2, endHeaders = true, BufferTools.emptyBuffer) decoder.decodeBuffer(BufferTools.joinBuffers(bs2)) match { case _: Error => () case _ => fail("Unexpected decodeBuffer result") @@ -133,9 +163,15 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { test("HEADERS frame with compressors should fail on invalid frame sequence (wrong frame type)") { val bs = - FrameSerializer.mkHeaderFrame(1, Priority.NoPriority, false, true, 0, BufferTools.emptyBuffer) + FrameSerializer.mkHeaderFrame( + 1, + Priority.NoPriority, + endHeaders = false, + endStream = true, + 0, + BufferTools.emptyBuffer) - val decoder = mkDecoder(1, Priority.NoPriority, true, Seq()) + val decoder = mkDecoder(1, Priority.NoPriority, es = true, Seq()) assertEquals(decoder.listener.inHeaderSequence, false) assertEquals(decoder.decodeBuffer(BufferTools.joinBuffers(bs)), Continue) @@ -152,7 +188,7 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { private def dat = mkData(20) private def dec(sId: Int, pId: Int, end_h: Boolean) = - decoder(new MockFrameListener(false) { + decoder(new MockFrameListener(inHeaders = false) { override def onPushPromiseFrame( streamId: Int, promisedId: Int, @@ -168,29 +204,31 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { }) test("PUSH_PROMISE frame should make round trip") { - val buff1 = BufferTools.joinBuffers(FrameSerializer.mkPushPromiseFrame(1, 2, true, 0, dat)) - assertEquals(dec(1, 2, true).decodeBuffer(buff1), Continue) + val buff1 = + BufferTools.joinBuffers(FrameSerializer.mkPushPromiseFrame(1, 2, endHeaders = true, 0, dat)) + assertEquals(dec(1, 2, end_h = true).decodeBuffer(buff1), Continue) assertEquals(buff1.remaining(), 0) } test("PUSH_PROMISE frame should handle padding") { val paddingSize = 10 - val buff = joinBuffers(FrameSerializer.mkPushPromiseFrame(1, 2, true, paddingSize, dat)) - assertEquals(dec(1, 2, true).decodeBuffer(buff), Continue) + val buff = + joinBuffers(FrameSerializer.mkPushPromiseFrame(1, 2, endHeaders = true, paddingSize, dat)) + assertEquals(dec(1, 2, end_h = true).decodeBuffer(buff), Continue) } test("PUSH_PROMISE frame should fail on bad stream ID") { - intercept[Throwable](FrameSerializer.mkPushPromiseFrame(0, 2, true, -10, dat)) + intercept[Throwable](FrameSerializer.mkPushPromiseFrame(0, 2, endHeaders = true, -10, dat)) } test("PUSH_PROMISE frame should fail on bad promised stream ID") { - intercept[Throwable](FrameSerializer.mkPushPromiseFrame(1, 0, true, -10, dat)) - intercept[Throwable](FrameSerializer.mkPushPromiseFrame(1, 3, true, -10, dat)) + intercept[Throwable](FrameSerializer.mkPushPromiseFrame(1, 0, endHeaders = true, -10, dat)) + intercept[Throwable](FrameSerializer.mkPushPromiseFrame(1, 3, endHeaders = true, -10, dat)) } test("PUSH_PROMISE frame should fail on bad padding") { - intercept[Throwable](FrameSerializer.mkPushPromiseFrame(1, 2, true, -10, dat)) - intercept[Throwable](FrameSerializer.mkPushPromiseFrame(1, 2, true, 500, dat)) + intercept[Throwable](FrameSerializer.mkPushPromiseFrame(1, 2, endHeaders = true, -10, dat)) + intercept[Throwable](FrameSerializer.mkPushPromiseFrame(1, 2, endHeaders = true, 500, dat)) } private def mkDec(sId: Int, pId: Int, hs: Headers) = @@ -210,7 +248,7 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { test("PUSH_PROMISE frame with header decoder should make a simple round trip") { val hs = Seq("foo" -> "bar", "biz" -> "baz") val hsBuf = encodeHeaders(hs) - val bs = FrameSerializer.mkPushPromiseFrame(1, 2, true, 0, hsBuf) + val bs = FrameSerializer.mkPushPromiseFrame(1, 2, endHeaders = true, 0, hsBuf) val decoder = mkDec(1, 2, hs) assertEquals(decoder.decodeBuffer(BufferTools.joinBuffers(bs)), Halt) @@ -222,7 +260,7 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { ) { val hs = Seq("foo" -> "bar", "biz" -> "baz") val hsBuf = encodeHeaders(hs) - val bs = FrameSerializer.mkPushPromiseFrame(1, 2, false, 0, hsBuf) + val bs = FrameSerializer.mkPushPromiseFrame(1, 2, endHeaders = false, 0, hsBuf) val decoder = mkDec(1, 2, hs) @@ -231,7 +269,7 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { assert(decoder.listener.inHeaderSequence) - val bs2 = FrameSerializer.mkContinuationFrame(1, true, BufferTools.emptyBuffer) + val bs2 = FrameSerializer.mkContinuationFrame(1, endHeaders = true, BufferTools.emptyBuffer) assertEquals(decoder.decodeBuffer(BufferTools.joinBuffers(bs2)), Halt) assertEquals(decoder.listener.inHeaderSequence, false) } @@ -241,7 +279,8 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { ) { val hs = Seq("foo" -> "bar", "biz" -> "baz") - val bs = FrameSerializer.mkPushPromiseFrame(1, 2, false, 0, BufferTools.emptyBuffer) + val bs = + FrameSerializer.mkPushPromiseFrame(1, 2, endHeaders = false, 0, BufferTools.emptyBuffer) val decoder = mkDec(1, 2, hs) @@ -250,7 +289,7 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { assert(decoder.listener.inHeaderSequence) - val bs2 = FrameSerializer.mkContinuationFrame(1, true, encodeHeaders(hs)) + val bs2 = FrameSerializer.mkContinuationFrame(1, endHeaders = true, encodeHeaders(hs)) assertEquals(decoder.decodeBuffer(BufferTools.joinBuffers(bs2)), Halt) assertEquals(decoder.listener.inHeaderSequence, false) } @@ -260,7 +299,7 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { ) { val hs1 = Seq("foo" -> "bar") val hs2 = Seq("biz" -> "baz") - val bs = FrameSerializer.mkPushPromiseFrame(1, 2, false, 0, encodeHeaders(hs1)) + val bs = FrameSerializer.mkPushPromiseFrame(1, 2, endHeaders = false, 0, encodeHeaders(hs1)) val decoder = mkDec(1, 2, hs1 ++ hs2) @@ -269,7 +308,7 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { assert(decoder.listener.inHeaderSequence) - val bs2 = FrameSerializer.mkContinuationFrame(1, true, encodeHeaders(hs2)) + val bs2 = FrameSerializer.mkContinuationFrame(1, endHeaders = true, encodeHeaders(hs2)) assertEquals(decoder.decodeBuffer(BufferTools.joinBuffers(bs2)), Halt) assertEquals(decoder.listener.inHeaderSequence, false) } @@ -279,13 +318,13 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { ) { val hs1 = Seq("foo" -> "bar") val hs2 = Seq("biz" -> "baz") - val bs = FrameSerializer.mkPushPromiseFrame(1, 2, false, 0, encodeHeaders(hs1)) + val bs = FrameSerializer.mkPushPromiseFrame(1, 2, endHeaders = false, 0, encodeHeaders(hs1)) val decoder = mkDec(1, 2, hs1 ++ hs2) assertEquals(decoder.decodeBuffer(BufferTools.joinBuffers(bs)), Continue) - val bs2 = FrameSerializer.mkContinuationFrame(2, true, encodeHeaders(hs2)) + val bs2 = FrameSerializer.mkContinuationFrame(2, endHeaders = true, encodeHeaders(hs2)) decoder.decodeBuffer(BufferTools.joinBuffers(bs2)) match { case _: Error => () case _ => fail("Unexpected decodeBuffer result") @@ -296,7 +335,7 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { "PUSH_PROMISE frame with header decoder should fail on invalid frame sequence (wrong frame type)" ) { val hs1 = Seq("foo" -> "bar") - val bs = FrameSerializer.mkPushPromiseFrame(1, 2, false, 0, encodeHeaders(hs1)) + val bs = FrameSerializer.mkPushPromiseFrame(1, 2, endHeaders = false, 0, encodeHeaders(hs1)) val decoder = mkDec(1, 2, hs1) diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/HeaderCodecHelpers.scala b/http/src/test/scala/org/http4s/blaze/http/http2/HeaderCodecHelpers.scala index acdf69e6c..50a98fd45 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/HeaderCodecHelpers.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/HeaderCodecHelpers.scala @@ -25,8 +25,9 @@ object HeaderCodecHelpers { } def decodeHeaders(bb: ByteBuffer, maxTableSize: Int): Seq[(String, String)] = { - val dec = new HeaderDecoder(Int.MaxValue, false, maxTableSize) - dec.decode(bb, -1, true) + val dec = + new HeaderDecoder(Int.MaxValue, discardOverflowHeaders = false, maxTableSize = maxTableSize) + dec.decode(bb, -1, endHeaders = true) dec.finish() } } diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/HeaderDecoderSuite.scala b/http/src/test/scala/org/http4s/blaze/http/http2/HeaderDecoderSuite.scala index c228154c5..c2af12201 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/HeaderDecoderSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/HeaderDecoderSuite.scala @@ -30,8 +30,11 @@ class HeaderDecoderSuite extends BlazeTestSuite { val bb = HeaderCodecHelpers.encodeHeaders(testHeaders, Http2Settings.DefaultSettings.HEADER_TABLE_SIZE) val dec = - new HeaderDecoder(Int.MaxValue, false, Http2Settings.DefaultSettings.HEADER_TABLE_SIZE) - assertEquals(dec.decode(bb, -1, true), Continue) + new HeaderDecoder( + Int.MaxValue, + discardOverflowHeaders = false, + maxTableSize = Http2Settings.DefaultSettings.HEADER_TABLE_SIZE) + assertEquals(dec.decode(bb, -1, endHeaders = true), Continue) assertEquals(dec.finish(), testHeaders) // Decode another block to make sure we don't contaminate the first @@ -39,7 +42,7 @@ class HeaderDecoderSuite extends BlazeTestSuite { val nextEncodedHs = HeaderCodecHelpers.encodeHeaders(nextHs, Http2Settings.DefaultSettings.HEADER_TABLE_SIZE) - assertEquals(dec.decode(nextEncodedHs, -1, true), Continue) + assertEquals(dec.decode(nextEncodedHs, -1, endHeaders = true), Continue) assertEquals(dec.finish(), nextHs) } @@ -47,12 +50,15 @@ class HeaderDecoderSuite extends BlazeTestSuite { val bb = HeaderCodecHelpers.encodeHeaders(testHeaders, Http2Settings.DefaultSettings.HEADER_TABLE_SIZE) val dec = - new HeaderDecoder(Int.MaxValue, false, Http2Settings.DefaultSettings.HEADER_TABLE_SIZE) + new HeaderDecoder( + Int.MaxValue, + discardOverflowHeaders = false, + maxTableSize = Http2Settings.DefaultSettings.HEADER_TABLE_SIZE) val b1 = BufferTools.takeSlice(bb, bb.remaining() / 2) - assertEquals(dec.decode(b1, -1, false), Continue) - assertEquals(dec.decode(bb, -1, true), Continue) + assertEquals(dec.decode(b1, -1, endHeaders = false), Continue) + assertEquals(dec.decode(bb, -1, endHeaders = true), Continue) assertEquals(dec.finish(), testHeaders) } @@ -60,10 +66,13 @@ class HeaderDecoderSuite extends BlazeTestSuite { val bb = HeaderCodecHelpers.encodeHeaders(testHeaders, Http2Settings.DefaultSettings.HEADER_TABLE_SIZE) val dec = - new HeaderDecoder(Int.MaxValue, false, Http2Settings.DefaultSettings.HEADER_TABLE_SIZE) + new HeaderDecoder( + Int.MaxValue, + discardOverflowHeaders = false, + maxTableSize = Http2Settings.DefaultSettings.HEADER_TABLE_SIZE) assertEquals(dec.currentHeaderBlockSize, 0) - assertEquals(dec.decode(bb, -1, true), Continue) + assertEquals(dec.decode(bb, -1, endHeaders = true), Continue) assertEquals(dec.currentHeaderBlockSize, headersBlockSize) assertEquals(dec.headerListSizeOverflow, false) @@ -77,11 +86,12 @@ class HeaderDecoderSuite extends BlazeTestSuite { Http2Settings.DefaultSettings.HEADER_TABLE_SIZE ) val dec = new HeaderDecoder( - headersBlockSize, /*discardOnOverflow*/ true, - Http2Settings.DefaultSettings.HEADER_TABLE_SIZE + headersBlockSize, + discardOverflowHeaders = true, + maxTableSize = Http2Settings.DefaultSettings.HEADER_TABLE_SIZE ) - assertEquals(dec.decode(bb, -1, true), Continue) + assertEquals(dec.decode(bb, -1, endHeaders = true), Continue) assert(dec.headerListSizeOverflow) assertEquals(dec.finish(), testHeaders) // didn't get the second round assertEquals(dec.headerListSizeOverflow, false) diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/OutboundStreamStateImplSuite.scala b/http/src/test/scala/org/http4s/blaze/http/http2/OutboundStreamStateImplSuite.scala index 4d577e80a..361c18453 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/OutboundStreamStateImplSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/OutboundStreamStateImplSuite.scala @@ -52,7 +52,7 @@ class OutboundStreamStateImplSuite extends BlazeTestSuite { import ctx._ intercept[IllegalStateException](streamState.streamId) - streamState.writeRequest(HeadersFrame(Priority.NoPriority, true, Seq.empty)) + streamState.writeRequest(HeadersFrame(Priority.NoPriority, endStream = true, Seq.empty)) assertEquals(streamManager.get(streamState.streamId), Some(streamState)) assertEquals(streamState.streamId, 1) // it's hard coded to 1 } @@ -60,12 +60,13 @@ class OutboundStreamStateImplSuite extends BlazeTestSuite { test("An OutboundStreamState should fail write requests if we fail to acquire a stream ID") { val ctx = new Ctx(Connection.Running) { override lazy val tools = new MockTools { - override lazy val idManager = StreamIdManager.create(true, -10) // should be depleted + override lazy val idManager = + StreamIdManager.create(isClient = true, -10) // should be depleted } } import ctx._ - val f = streamState.writeRequest(HeadersFrame(Priority.NoPriority, true, Seq.empty)) + val f = streamState.writeRequest(HeadersFrame(Priority.NoPriority, endStream = true, Seq.empty)) assertEquals(tools.drainGracePeriod, Some(Duration.Inf)) assertEquals(streamManager.size, 0) @@ -82,7 +83,7 @@ class OutboundStreamStateImplSuite extends BlazeTestSuite { val ctx = new Ctx(Connection.Closed) import ctx._ - val f = streamState.writeRequest(HeadersFrame(Priority.NoPriority, true, Seq.empty)) + val f = streamState.writeRequest(HeadersFrame(Priority.NoPriority, endStream = true, Seq.empty)) assertEquals(streamManager.size, 0) f.value match { diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/PingManagerSuite.scala b/http/src/test/scala/org/http4s/blaze/http/http2/PingManagerSuite.scala index 27c7eec9e..7b32fb154 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/PingManagerSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/PingManagerSuite.scala @@ -26,7 +26,7 @@ import scala.util.{Failure, Success} class PingManagerSuite extends BlazeTestSuite { test("A PingManager should write a ping") { - val tools = new MockTools(false) + val tools = new MockTools(isClient = false) // send one ping val f1 = tools.pingManager.ping() @@ -55,7 +55,7 @@ class PingManagerSuite extends BlazeTestSuite { } test("A PingManager should fail for a ping already in progress") { - val tools = new MockTools(false) + val tools = new MockTools(isClient = false) // send one ping val f1 = tools.pingManager.ping() @@ -82,7 +82,7 @@ class PingManagerSuite extends BlazeTestSuite { } test("A PingManager should fail if the write fails") { - val tools = new MockTools(true) { + val tools = new MockTools(isClient = true) { override val writeController: MockWriteController = new MockWriteController { override def write(data: Seq[ByteBuffer]): Boolean = false } @@ -96,7 +96,7 @@ class PingManagerSuite extends BlazeTestSuite { } test("A PingManager should closing fails pending ping") { - val tools = new MockTools(true) + val tools = new MockTools(isClient = true) // ping should fail val f = tools.pingManager.ping() diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/SessionFlowControlSuite.scala b/http/src/test/scala/org/http4s/blaze/http/http2/SessionFlowControlSuite.scala index ab88af612..389dcfb94 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/SessionFlowControlSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/SessionFlowControlSuite.scala @@ -43,7 +43,7 @@ class SessionFlowControlSuite extends BlazeTestSuite { } private def flowControl(local: Http2Settings, remote: Http2Settings): TestSessionFlowControl = { - val core = new MockTools(true /* doesn't matter */ ) { + val core = new MockTools(isClient = true /* doesn't matter */ ) { override lazy val remoteSettings: MutableHttp2Settings = MutableHttp2Settings(remote) override lazy val localSettings: MutableHttp2Settings = MutableHttp2Settings(local) } diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/SessionFrameListenerSuite.scala b/http/src/test/scala/org/http4s/blaze/http/http2/SessionFrameListenerSuite.scala index 19769e336..10ce24893 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/SessionFrameListenerSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/SessionFrameListenerSuite.scala @@ -33,8 +33,8 @@ class SessionFrameListenerSuite extends BlazeTestSuite { lazy val headerDecoder: HeaderDecoder = new HeaderDecoder( localSettings.maxHeaderListSize, - true, // discard overflow headers - localSettings.headerTableSize + discardOverflowHeaders = true, + maxTableSize = localSettings.headerTableSize ) lazy val newInboundStream: Option[Int => LeafBuilder[StreamFrame]] = None @@ -52,7 +52,7 @@ class SessionFrameListenerSuite extends BlazeTestSuite { val os = tools.streamManager.newOutboundStream() // initialize the stream - os.writeRequest(HeadersFrame(Priority.NoPriority, true, Seq.empty)) + os.writeRequest(HeadersFrame(Priority.NoPriority, endStream = true, Seq.empty)) tools.frameListener.onCompleteHeadersFrame( streamId = os.streamId, @@ -110,7 +110,9 @@ class SessionFrameListenerSuite extends BlazeTestSuite { tools.localSettings.pushEnabled = false val os = tools.streamManager.newOutboundStream() - os.writeRequest(HeadersFrame(Priority.NoPriority, false, Seq.empty)) // initiate stream + os.writeRequest( + HeadersFrame(Priority.NoPriority, endStream = false, Seq.empty) + ) // initiate stream tools.frameListener.onCompletePushPromiseFrame(os.streamId, os.streamId + 1, hs) match { case Error(ex: Http2SessionException) => @@ -148,10 +150,12 @@ class SessionFrameListenerSuite extends BlazeTestSuite { val tools = new MockTools(isClient = true) val os = tools.streamManager.newOutboundStream() - os.writeRequest(HeadersFrame(Priority.NoPriority, false, Seq.empty)) // initiate stream + os.writeRequest( + HeadersFrame(Priority.NoPriority, endStream = false, Seq.empty) + ) // initiate stream val data = BufferTools.allocate(4) - assertEquals(tools.frameListener.onDataFrame(os.streamId, true, data, 4), Continue) + assertEquals(tools.frameListener.onDataFrame(os.streamId, isLast = true, data, 4), Continue) os.readRequest(1).value match { case Some(Success(DataFrame(true, d))) => @@ -167,13 +171,15 @@ class SessionFrameListenerSuite extends BlazeTestSuite { val tools = new MockTools(isClient = true) val os = tools.streamManager.newOutboundStream() - os.writeRequest(HeadersFrame(Priority.NoPriority, false, Seq.empty)) // initiate stream + os.writeRequest( + HeadersFrame(Priority.NoPriority, endStream = false, Seq.empty) + ) // initiate stream os.doCloseWithError(None) val data = BufferTools.allocate(4) val init = tools.sessionFlowControl.sessionInboundWindow - tools.frameListener.onDataFrame(os.streamId, true, data, 4) match { + tools.frameListener.onDataFrame(os.streamId, isLast = true, data, 4) match { case Error(ex: Http2StreamException) => assertEquals(ex.code, STREAM_CLOSED.code) case _ => @@ -187,7 +193,7 @@ class SessionFrameListenerSuite extends BlazeTestSuite { val tools = new MockTools(isClient = true) val init = tools.sessionFlowControl.sessionInboundWindow - tools.frameListener.onDataFrame(1, true, BufferTools.emptyBuffer, 4) match { + tools.frameListener.onDataFrame(1, isLast = true, BufferTools.emptyBuffer, 4) match { case Error(ex: Http2SessionException) => assertEquals(ex.code, PROTOCOL_ERROR.code) case _ => @@ -201,12 +207,14 @@ class SessionFrameListenerSuite extends BlazeTestSuite { val tools = new MockTools(isClient = true) val os = tools.streamManager.newOutboundStream() - os.writeRequest(HeadersFrame(Priority.NoPriority, false, Seq.empty)) // initiate stream + os.writeRequest( + HeadersFrame(Priority.NoPriority, endStream = false, Seq.empty) + ) // initiate stream os.doCloseWithError(None) val data = BufferTools.allocate(4) - tools.frameListener.onDataFrame(os.streamId, true, data, 4) match { + tools.frameListener.onDataFrame(os.streamId, isLast = true, data, 4) match { case Error(ex: Http2StreamException) => assertEquals(ex.code, STREAM_CLOSED.code) case _ => @@ -216,7 +224,7 @@ class SessionFrameListenerSuite extends BlazeTestSuite { test("A SessionFrameListener on RST_STREAM delegates to the StreamManager") { var observedCause: Option[Http2StreamException] = None - val tools = new MockTools(true) { + val tools = new MockTools(isClient = true) { override lazy val streamManager = new MockStreamManager() { override def rstStream(cause: Http2StreamException) = { observedCause = Some(cause) @@ -238,7 +246,7 @@ class SessionFrameListenerSuite extends BlazeTestSuite { test("A SessionFrameListener on WINDOW_UPDATE delegates to the StreamManager") { var observedIncrement: Option[(Int, Int)] = None - val tools = new MockTools(true) { + val tools = new MockTools(isClient = true) { override lazy val streamManager = new MockStreamManager() { override def flowWindowUpdate(streamId: Int, sizeIncrement: Int) = { observedIncrement = Some(streamId -> sizeIncrement) @@ -255,9 +263,9 @@ class SessionFrameListenerSuite extends BlazeTestSuite { } test("A SessionFrameListener on PING frame writes ACK's for peer initiated PINGs") { - val tools = new MockTools(true) + val tools = new MockTools(isClient = true) val data = (0 until 8).map(_.toByte).toArray - assertEquals(tools.frameListener.onPingFrame(false, data), Continue) + assertEquals(tools.frameListener.onPingFrame(ack = false, data), Continue) val written = tools.writeController.observedWrites.dequeue() assertEquals(written, FrameSerializer.mkPingFrame(ack = true, data = data)) @@ -265,19 +273,19 @@ class SessionFrameListenerSuite extends BlazeTestSuite { test("A SessionFrameListener on PING frame pass ping ACK's to the PingManager") { var observedAck: Option[Array[Byte]] = None - val tools = new MockTools(true) { + val tools = new MockTools(isClient = true) { override lazy val pingManager = new PingManager(this) { override def pingAckReceived(data: Array[Byte]): Unit = observedAck = Some(data) } } val data = (0 until 8).map(_.toByte).toArray - assertEquals(tools.frameListener.onPingFrame(true, data), Continue) + assertEquals(tools.frameListener.onPingFrame(ack = true, data), Continue) assertEquals(observedAck, Some(data)) } test("A SessionFrameListener on SETTINGS frame updates remote settings") { - val tools = new MockTools(true) + val tools = new MockTools(isClient = true) val settingChange = Http2Settings.INITIAL_WINDOW_SIZE(1) assertEquals(tools.frameListener.onSettingsFrame(Some(Seq(settingChange))), Continue) @@ -291,7 +299,7 @@ class SessionFrameListenerSuite extends BlazeTestSuite { test("A SessionFrameListener on GOAWAY frame delegates to the sessions goAway logic") { var observedGoAway: Option[(Int, Http2SessionException)] = None - val tools = new MockTools(true) { + val tools = new MockTools(isClient = true) { override def invokeGoAway( lastHandledOutboundStream: Int, reason: Http2SessionException diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/StreamManagerImplSuite.scala b/http/src/test/scala/org/http4s/blaze/http/http2/StreamManagerImplSuite.scala index 5ee76d623..8b8f00fce 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/StreamManagerImplSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/StreamManagerImplSuite.scala @@ -61,7 +61,7 @@ class StreamManagerImplSuite extends BlazeTestSuite { ) // Since the streams are closed stream operations should fail - val hs = HeadersFrame(Priority.NoPriority, false, Seq.empty) + val hs = HeadersFrame(Priority.NoPriority, endStream = false, Seq.empty) s1.writeRequest(hs).value match { case Some(Failure(`ex`)) => () case _ => fail("Unexpected writeRequest result found") @@ -80,8 +80,8 @@ class StreamManagerImplSuite extends BlazeTestSuite { val os4 = tools.streamManager.newOutboundStream() // each needs to write some data to initialize - os2.writeRequest(HeadersFrame(Priority.NoPriority, false, Seq.empty)) - val f4 = os4.writeRequest(HeadersFrame(Priority.NoPriority, false, Seq.empty)) + os2.writeRequest(HeadersFrame(Priority.NoPriority, endStream = false, Seq.empty)) + val f4 = os4.writeRequest(HeadersFrame(Priority.NoPriority, endStream = false, Seq.empty)) val f = tools.streamManager.drain(2, Http2Exception.NO_ERROR.goaway("bye-bye")) assertEquals(f.isCompleted, false) @@ -115,7 +115,7 @@ class StreamManagerImplSuite extends BlazeTestSuite { tools.streamManager .newOutboundStream() - .writeRequest(HeadersFrame(Priority.NoPriority, false, Seq.empty)) + .writeRequest(HeadersFrame(Priority.NoPriority, endStream = false, Seq.empty)) .value match { case Some(Failure(ex: Http2StreamException)) => assertEquals(ex.code, REFUSED_STREAM.code) @@ -205,7 +205,7 @@ class StreamManagerImplSuite extends BlazeTestSuite { assert(tools.streamManager.get(1).isEmpty) assert(tools.streamManager.get(3).isEmpty) - val hs = HeadersFrame(Priority.NoPriority, false, Seq.empty) + val hs = HeadersFrame(Priority.NoPriority, endStream = false, Seq.empty) oss1.writeRequest(hs) oss3.writeRequest(hs) @@ -288,7 +288,7 @@ class StreamManagerImplSuite extends BlazeTestSuite { "A StreamManagerImpl flow windows should handle successful flow window updates for the session" ) { var sessionAcked: Option[Int] = None - val tools = new MockTools(true) { + val tools = new MockTools(isClient = true) { override lazy val sessionFlowControl: SessionFlowControl = new MockSessionFlowControl { override def sessionOutboundAcked(count: Int): Option[Http2Exception] = { sessionAcked = Some(count) @@ -305,7 +305,7 @@ class StreamManagerImplSuite extends BlazeTestSuite { "A StreamManagerImpl flow windows should handle failed flow window updates for the session" ) { var sessionAcked: Option[Int] = None - val tools = new MockTools(true) { + val tools = new MockTools(isClient = true) { override lazy val sessionFlowControl: SessionFlowControl = new MockSessionFlowControl { override def sessionOutboundAcked(count: Int): Option[Http2Exception] = { sessionAcked = Some(count) @@ -330,7 +330,7 @@ class StreamManagerImplSuite extends BlazeTestSuite { tools.streamManager .newOutboundStream() - .writeRequest(HeadersFrame(Priority.NoPriority, true, Seq.empty)) + .writeRequest(HeadersFrame(Priority.NoPriority, endStream = true, Seq.empty)) tools.streamManager.handlePushPromise(streamId = 1, promisedId = 2, headers = Seq.empty) match { case Error(ex: Http2StreamException) => diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/StreamStateImplSuite.scala b/http/src/test/scala/org/http4s/blaze/http/http2/StreamStateImplSuite.scala index 47157c92e..3dd7a95c0 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/StreamStateImplSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/StreamStateImplSuite.scala @@ -61,7 +61,7 @@ class StreamStateImplSuite extends BlazeTestSuite { val ctx = new Ctx import ctx._ - val f = streamState.writeRequest(DataFrame(true, BufferTools.emptyBuffer)) + val f = streamState.writeRequest(DataFrame(endStream = true, BufferTools.emptyBuffer)) assertEquals(tools.writeController.observedInterests.result(), streamState :: Nil) tools.writeController.observedInterests.clear() @@ -72,7 +72,7 @@ class StreamStateImplSuite extends BlazeTestSuite { val ctx = new Ctx import ctx._ - val f = streamState.writeRequest(DataFrame(true, BufferTools.emptyBuffer)) + val f = streamState.writeRequest(DataFrame(endStream = true, BufferTools.emptyBuffer)) assertEquals(tools.writeController.observedInterests.result(), streamState :: Nil) tools.writeController.observedInterests.clear() @@ -86,13 +86,13 @@ class StreamStateImplSuite extends BlazeTestSuite { val ctx = new Ctx import ctx._ - val f1 = streamState.writeRequest(DataFrame(true, BufferTools.emptyBuffer)) + val f1 = streamState.writeRequest(DataFrame(endStream = true, BufferTools.emptyBuffer)) assertEquals(f1.isCompleted, false) assertEquals(tools.writeController.observedInterests.result(), streamState :: Nil) val currentSize = tools.writeController.observedWrites.length - val f2 = streamState.writeRequest(DataFrame(true, BufferTools.emptyBuffer)) + val f2 = streamState.writeRequest(DataFrame(endStream = true, BufferTools.emptyBuffer)) assert(Seq(f1, f2).forall { f => f.value match { @@ -146,8 +146,14 @@ class StreamStateImplSuite extends BlazeTestSuite { val ctx = new Ctx import ctx._ - streamState.invokeInboundHeaders(Priority.NoPriority, true, Seq.empty) // remote closed - streamState.writeRequest(HeadersFrame(Priority.NoPriority, true, Seq.empty)) // local closed + streamState.invokeInboundHeaders( + Priority.NoPriority, + endStream = true, + Seq.empty + ) // remote closed + streamState.writeRequest( + HeadersFrame(Priority.NoPriority, endStream = true, Seq.empty) + ) // local closed streamState.closePipeline(None) assertEquals(tools.streamManager.finishedStreams.dequeue(), streamState) @@ -190,7 +196,9 @@ class StreamStateImplSuite extends BlazeTestSuite { import ctx._ // Need to open the stream - assertEquals(streamState.invokeInboundHeaders(Priority.NoPriority, false, Seq.empty), Continue) + assertEquals( + streamState.invokeInboundHeaders(Priority.NoPriority, endStream = false, Seq.empty), + Continue) assert(streamState.readRequest(1).isCompleted) // headers val f1 = streamState.readRequest(1) @@ -215,7 +223,9 @@ class StreamStateImplSuite extends BlazeTestSuite { import ctx._ // Need to open the stream - assertEquals(streamState.invokeInboundHeaders(Priority.NoPriority, false, Seq.empty), Continue) + assertEquals( + streamState.invokeInboundHeaders(Priority.NoPriority, endStream = false, Seq.empty), + Continue) assert(streamState.readRequest(1).isCompleted) // headers // We should count the flow bytes size, not the actual buffer size @@ -244,7 +254,9 @@ class StreamStateImplSuite extends BlazeTestSuite { ) // Need to open the stream - assertEquals(streamState.invokeInboundHeaders(Priority.NoPriority, false, Seq.empty), Continue) + assertEquals( + streamState.invokeInboundHeaders(Priority.NoPriority, endStream = false, Seq.empty), + Continue) // We should count the flow bytes size, not the actual buffer size streamState.invokeInboundData( @@ -276,7 +288,9 @@ class StreamStateImplSuite extends BlazeTestSuite { ) // Need to open the stream - assertEquals(streamState.invokeInboundHeaders(Priority.NoPriority, false, Seq.empty), Continue) + assertEquals( + streamState.invokeInboundHeaders(Priority.NoPriority, endStream = false, Seq.empty), + Continue) // We should count the flow bytes size, not the actual buffer size streamState.invokeInboundData( @@ -300,7 +314,9 @@ class StreamStateImplSuite extends BlazeTestSuite { val hs = Seq("foo" -> "bar") - assertEquals(streamState.invokeInboundHeaders(Priority.NoPriority, false, hs), Continue) + assertEquals( + streamState.invokeInboundHeaders(Priority.NoPriority, endStream = false, hs), + Continue) f1.value match { case Some(Success(HeadersFrame(Priority.NoPriority, false, hss))) => @@ -317,7 +333,9 @@ class StreamStateImplSuite extends BlazeTestSuite { val f1 = streamState.readRequest(1) assertEquals(f1.isCompleted, false) - assertEquals(streamState.invokeInboundData(false, BufferTools.allocate(1), 1), Continue) + assertEquals( + streamState.invokeInboundData(endStream = false, BufferTools.allocate(1), 1), + Continue) f1.value match { case Some(Success(DataFrame(false, data))) => diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/WriteControllerImplSuite.scala b/http/src/test/scala/org/http4s/blaze/http/http2/WriteControllerImplSuite.scala index aa94e5e21..cd58b1f1a 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/WriteControllerImplSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/WriteControllerImplSuite.scala @@ -59,7 +59,7 @@ class WriteControllerImplSuite extends BlazeTestSuite { private class Ctx { def highWaterMark = Int.MaxValue - val tools = new MockTools(true) + val tools = new MockTools(isClient = true) val tail = new MockTail val writeController = new WriteControllerImpl(tools, highWaterMark, tail) } diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockHeaderAggregatingFrameListener.scala b/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockHeaderAggregatingFrameListener.scala index 53823a1f3..340725208 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockHeaderAggregatingFrameListener.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockHeaderAggregatingFrameListener.scala @@ -25,7 +25,7 @@ import org.http4s.blaze.http.http2._ private[http2] class MockHeaderAggregatingFrameListener extends HeaderAggregatingFrameListener( Http2Settings.default, - new HeaderDecoder(20 * 1024, true, 4096) + new HeaderDecoder(20 * 1024, discardOverflowHeaders = true, maxTableSize = 4096) ) { override def onCompletePushPromiseFrame( streamId: Int, diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockStreamManager.scala b/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockStreamManager.scala index 2715bf3ad..e0b388a5e 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockStreamManager.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockStreamManager.scala @@ -44,8 +44,10 @@ private[http2] class MockStreamManager() extends StreamManager { override def get(streamId: Int): Option[StreamState] = None - override def drain(lastHandledOutboundStream: Int, reason: Http2SessionException): Future[Unit] = - ??? + override def drain( + lastHandledOutboundStream: Int, + reason: Http2SessionException + ): Future[Unit] = ??? override def rstStream(cause: Http2StreamException): MaybeError = Continue diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockTools.scala b/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockTools.scala index 902b66034..5c62c68a5 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockTools.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockTools.scala @@ -57,8 +57,10 @@ private[http2] class MockTools(isClient: Boolean) extends SessionCore { override def invokeDrain(gracePeriod: Duration): Unit = drainGracePeriod = Some(gracePeriod) - override def invokeGoAway(lastHandledOutboundStream: Int, reason: Http2SessionException): Unit = - ??? + override def invokeGoAway( + lastHandledOutboundStream: Int, + reason: Http2SessionException + ): Unit = ??? override def invokeShutdownWithError(ex: Option[Throwable], phase: String): Unit = ??? } diff --git a/project/Dependencies.scala b/project/Dependencies.scala index e7a8c0d57..5024a6547 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -1,9 +1,9 @@ import sbt._ object Dependencies { - lazy val logbackClassic = "ch.qos.logback" % "logback-classic" % "1.2.12" + lazy val logbackClassic = "ch.qos.logback" % "logback-classic" % "1.2.13" lazy val twitterHPACK = "com.twitter" % "hpack" % "1.0.2" - lazy val asyncHttpClient = "org.asynchttpclient" % "async-http-client" % "2.12.3" + lazy val asyncHttpClient = "org.asynchttpclient" % "async-http-client" % "3.0.0" lazy val log4s = "org.log4s" %% "log4s" % "1.10.0" lazy val munit = "org.scalameta" %% "munit" % "1.0.0-M6" lazy val scalacheckMunit = "org.scalameta" %% "munit-scalacheck" % munit.revision diff --git a/project/build.properties b/project/build.properties index 304098715..db1723b08 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.4 +sbt.version=1.10.5 diff --git a/project/plugins.sbt b/project/plugins.sbt index 412449dcc..a7bbe0361 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,4 @@ -addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.13.0") +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.13.1") addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % "0.8.0") addSbtPlugin("io.spray" % "sbt-revolver" % "0.10.0") -addSbtPlugin("org.http4s" %% "sbt-http4s-org" % "0.15.0") +addSbtPlugin("org.http4s" %% "sbt-http4s-org" % "0.17.5")