diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 05a59f092..14d1c7e60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,9 +9,9 @@ name: Continuous Integration on: pull_request: - branches: ['**'] + branches: ['**', '!update/**'] push: - branches: ['**'] + branches: ['**', '!update/**'] tags: [v*] env: @@ -87,6 +87,10 @@ jobs: - name: Check Java formatting run: sbt '++${{ matrix.scala }}' '${{ matrix.ci }}' javafmtCheckAll + - name: Check scalafix lints + if: matrix.java == 'temurin@8' && !startsWith(matrix.scala, '3.') + run: sbt '++${{ matrix.scala }}' 'scalafixAll --check' + - name: Check unused compile dependencies if: matrix.java == 'temurin@8' run: sbt '++${{ matrix.scala }}' unusedCompileDependenciesTest diff --git a/.scalafix.blaze.conf b/.scalafix.blaze.conf new file mode 100644 index 000000000..26ad6fae6 --- /dev/null +++ b/.scalafix.blaze.conf @@ -0,0 +1,7 @@ +rules = [ + RedundantSyntax +] + +triggered.rules = [ + RedundantSyntax +] \ No newline at end of file diff --git a/.scalafix.conf b/.scalafix.conf new file mode 100644 index 000000000..44c071e06 --- /dev/null +++ b/.scalafix.conf @@ -0,0 +1,15 @@ +rules = [ + Http4sFs2Linters + Http4sGeneralLinters + Http4sUseLiteralsSyntax + LeakingImplicitClassVal + ExplicitResultTypes + OrganizeImports +] + +triggered.rules = [ + Http4sFs2Linters + Http4sGeneralLinters + Http4sUseLiteralsSyntax + LeakingImplicitClassVal +] \ No newline at end of file diff --git a/.scalafix.test.conf b/.scalafix.test.conf new file mode 100644 index 000000000..529257ad8 --- /dev/null +++ b/.scalafix.test.conf @@ -0,0 +1,12 @@ +rules = [ + Http4sGeneralLinters + Http4sUseLiteralsSyntax + LeakingImplicitClassVal + OrganizeImports +] + +triggered.rules = [ + Http4sGeneralLinters + Http4sUseLiteralsSyntax + LeakingImplicitClassVal +] \ No newline at end of file diff --git a/.scalafmt.conf b/.scalafmt.conf index cc782f8be..a362fffc5 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = 3.5.2 +version = 3.5.8 style = default 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 486f7927a..a35e3bc7c 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 @@ -517,7 +517,7 @@ class Http1ServerStageSpec extends CatsEffectSuite { .orNotFound fixture.test("Http1ServerStage: routes should Handle trailing headers") { tw => - (runRequest(tw, Seq(req("foo")), routes2).result).map { buff => + runRequest(tw, Seq(req("foo")), routes2).result.map { buff => val results = dropDate(ResponseParser.parseBuffer(buff)) assertEquals(results._1, Ok) assertEquals(results._3, "Foo: Bar") diff --git a/build.sbt b/build.sbt index 0c8839473..14c491944 100644 --- a/build.sbt +++ b/build.sbt @@ -22,17 +22,20 @@ ThisBuild / developers ++= List( "bryce-anderson", "Bryce L. Anderson", "bryce.anderson22@gamil.com", - url("https://github.com/bryce-anderson")), + url("https://github.com/bryce-anderson") + ), Developer( "rossabaker", "Ross A. Baker", "ross@rossabaker.com", - url("https://github.com/rossabaker")), + url("https://github.com/rossabaker") + ), Developer( "ChristopherDavenport", "Christopher Davenport", "chris@christopherdavenport.tech", - url("https://github.com/ChristopherDavenport")) + url("https://github.com/ChristopherDavenport") + ) ) ThisBuild / startYear := Some(2014) @@ -50,7 +53,8 @@ lazy val commonSettings = Seq( } }, run / fork := true, - scalafmtConfig := file(".scalafmt.blaze.conf") + scalafmtConfig := file(".scalafmt.blaze.conf"), + scalafixConfig := Some(file(".scalafix.blaze.conf")) ) // currently only publishing tags @@ -60,7 +64,8 @@ ThisBuild / githubWorkflowPublishTargetBranches := ThisBuild / githubWorkflowBuild ++= Seq( WorkflowStep.Sbt( List("${{ matrix.ci }}", "javafmtCheckAll"), - name = Some("Check Java formatting")) + name = Some("Check Java formatting") + ) ) lazy val blaze = project @@ -93,7 +98,8 @@ lazy val core = Project("blaze-core", file("core")) mimaBinaryIssueFilters ++= Seq( // private constructor for which there are no sensible defaults ProblemFilters.exclude[DirectMissingMethodProblem]( - "org.http4s.blaze.channel.nio1.NIO1SocketServerGroup.this") + "org.http4s.blaze.channel.nio1.NIO1SocketServerGroup.this" + ) ) ) .dependsOn(testkit % Test) @@ -107,14 +113,16 @@ lazy val http = Project("blaze-http", file("http")) // Test Dependencies libraryDependencies += asyncHttpClient % Test, mimaBinaryIssueFilters ++= Seq( + ProblemFilters + .exclude[MissingClassProblem]("org.http4s.blaze.http.http2.PingManager$PingState"), + ProblemFilters + .exclude[MissingClassProblem]("org.http4s.blaze.http.http2.PingManager$PingState$"), ProblemFilters.exclude[MissingClassProblem]( - "org.http4s.blaze.http.http2.PingManager$PingState"), - ProblemFilters.exclude[MissingClassProblem]( - "org.http4s.blaze.http.http2.PingManager$PingState$"), - ProblemFilters.exclude[MissingClassProblem]( - "org.http4s.blaze.http.http2.client.ALPNClientSelector$ClientProvider"), + "org.http4s.blaze.http.http2.client.ALPNClientSelector$ClientProvider" + ), ProblemFilters.exclude[MissingClassProblem]( - "org.http4s.blaze.http.http2.server.ALPNServerSelector$ServerProvider") + "org.http4s.blaze.http.http2.server.ALPNServerSelector$ServerProvider" + ) ) ) .dependsOn(testkit % Test, core % "test->test;compile->compile") @@ -159,7 +167,8 @@ lazy val blazeCore = project .exclude[DirectMissingMethodProblem]("org.http4s.blazecore.util.IdentityWriter.ec") ) else Seq.empty - } + }, + Test / scalafixConfig := Some(file(".scalafix.test.conf")) ) .dependsOn(http) @@ -221,7 +230,8 @@ lazy val blazeServer = project ) ) else Seq.empty, - } + }, + Test / scalafixConfig := Some(file(".scalafix.test.conf")) ) .dependsOn(blazeCore % "compile;test->test") @@ -317,7 +327,8 @@ lazy val blazeClient = project ) ) else Seq.empty - } + }, + Test / scalafixConfig := Some(file(".scalafix.test.conf")) ) .dependsOn(blazeCore % "compile;test->test") @@ -330,7 +341,8 @@ lazy val examples = Project("blaze-examples", file("examples")) "org.http4s" %% "http4s-dsl" % http4sVersion, "org.http4s" %% "http4s-circe" % http4sVersion, "io.circe" %% "circe-generic" % "0.14.2" - ) + ), + Test / scalafixConfig := Some(file(".scalafix.test.conf")) ) .dependsOn(blazeServer, blazeClient) @@ -339,4 +351,5 @@ lazy val examples = Project("blaze-examples", file("examples")) // use it in the local development process addCommandAlias( "validate", - ";scalafmtCheckAll ;scalafmtSbtCheck ;javafmtCheckAll ;+test:compile ;test ;unusedCompileDependenciesTest ;mimaReportBinaryIssues") + ";scalafmtCheckAll ;scalafmtSbtCheck ;javafmtCheckAll ;+test:compile ;test ;unusedCompileDependenciesTest ;mimaReportBinaryIssues" +) diff --git a/core/src/main/scala/org/http4s/blaze/channel/ServerChannel.scala b/core/src/main/scala/org/http4s/blaze/channel/ServerChannel.scala index 85a8ea060..f9f23190d 100644 --- a/core/src/main/scala/org/http4s/blaze/channel/ServerChannel.scala +++ b/core/src/main/scala/org/http4s/blaze/channel/ServerChannel.scala @@ -85,8 +85,9 @@ abstract class ServerChannel extends Closeable { self => * @return * true if the hook was successfully registered, false otherwise. */ - final def addShutdownHook(f: () => Unit)(implicit - ec: ExecutionContext = Execution.directec): Boolean = + final def addShutdownHook( + f: () => Unit + )(implicit ec: ExecutionContext = Execution.directec): Boolean = shutdownHooks.synchronized { if (state != Open) false else { diff --git a/core/src/main/scala/org/http4s/blaze/channel/nio1/NIO1ClientChannel.scala b/core/src/main/scala/org/http4s/blaze/channel/nio1/NIO1ClientChannel.scala index df11159cc..262baf5dc 100644 --- a/core/src/main/scala/org/http4s/blaze/channel/nio1/NIO1ClientChannel.scala +++ b/core/src/main/scala/org/http4s/blaze/channel/nio1/NIO1ClientChannel.scala @@ -25,8 +25,8 @@ import java.util.concurrent.atomic.AtomicBoolean private[blaze] final class NIO1ClientChannel( private[this] val underlying: SocketChannel, - private[this] val onClose: () => Unit) - extends NIO1Channel { + private[this] val onClose: () => Unit +) extends NIO1Channel { private[this] val closed = new AtomicBoolean(false) diff --git a/core/src/main/scala/org/http4s/blaze/channel/nio1/NIO1HeadStage.scala b/core/src/main/scala/org/http4s/blaze/channel/nio1/NIO1HeadStage.scala index cf1deba3a..87d042bc1 100644 --- a/core/src/main/scala/org/http4s/blaze/channel/nio1/NIO1HeadStage.scala +++ b/core/src/main/scala/org/http4s/blaze/channel/nio1/NIO1HeadStage.scala @@ -72,7 +72,8 @@ private[nio1] object NIO1HeadStage { private def performWrite( ch: NIO1ClientChannel, scratch: ByteBuffer, - buffers: Array[ByteBuffer]): WriteResult = + buffers: Array[ByteBuffer] + ): WriteResult = try if (BufferTools.areDirectOrEmpty(buffers)) { ch.write(buffers) @@ -198,7 +199,7 @@ private[nio1] final class NIO1HeadStage( // / channel reading bits ////////////////////////////////////////////// - final override def readRequest(size: Int): Future[ByteBuffer] = { + override final def readRequest(size: Int): Future[ByteBuffer] = { logger.trace(s"NIOHeadStage received a read request of size $size") val p = Promise[ByteBuffer]() @@ -238,10 +239,10 @@ private[nio1] final class NIO1HeadStage( // / channel write bits ///////////////////////////////////////////////// - final override def writeRequest(data: ByteBuffer): Future[Unit] = + override final def writeRequest(data: ByteBuffer): Future[Unit] = writeRequest(data :: Nil) - final override def writeRequest(data: collection.Seq[ByteBuffer]): Future[Unit] = { + override final def writeRequest(data: collection.Seq[ByteBuffer]): Future[Unit] = { logger.trace(s"NIO1HeadStage Write Request: $data") val p = Promise[Unit]() selectorLoop.executeTask(new selectorLoop.LoopRunnable { @@ -289,9 +290,9 @@ private[nio1] final class NIO1HeadStage( // /////////////////////////////// Channel Ops //////////////////////////////////////// - final override def close(cause: Option[Throwable]): Unit = doClosePipeline(cause) + override final def close(cause: Option[Throwable]): Unit = doClosePipeline(cause) - final override protected def doClosePipeline(cause: Option[Throwable]): Unit = { + override protected final def doClosePipeline(cause: Option[Throwable]): Unit = { // intended to be called from within the SelectorLoop but if // it's closed it will be performed in the current thread def doClose(t: Throwable): Unit = { @@ -324,7 +325,8 @@ private[nio1] final class NIO1HeadStage( selectorLoop.executeTask(new Runnable { def run(): Unit = { logger.trace( - s"closeWithError($cause); readPromise: $readPromise, writePromise: $writePromise") + s"closeWithError($cause); readPromise: $readPromise, writePromise: $writePromise" + ) val c = cause match { case Some(ex) => logger.error(cause.get)("Abnormal NIO1HeadStage termination") diff --git a/core/src/main/scala/org/http4s/blaze/channel/nio1/NIO1SocketServerGroup.scala b/core/src/main/scala/org/http4s/blaze/channel/nio1/NIO1SocketServerGroup.scala index 55e9fe953..8978b6904 100644 --- a/core/src/main/scala/org/http4s/blaze/channel/nio1/NIO1SocketServerGroup.scala +++ b/core/src/main/scala/org/http4s/blaze/channel/nio1/NIO1SocketServerGroup.scala @@ -122,8 +122,8 @@ private final class NIO1SocketServerGroup private ( acceptorPool: SelectorLoopPool, workerPool: SelectorLoopPool, channelOptions: ChannelOptions, - maxConnections: Int) - extends ServerChannelGroup { + maxConnections: Int +) extends ServerChannelGroup { private[this] val logger = getLogger // Also acts as our intrinsic lock. private[this] val listeningSet = new mutable.HashSet[ServerChannelImpl]() @@ -140,8 +140,8 @@ private final class NIO1SocketServerGroup private ( private[this] class SocketAcceptor( key: SelectionKey, ch: ServerChannelImpl, - service: SocketPipelineBuilder) - extends Selectable { + service: SocketPipelineBuilder + ) extends Selectable { // Save it since once the channel is closed, we're in trouble. private[this] val closed = new AtomicBoolean(false) @@ -192,8 +192,8 @@ private final class NIO1SocketServerGroup private ( // minimize race conditions. private[this] final class ServerChannelImpl( val selectableChannel: ServerSocketChannel, - selectorLoop: SelectorLoop) - extends ServerChannel + selectorLoop: SelectorLoop + ) extends ServerChannel with NIO1Channel { @volatile private[this] var closed = false diff --git a/core/src/main/scala/org/http4s/blaze/channel/nio1/SelectorLoop.scala b/core/src/main/scala/org/http4s/blaze/channel/nio1/SelectorLoop.scala index 44a8256d8..f819d863f 100644 --- a/core/src/main/scala/org/http4s/blaze/channel/nio1/SelectorLoop.scala +++ b/core/src/main/scala/org/http4s/blaze/channel/nio1/SelectorLoop.scala @@ -264,7 +264,7 @@ final class SelectorLoop( */ def run(scratch: ByteBuffer): Unit - final override def run(): Unit = { + override final def run(): Unit = { val currentThread = Thread.currentThread if (currentThread == thread) run(scratch) else { diff --git a/core/src/main/scala/org/http4s/blaze/channel/nio2/ClientChannelFactory.scala b/core/src/main/scala/org/http4s/blaze/channel/nio2/ClientChannelFactory.scala index c040dc2c6..e10acbfc2 100644 --- a/core/src/main/scala/org/http4s/blaze/channel/nio2/ClientChannelFactory.scala +++ b/core/src/main/scala/org/http4s/blaze/channel/nio2/ClientChannelFactory.scala @@ -44,19 +44,22 @@ final class ClientChannelFactory( group: Option[AsynchronousChannelGroup] = None, channelOptions: ChannelOptions = ChannelOptions.DefaultOptions, scheduler: TickWheelExecutor = Execution.scheduler, - connectTimeout: Duration = Duration.Inf) { + connectTimeout: Duration = Duration.Inf +) { private[this] val logger = getLogger // for binary compatibility with <=0.14.6 def this( bufferSize: Int, group: Option[AsynchronousChannelGroup], - channelOptions: ChannelOptions) = + channelOptions: ChannelOptions + ) = this(bufferSize, group, channelOptions, Execution.scheduler, Duration.Inf) def connect( remoteAddress: SocketAddress, - bufferSize: Int = bufferSize): Future[HeadStage[ByteBuffer]] = { + bufferSize: Int = bufferSize + ): Future[HeadStage[ByteBuffer]] = { val p = Promise[HeadStage[ByteBuffer]]() try { @@ -65,7 +68,8 @@ final class ClientChannelFactory( val onTimeout = new Runnable { override def run(): Unit = { val exception = new SocketTimeoutException( - s"An attempt to establish connection with $remoteAddress timed out after $connectTimeout.") + s"An attempt to establish connection with $remoteAddress timed out after $connectTimeout." + ) val finishedWithTimeout = p.tryFailure(exception) if (finishedWithTimeout) try ch.close() diff --git a/core/src/main/scala/org/http4s/blaze/pipeline/PipelineBuilder.scala b/core/src/main/scala/org/http4s/blaze/pipeline/PipelineBuilder.scala index e72251bc3..abe9138a8 100644 --- a/core/src/main/scala/org/http4s/blaze/pipeline/PipelineBuilder.scala +++ b/core/src/main/scala/org/http4s/blaze/pipeline/PipelineBuilder.scala @@ -56,7 +56,8 @@ object LeafBuilder { */ final class TrunkBuilder[I1, O] private[pipeline] ( protected val head: MidStage[I1, _], - protected val tail: MidStage[_, O]) { + protected val tail: MidStage[_, O] +) { def append[N](stage: MidStage[O, N]): TrunkBuilder[I1, N] = { if (stage._prevStage != null) sys.error(s"Stage $stage must be fresh") if (stage.isInstanceOf[HeadStage[_]]) diff --git a/core/src/main/scala/org/http4s/blaze/pipeline/Stages.scala b/core/src/main/scala/org/http4s/blaze/pipeline/Stages.scala index 85ff8fba9..4564aabba 100644 --- a/core/src/main/scala/org/http4s/blaze/pipeline/Stages.scala +++ b/core/src/main/scala/org/http4s/blaze/pipeline/Stages.scala @@ -45,7 +45,7 @@ import scala.util.control.NonFatal */ sealed trait Stage { - final protected val logger = getLogger(this.getClass) + protected final val logger = getLogger(this.getClass) def name: String diff --git a/core/src/main/scala/org/http4s/blaze/pipeline/stages/TimeoutStageBase.scala b/core/src/main/scala/org/http4s/blaze/pipeline/stages/TimeoutStageBase.scala index 952ae9d33..50d6f8ec9 100644 --- a/core/src/main/scala/org/http4s/blaze/pipeline/stages/TimeoutStageBase.scala +++ b/core/src/main/scala/org/http4s/blaze/pipeline/stages/TimeoutStageBase.scala @@ -71,13 +71,13 @@ abstract class TimeoutStageBase[T](timeout: Duration, exec: TickWheelExecutor) super.stageShutdown() } - final protected def resetTimeout(): Unit = + protected final def resetTimeout(): Unit = setAndCancel(exec.schedule(killswitch, timeout)) - final protected def cancelTimeout(): Unit = + protected final def cancelTimeout(): Unit = setAndCancel(Cancelable.NoopCancel) - final protected def startTimeout(): Unit = resetTimeout() + protected final def startTimeout(): Unit = resetTimeout() } private object TimeoutStageBase { diff --git a/core/src/main/scala/org/http4s/blaze/pipeline/stages/monitors/IntervalConnectionMonitor.scala b/core/src/main/scala/org/http4s/blaze/pipeline/stages/monitors/IntervalConnectionMonitor.scala index ca65a08d2..ba6d15c9b 100644 --- a/core/src/main/scala/org/http4s/blaze/pipeline/stages/monitors/IntervalConnectionMonitor.scala +++ b/core/src/main/scala/org/http4s/blaze/pipeline/stages/monitors/IntervalConnectionMonitor.scala @@ -21,7 +21,8 @@ import scala.concurrent.duration.Duration class IntervalConnectionMonitor(val interval: Duration) extends ConnectionMonitor { require( interval.isFinite && interval.toNanos > 1, - "Duration must be Finite and greater than 1 ns") + "Duration must be Finite and greater than 1 ns" + ) private val alpha = 1.0 / (interval.toNanos + 1).toDouble @@ -74,7 +75,8 @@ class IntervalConnectionMonitor(val interval: Duration) extends ConnectionMonito ototal: Long, connmean: Double, conntotal: Long, - connlive: Long) { + connlive: Long + ) { override def toString: String = { val mb = (1024 * 1024).toDouble val (f1, unit1) = @@ -99,7 +101,8 @@ class IntervalConnectionMonitor(val interval: Duration) extends ConnectionMonito ototal / f2, connmean, conntotal, - connlive) + connlive + ) } } @@ -112,7 +115,8 @@ class IntervalConnectionMonitor(val interval: Duration) extends ConnectionMonito outbound.getTotal(), conns.getMean(), conns.getTotal(), - conns.getLive()) + conns.getLive() + ) })) override protected def connectionAccepted(): Unit = conns.update(1) diff --git a/core/src/main/scala/org/http4s/blaze/util/TaskQueue.scala b/core/src/main/scala/org/http4s/blaze/util/TaskQueue.scala index fc6bef419..1d67e4fd3 100644 --- a/core/src/main/scala/org/http4s/blaze/util/TaskQueue.scala +++ b/core/src/main/scala/org/http4s/blaze/util/TaskQueue.scala @@ -139,7 +139,8 @@ private[blaze] object TaskQueue { def run(): Unit = { val ex = bug( "Illegal state reached! TaskQueue found executing " + - "a marker node. Please report as a bug.") + "a marker node. Please report as a bug." + ) logger.error(ex)("Unexpected state") } }) diff --git a/core/src/main/scala/org/http4s/blaze/util/TickWheelExecutor.scala b/core/src/main/scala/org/http4s/blaze/util/TickWheelExecutor.scala index 553c229f5..bb21b2367 100644 --- a/core/src/main/scala/org/http4s/blaze/util/TickWheelExecutor.scala +++ b/core/src/main/scala/org/http4s/blaze/util/TickWheelExecutor.scala @@ -237,7 +237,7 @@ class TickWheelExecutor(wheelSize: Int = DefaultWheelSize, val tick: Duration = * @param next * next Node in the list or `tailNode` if this is the last element */ - final private class Node( + private final class Node( r: Runnable, ec: ExecutionContext, val expiration: Long, diff --git a/core/src/main/scala/org/http4s/blaze/util/package.scala b/core/src/main/scala/org/http4s/blaze/util/package.scala index 9cc085651..61581f07e 100644 --- a/core/src/main/scala/org/http4s/blaze/util/package.scala +++ b/core/src/main/scala/org/http4s/blaze/util/package.scala @@ -26,7 +26,8 @@ package object util { */ private[blaze] def bug(message: String): AssertionError = new AssertionError( - s"This is a bug. Please report to https://github.com/http4s/blaze/issues: $message") + s"This is a bug. Please report to https://github.com/http4s/blaze/issues: $message" + ) // Can replace with `Future.unit` when we drop 2.11 support private[blaze] val FutureUnit: Future[Unit] = Future.successful(()) diff --git a/core/src/test/scala/org/http4s/blaze/channel/ChannelOptionsSuite.scala b/core/src/test/scala/org/http4s/blaze/channel/ChannelOptionsSuite.scala index 5b38a6cb1..f8e0dd840 100644 --- a/core/src/test/scala/org/http4s/blaze/channel/ChannelOptionsSuite.scala +++ b/core/src/test/scala/org/http4s/blaze/channel/ChannelOptionsSuite.scala @@ -62,9 +62,11 @@ class ChannelOptionsSuite extends FunSuite { assertEquals( ch.getOption[java.lang.Boolean](java.net.StandardSocketOptions.TCP_NODELAY), - java.lang.Boolean.TRUE) + java.lang.Boolean.TRUE + ) assertEquals( ch.getOption[java.lang.Boolean](java.net.StandardSocketOptions.SO_KEEPALIVE), - java.lang.Boolean.FALSE) + java.lang.Boolean.FALSE + ) } } diff --git a/core/src/test/scala/org/http4s/blaze/channel/EchoStage.scala b/core/src/test/scala/org/http4s/blaze/channel/EchoStage.scala index 3c1c47ac3..10767fd37 100644 --- a/core/src/test/scala/org/http4s/blaze/channel/EchoStage.scala +++ b/core/src/test/scala/org/http4s/blaze/channel/EchoStage.scala @@ -28,9 +28,9 @@ class EchoStage extends TailStage[ByteBuffer] { val msg = "echo: ".getBytes - private implicit def ec: ExecutionContext = util.Execution.trampoline + implicit private def ec: ExecutionContext = util.Execution.trampoline - final override def stageStartup(): Unit = + override final def stageStartup(): Unit = channelRead().onComplete { case Success(buff) => val b = ByteBuffer.allocate(buff.remaining() + msg.length) diff --git a/core/src/test/scala/org/http4s/blaze/pipeline/PipelineSuite.scala b/core/src/test/scala/org/http4s/blaze/pipeline/PipelineSuite.scala index 6de75020a..a8846c596 100644 --- a/core/src/test/scala/org/http4s/blaze/pipeline/PipelineSuite.scala +++ b/core/src/test/scala/org/http4s/blaze/pipeline/PipelineSuite.scala @@ -23,7 +23,7 @@ import scala.concurrent.Future import scala.concurrent.ExecutionContext class PipelineSuite extends BlazeTestSuite { - private implicit def ec: ExecutionContext = Execution.trampoline + implicit private def ec: ExecutionContext = Execution.trampoline class IntHead extends HeadStage[Int] { def name = "IntHead" diff --git a/core/src/test/scala/org/http4s/blaze/pipeline/stages/DelayHead.scala b/core/src/test/scala/org/http4s/blaze/pipeline/stages/DelayHead.scala index 5913f23ac..f42b87c63 100644 --- a/core/src/test/scala/org/http4s/blaze/pipeline/stages/DelayHead.scala +++ b/core/src/test/scala/org/http4s/blaze/pipeline/stages/DelayHead.scala @@ -63,7 +63,8 @@ abstract class DelayHead[I](delay: Duration) extends HeadStage[I] { } }, delay.toNanos, - TimeUnit.NANOSECONDS) + TimeUnit.NANOSECONDS + ) p.future } @@ -77,7 +78,8 @@ abstract class DelayHead[I](delay: Duration) extends HeadStage[I] { } }, delay.toNanos, - TimeUnit.NANOSECONDS) + TimeUnit.NANOSECONDS + ) rememberPromise(p) p.future diff --git a/core/src/test/scala/org/http4s/blaze/pipeline/stages/SSLStageSuite.scala b/core/src/test/scala/org/http4s/blaze/pipeline/stages/SSLStageSuite.scala index f7fd7c248..732be0dc8 100644 --- a/core/src/test/scala/org/http4s/blaze/pipeline/stages/SSLStageSuite.scala +++ b/core/src/test/scala/org/http4s/blaze/pipeline/stages/SSLStageSuite.scala @@ -31,7 +31,7 @@ import scala.concurrent.{ExecutionContext, Future} import scala.util.control.NonFatal class SSLStageSuite extends BlazeTestSuite { - private implicit def ec: ExecutionContext = Execution.trampoline + implicit private def ec: ExecutionContext = Execution.trampoline private def debug = false @@ -42,7 +42,8 @@ class SSLStageSuite extends BlazeTestSuite { // The battery of tests for both client and server private def testBattery( testSuitePrefix: String, - mkClientServerEngines: => (SSLEngine, SSLEngine)) = { + mkClientServerEngines: => (SSLEngine, SSLEngine) + ) = { test(testSuitePrefix + " should transcode a single buffer") { val (headEng, stageEng) = mkClientServerEngines val head = new SSLSeqHead(Seq(mkBuffer("Foo")), headEng) @@ -92,7 +93,8 @@ class SSLStageSuite extends BlazeTestSuite { r <- Future(BufferTools.mkString(head.results)) h <- Future(head.multipleWrite) } yield r -> h, - s + s -> false)) + s + s -> false + )) } test(testSuitePrefix + " should transcode multiple single byte buffers") { diff --git a/core/src/test/scala/org/http4s/blaze/util/ActorSuite.scala b/core/src/test/scala/org/http4s/blaze/util/ActorSuite.scala index 44c68d5b0..f0fea7d78 100644 --- a/core/src/test/scala/org/http4s/blaze/util/ActorSuite.scala +++ b/core/src/test/scala/org/http4s/blaze/util/ActorSuite.scala @@ -57,7 +57,8 @@ class ActorSuite extends FunSuite { flag.set(t) latch.countDown() }, - global) + global + ) for (_ <- 0 until senders) global.execute(() => @@ -102,7 +103,8 @@ class ActorSuite extends FunSuite { } test( - "An actor under load shouldn't have a stack overflow dueling actors with a trampolining ec") { + "An actor under load shouldn't have a stack overflow dueling actors with a trampolining ec" + ) { val latch = new CountDownLatch(1) implicit val ec = Execution.trampoline 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 6e1366f64..6b2e8a6b7 100644 --- a/core/src/test/scala/org/http4s/blaze/util/BufferToolsSuite.scala +++ b/core/src/test/scala/org/http4s/blaze/util/BufferToolsSuite.scala @@ -54,7 +54,8 @@ class BufferToolsSuite extends FunSuite { } test( - "BufferTools.concatBuffers should append the result of one to the end of another if there is room") { + "BufferTools.concatBuffers should append the result of one to the end of another if there is room" + ) { val b1 = ByteBuffer.allocate(9) b1.position(1) // offset by 1 to simulated already having read a byte b1.putInt(1).flip().position(1) @@ -102,7 +103,8 @@ class BufferToolsSuite extends FunSuite { } test( - "BufferTools.takeSlice should throw an `IllegalArgumentException` if you try to slice too many bytes") { + "BufferTools.takeSlice should throw an `IllegalArgumentException` if you try to slice too many bytes" + ) { val a = ByteBuffer.allocate(10) a.putInt(123).putInt(456).flip() assertEquals(a.remaining(), 8) @@ -116,12 +118,14 @@ class BufferToolsSuite extends FunSuite { }, _ => fail( - "BufferTools.takeSlice should throw an `IllegalArgumentException` if you try to slice too many bytes") + "BufferTools.takeSlice should throw an `IllegalArgumentException` if you try to slice too many bytes" + ) ) } test( - "BufferTools.takeSlice should throw an `IllegalArgumentException` if you try to slice negative bytes") { + "BufferTools.takeSlice should throw an `IllegalArgumentException` if you try to slice negative bytes" + ) { val a = ByteBuffer.allocate(10) a.putInt(123).putInt(456).flip() assertEquals(a.remaining(), 8) @@ -135,14 +139,16 @@ class BufferToolsSuite extends FunSuite { }, _ => fail( - "BufferTools.takeSlice should throw an `IllegalArgumentException` if you try to slice negative bytes") + "BufferTools.takeSlice should throw an `IllegalArgumentException` if you try to slice negative bytes" + ) ) } test("BufferTools.checkEmpty should check if buffers are empty") { assertEquals( BufferTools.checkEmpty(Array(ByteBuffer.allocate(0), ByteBuffer.allocate(3))), - false) + false + ) assertEquals(BufferTools.checkEmpty(Seq(ByteBuffer.allocate(0), ByteBuffer.allocate(3))), false) assert(BufferTools.checkEmpty(Array(ByteBuffer.allocate(0), ByteBuffer.allocate(0)))) @@ -173,7 +179,8 @@ class BufferToolsSuite extends FunSuite { } test( - "BufferTools.dropEmpty should drop empty buffers until the first non-empty buffer except the last") { + "BufferTools.dropEmpty should drop empty buffers until the first non-empty buffer except the last" + ) { val arr = Array(buff0, buff0) assertEquals(BufferTools.dropEmpty(arr), 1) assert(arr(0) eq BufferTools.emptyBuffer) @@ -295,21 +302,24 @@ class BufferToolsSuite extends FunSuite { } test( - "BufferTools.areDirectOrEmpty should be true for a collection of direct buffers with a null element") { + "BufferTools.areDirectOrEmpty should be true for a collection of direct buffers with a null element" + ) { val buffs = getDirect(4) buffs(3) = null assert(BufferTools.areDirectOrEmpty(buffs)) } test( - "BufferTools.areDirectOrEmpty should be false for a collection with a non-empty heap buffer in it") { + "BufferTools.areDirectOrEmpty should be false for a collection with a non-empty heap buffer in it" + ) { val buffs = getDirect(4) buffs(3) = ByteBuffer.allocate(4) assertEquals(BufferTools.areDirectOrEmpty(buffs), false) } test( - "BufferTools.areDirectOrEmpty should be true for a collection with an empty heap buffer in it") { + "BufferTools.areDirectOrEmpty should be true for a collection with an empty heap buffer in it" + ) { val buffs = getDirect(4) buffs(3) = ByteBuffer.allocate(0) assert(BufferTools.areDirectOrEmpty(buffs)) diff --git a/core/src/test/scala/org/http4s/blaze/util/StageToolsSuite.scala b/core/src/test/scala/org/http4s/blaze/util/StageToolsSuite.scala index 1c7a88e56..535e0d2a4 100644 --- a/core/src/test/scala/org/http4s/blaze/util/StageToolsSuite.scala +++ b/core/src/test/scala/org/http4s/blaze/util/StageToolsSuite.scala @@ -36,7 +36,8 @@ class StageToolsSuite extends BlazeTestSuite { } test( - "StageTools.accumulateAtLeast should accumulate only one buffer if it satisfies the number of bytes required") { + "StageTools.accumulateAtLeast should accumulate only one buffer if it satisfies the number of bytes required" + ) { val buff = ByteBuffer.wrap(Array[Byte](1, 2, 3)) val stage = new TailStage[ByteBuffer] { def name: String = "TestTailStage" diff --git a/core/src/test/scala/org/http4s/blaze/util/TaskQueueSuite.scala b/core/src/test/scala/org/http4s/blaze/util/TaskQueueSuite.scala index cd9296513..93435959f 100644 --- a/core/src/test/scala/org/http4s/blaze/util/TaskQueueSuite.scala +++ b/core/src/test/scala/org/http4s/blaze/util/TaskQueueSuite.scala @@ -107,7 +107,8 @@ class TaskQueueSuite extends FunSuite { counter.incrementAndGet() () }, - TaskQueue.Enqueued) + TaskQueue.Enqueued + ) sleepLatch.countDown() t.join(30000) // 30 seconds max diff --git a/examples/src/main/scala/org/http4s/blaze/examples/EchoServer.scala b/examples/src/main/scala/org/http4s/blaze/examples/EchoServer.scala index e3a496f16..fbaa51fdf 100644 --- a/examples/src/main/scala/org/http4s/blaze/examples/EchoServer.scala +++ b/examples/src/main/scala/org/http4s/blaze/examples/EchoServer.scala @@ -59,7 +59,7 @@ class EchoServer { val msg = "echo: ".getBytes - final override def stageStartup(): Unit = + override final def stageStartup(): Unit = channelRead().onComplete { case Success(buff) => val b = BufferTools.allocate(buff.remaining() + msg.length) diff --git a/http/src/main/scala/org/http4s/blaze/http/BodyReader.scala b/http/src/main/scala/org/http4s/blaze/http/BodyReader.scala index 0e5190b5a..f9580fba0 100644 --- a/http/src/main/scala/org/http4s/blaze/http/BodyReader.scala +++ b/http/src/main/scala/org/http4s/blaze/http/BodyReader.scala @@ -76,7 +76,8 @@ object BodyReader { final class BodyReaderOverflowException(val max: Int, val accumulated: Long) extends Exception( - s"Message body overflowed. Maximum permitted: $max, accumulated: $accumulated") + s"Message body overflowed. Maximum permitted: $max, accumulated: $accumulated" + ) /** The canonical empty [[BodyReader]] * diff --git a/http/src/main/scala/org/http4s/blaze/http/HeaderNames.scala b/http/src/main/scala/org/http4s/blaze/http/HeaderNames.scala index 9c2906dc5..03734e71d 100644 --- a/http/src/main/scala/org/http4s/blaze/http/HeaderNames.scala +++ b/http/src/main/scala/org/http4s/blaze/http/HeaderNames.scala @@ -61,5 +61,6 @@ object HeaderNames { */ private val validChars = BitSet( - (('0' to '9') ++ ('a' to 'z') ++ "!#$%&'*+-.^_`|~").map(_.toInt): _*) + (('0' to '9') ++ ('a' to 'z') ++ "!#$%&'*+-.^_`|~").map(_.toInt): _* + ) } diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/DefaultFlowStrategy.scala b/http/src/main/scala/org/http4s/blaze/http/http2/DefaultFlowStrategy.scala index 83263e668..a30954015 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/DefaultFlowStrategy.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/DefaultFlowStrategy.scala @@ -23,14 +23,16 @@ final class DefaultFlowStrategy(localSettings: Http2Settings) extends FlowStrate check( localSettings.initialWindowSize, session.sessionInboundWindow, - session.sessionUnconsumedBytes) + session.sessionUnconsumedBytes + ) override def checkStream(stream: StreamFlowWindow): Increment = { val sessionAck = checkSession(stream.sessionFlowControl) val streamAck = check( localSettings.initialWindowSize, stream.streamInboundWindow, - stream.streamUnconsumedBytes) + stream.streamUnconsumedBytes + ) FlowStrategy.increment(sessionAck, streamAck) } diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/FrameDecoder.scala b/http/src/main/scala/org/http4s/blaze/http/http2/FrameDecoder.scala index 624ed7f50..b3b3684ec 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/FrameDecoder.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/FrameDecoder.scala @@ -84,7 +84,9 @@ private class FrameDecoder(localSettings: Http2Settings, listener: FrameListener case _: BufferUnderflowException => Error( FRAME_SIZE_ERROR.goaway( - s"Frame type ${hexStr(frameType.toInt)} and size $len underflowed")) + s"Frame type ${hexStr(frameType.toInt)} and size $len underflowed" + ) + ) } finally { // reset buffer limits buffer.limit(oldLimit) @@ -172,7 +174,8 @@ private class FrameDecoder(localSettings: Http2Settings, listener: FrameListener priority, Flags.END_HEADERS(flags), Flags.END_STREAM(flags), - buffer.slice()) + buffer.slice() + ) } } @@ -229,7 +232,9 @@ private class FrameDecoder(localSettings: Http2Settings, listener: FrameListener else if (promisedId == streamId) Error( PROTOCOL_ERROR.goaway( - s"PUSH_PROMISE frame with promised stream of the same stream ${hexStr(streamId)}")) + s"PUSH_PROMISE frame with promised stream of the same stream ${hexStr(streamId)}" + ) + ) else { val r = limitPadding(padding, buffer) if (!r.success) r @@ -238,7 +243,8 @@ private class FrameDecoder(localSettings: Http2Settings, listener: FrameListener streamId, promisedId, Flags.END_HEADERS(flags), - buffer.slice()) + buffer.slice() + ) } } @@ -275,7 +281,9 @@ private class FrameDecoder(localSettings: Http2Settings, listener: FrameListener if (buffer.remaining != 4) Error( FRAME_SIZE_ERROR.goaway( - s"WindowUpdate with invalid frame size. Expected 4, found ${buffer.remaining}")) + s"WindowUpdate with invalid frame size. Expected 4, found ${buffer.remaining}" + ) + ) else { val size = buffer.getInt() & Masks.INT31 if (size != 0) listener.onWindowUpdateFrame(streamId, size) @@ -293,7 +301,8 @@ private class FrameDecoder(localSettings: Http2Settings, listener: FrameListener private[this] def decodeContinuationFrame( buffer: ByteBuffer, streamId: Int, - flags: Byte): Result = + flags: Byte + ): Result = if (streamId == 0) { val msg = s"CONTINUATION frame with invalid stream dependency on 0x0" Error(PROTOCOL_ERROR.goaway(msg)) @@ -335,7 +344,8 @@ private object FrameDecoder { // frame payload or greater, the recipient MUST treat this as a // connection error (Section 5.4.1) of type PROTOCOL_ERROR. Error( - PROTOCOL_ERROR.goaway(s"Padding ($padding) exceeds payload length: ${buffer.remaining}")) + PROTOCOL_ERROR.goaway(s"Padding ($padding) exceeds payload length: ${buffer.remaining}") + ) else { buffer.limit(buffer.limit() - padding) Continue diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/FrameEncoder.scala b/http/src/main/scala/org/http4s/blaze/http/http2/FrameEncoder.scala index 5ab4295b3..1a0413c48 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/FrameEncoder.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/FrameEncoder.scala @@ -96,7 +96,8 @@ private final class FrameEncoder(remoteSettings: Http2Settings, headerEncoder: H endHeaders = true, endStream, padding = 0, - rawHeaders) + rawHeaders + ) else { // need to fragment val acc = new ArrayBuffer[ByteBuffer] @@ -109,7 +110,8 @@ private final class FrameEncoder(remoteSettings: Http2Settings, headerEncoder: H endHeaders = false, endStream, padding = 0, - headersBuf) + headersBuf + ) while (rawHeaders.hasRemaining) { val size = math.min(limit, rawHeaders.remaining) diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/FrameListener.scala b/http/src/main/scala/org/http4s/blaze/http/http2/FrameListener.scala index d8f2a0c6f..4d66c722a 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/FrameListener.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/FrameListener.scala @@ -77,7 +77,8 @@ private trait FrameListener { priority: Priority, endHeaders: Boolean, endStream: Boolean, - data: ByteBuffer): Result + data: ByteBuffer + ): Result /** Called on successful receipt of a CONTINUATION frame * @@ -139,7 +140,8 @@ private trait FrameListener { streamId: Int, promisedId: Int, end_headers: Boolean, - data: ByteBuffer): Result + data: ByteBuffer + ): Result /** Called on successful receipt of a PING frame * diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/FrameSerializer.scala b/http/src/main/scala/org/http4s/blaze/http/http2/FrameSerializer.scala index dcab893e1..872077ce5 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/FrameSerializer.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/FrameSerializer.scala @@ -48,7 +48,8 @@ private[http2] object FrameSerializer { streamId: Int, endStream: Boolean, padding: Int, - data: ByteBuffer): Seq[ByteBuffer] = { + data: ByteBuffer + ): Seq[ByteBuffer] = { require(0 < streamId, "bad DATA frame stream id") require(0 <= padding && padding <= 256, "Invalid padding of DATA frame") @@ -106,7 +107,7 @@ private[http2] object FrameSerializer { val header = BufferTools.allocate(HeaderSize + nonDataSize) val payloadSize = nonDataSize + headerData.remaining + (if (padded) - (padding - 1) + padding - 1 else 0) writeFrameHeader(payloadSize, FrameTypes.HEADERS, flags.toByte, streamId, header) @@ -198,7 +199,8 @@ private[http2] object FrameSerializer { FrameTypes.PUSH_PROMISE, flags.toByte, streamId, - buffer) + buffer + ) if (padded) // padding of 1 is represented by the padding field and no trailing padding @@ -248,7 +250,8 @@ private[http2] object FrameSerializer { require(0 <= streamId, "Invalid stream id for WINDOW_UPDATE") require( 0 < increment && increment <= Integer.MAX_VALUE, - "Invalid stream increment for WINDOW_UPDATE") + "Invalid stream increment for WINDOW_UPDATE" + ) val size = 4 val buffer = BufferTools.allocate(HeaderSize + size) @@ -263,7 +266,8 @@ private[http2] object FrameSerializer { def mkContinuationFrame( streamId: Int, endHeaders: Boolean, - headerBuffer: ByteBuffer): Seq[ByteBuffer] = { + headerBuffer: ByteBuffer + ): Seq[ByteBuffer] = { require(0 < streamId, "Invalid stream id for CONTINUATION frame") val flags: Byte = if (endHeaders) Flags.END_HEADERS else 0x0 val buffer = BufferTools.allocate(HeaderSize) 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 6b2ea5b35..1d14bea73 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 @@ -35,8 +35,8 @@ import Http2Exception.PROTOCOL_ERROR */ private abstract class HeaderAggregatingFrameListener( localSettings: Http2Settings, - headerDecoder: HeaderDecoder) - extends FrameListener { + headerDecoder: HeaderDecoder +) extends FrameListener { private[this] sealed trait PartialFrame { def streamId: Int var buffer: ByteBuffer @@ -46,8 +46,8 @@ private abstract class HeaderAggregatingFrameListener( streamId: Int, priority: Priority, endStream: Boolean, - var buffer: ByteBuffer) - extends PartialFrame + var buffer: ByteBuffer + ) extends PartialFrame private[this] case class PPromise(streamId: Int, promisedId: Int, var buffer: ByteBuffer) extends PartialFrame @@ -90,9 +90,9 @@ private abstract class HeaderAggregatingFrameListener( final def setMaxHeaderTableSize(maxSize: Int): Unit = headerDecoder.setMaxHeaderTableSize(maxSize) - final override def inHeaderSequence: Boolean = hInfo != null + override final def inHeaderSequence: Boolean = hInfo != null - final override def onHeadersFrame( + override final def onHeadersFrame( streamId: Int, priority: Priority, endHeaders: Boolean, @@ -101,8 +101,11 @@ private abstract class HeaderAggregatingFrameListener( ): Result = if (inHeaderSequence) Error( - PROTOCOL_ERROR.goaway(s"Received HEADERS frame while in in headers sequence. Stream id " + - FrameDecoder.hexStr(streamId))) + PROTOCOL_ERROR.goaway( + s"Received HEADERS frame while in in headers sequence. Stream id " + + FrameDecoder.hexStr(streamId) + ) + ) else if (buffer.remaining > localSettings.maxHeaderListSize) headerSizeError(buffer.remaining, streamId) else if (endHeaders) { @@ -117,7 +120,7 @@ private abstract class HeaderAggregatingFrameListener( Continue } - final override def onPushPromiseFrame( + override final def onPushPromiseFrame( streamId: Int, promisedId: Int, endHeaders: Boolean, @@ -137,7 +140,7 @@ private abstract class HeaderAggregatingFrameListener( Continue } - final override def onContinuationFrame( + override final def onContinuationFrame( streamId: Int, endHeaders: Boolean, buffer: ByteBuffer diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/HeaderDecoder.scala b/http/src/main/scala/org/http4s/blaze/http/http2/HeaderDecoder.scala index 787ea3e8e..4add9dfc2 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/HeaderDecoder.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/HeaderDecoder.scala @@ -68,7 +68,8 @@ private final class HeaderDecoder( def finish(): Seq[(String, String)] = { if (!sawEndHeaders) throw new IllegalStateException( - "Should only be called after decoding the a terminating header fragment") + "Should only be called after decoding the a terminating header fragment" + ) leftovers = null headerBlockSize = 0 @@ -91,7 +92,8 @@ private final class HeaderDecoder( buffer: ByteBuffer, streamId: Int, endHeaders: Boolean, - listener: HeaderListener): MaybeError = { + listener: HeaderListener + ): MaybeError = { if (sawEndHeaders) throw new IllegalStateException("called doDecode() after receiving an endHeaders flag") diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/Http2Settings.scala b/http/src/main/scala/org/http4s/blaze/http/http2/Http2Settings.scala index 0a2dbb9c8..bbb2593f8 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/Http2Settings.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/Http2Settings.scala @@ -88,8 +88,8 @@ case class ImmutableHttp2Settings( pushEnabled: Boolean, maxConcurrentStreams: Int, maxFrameSize: Int, - maxHeaderListSize: Int) - extends Http2Settings + maxHeaderListSize: Int +) extends Http2Settings object Http2Settings { type SettingValue = Int @@ -154,7 +154,9 @@ object Http2Settings { case Setting(_, value) if value < 0 => Some( Http2Exception.PROTOCOL_ERROR.goaway( - s"Integer overflow for setting ${setting.name}: $value")) + s"Integer overflow for setting ${setting.name}: $value" + ) + ) case _ => None } diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/OutboundStreamStateImpl.scala b/http/src/main/scala/org/http4s/blaze/http/http2/OutboundStreamStateImpl.scala index 47433f6a6..48b515352 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/OutboundStreamStateImpl.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/OutboundStreamStateImpl.scala @@ -30,23 +30,23 @@ private abstract class OutboundStreamStateImpl(session: SessionCore) protected def registerStream(): Option[Int] - final override def initialized: Boolean = lazyStreamId != -1 + override final def initialized: Boolean = lazyStreamId != -1 - final override def name: String = { + override final def name: String = { val id = if (initialized) Integer.toString(streamId) else "uninitialized" s"OutboundStreamState($id)" } - final override def streamId: Int = + override final def streamId: Int = if (initialized) lazyStreamId else uninitializedException() - final override def flowWindow: StreamFlowWindow = + override final def flowWindow: StreamFlowWindow = if (initialized) lazyFlowWindow else uninitializedException() // We need to establish whether the stream has been initialized yet and try to acquire a new ID if not - final override protected def invokeStreamWrite(msg: StreamFrame, p: Promise[Unit]): Unit = + override protected final def invokeStreamWrite(msg: StreamFrame, p: Promise[Unit]): Unit = if (initialized) super.invokeStreamWrite(msg, p) else if (session.state.closing) { diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/PriorKnowledgeHandshaker.scala b/http/src/main/scala/org/http4s/blaze/http/http2/PriorKnowledgeHandshaker.scala index e487818a3..e737ae0b3 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/PriorKnowledgeHandshaker.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/PriorKnowledgeHandshaker.scala @@ -26,7 +26,7 @@ import scala.concurrent.{ExecutionContext, Future} /** Base type for performing the HTTP/2 prior knowledge handshake */ abstract class PriorKnowledgeHandshaker[T](localSettings: ImmutableHttp2Settings) extends TailStage[ByteBuffer] { - final protected implicit def ec: ExecutionContext = Execution.trampoline + implicit protected final def ec: ExecutionContext = Execution.trampoline override def name: String = s"${getClass.getSimpleName}($localSettings)" @@ -67,7 +67,8 @@ abstract class PriorKnowledgeHandshaker[T](localSettings: ImmutableHttp2Settings def insufficientData = { logger.debug( s"Insufficient data. Current representation: " + - BufferTools.hexString(acc, 256)) + BufferTools.hexString(acc, 256) + ) channelRead().flatMap(buff => readSettings(BufferTools.concatBuffers(acc, buff))) } @@ -78,7 +79,8 @@ abstract class PriorKnowledgeHandshaker[T](localSettings: ImmutableHttp2Settings // The settings frame is too large so abort val ex = Http2Exception.FRAME_SIZE_ERROR.goaway( "While waiting for initial settings frame, encountered frame of " + - s"size $size exceeded MAX_FRAME_SIZE (${localSettings.maxFrameSize})") + s"size $size exceeded MAX_FRAME_SIZE (${localSettings.maxFrameSize})" + ) logger.info(ex)(s"Received SETTINGS frame that was to large") sendGoAway(ex) @@ -100,7 +102,8 @@ abstract class PriorKnowledgeHandshaker[T](localSettings: ImmutableHttp2Settings case None => logger.debug( s"Successfully received settings frame. Current " + - s"remote settings: $remoteSettings") + s"remote settings: $remoteSettings" + ) sendSettingsAck().map(_ => remoteSettings -> acc) case Some(ex) => @@ -113,7 +116,8 @@ abstract class PriorKnowledgeHandshaker[T](localSettings: ImmutableHttp2Settings case Right(SettingsFrame(None)) => // was an ack! This is a PROTOCOL_ERROR logger.info(s"Received a SETTINGS ack frame which is a protocol error. Shutting down.") val ex = Http2Exception.PROTOCOL_ERROR.goaway( - "Received a SETTINGS ack before receiving remote settings") + "Received a SETTINGS ack before receiving remote settings" + ) sendGoAway(ex) case Left(http2Exception) => sendGoAway(http2Exception) diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/SessionFlowControlImpl.scala b/http/src/main/scala/org/http4s/blaze/http/http2/SessionFlowControlImpl.scala index 31b8f9da3..e45123c7c 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/SessionFlowControlImpl.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/SessionFlowControlImpl.scala @@ -68,7 +68,8 @@ private class SessionFlowControlImpl( if (0 < update.stream) { stream.streamInboundAcked(update.stream) session.writeController.write( - session.http2Encoder.streamWindowUpdate(stream.streamId, update.stream)) + session.http2Encoder.streamWindowUpdate(stream.streamId, update.stream) + ) () } } @@ -88,14 +89,14 @@ private class SessionFlowControlImpl( * @note * the stream [[StreamFlowWindow]] is not thread safe. */ - final override def newStreamFlowWindow(streamId: Int): StreamFlowWindow = { + override final def newStreamFlowWindow(streamId: Int): StreamFlowWindow = { require(0 < streamId) logger.trace(s"Created new stream: $streamId") new StreamFlowWindowImpl(streamId) } /** Get the number of bytes remaining in the inbound flow window */ - final override def sessionInboundWindow: Int = _sessionInboundWindow + override final def sessionInboundWindow: Int = _sessionInboundWindow /** Observe inbound bytes that don't belong to an active inbound stream * @@ -104,7 +105,7 @@ private class SessionFlowControlImpl( * @return * `true` if there was sufficient session flow window remaining, `false` otherwise. */ - final override def sessionInboundObserved(count: Int): Boolean = { + override final def sessionInboundObserved(count: Int): Boolean = { logger.trace(s"Observed $count inbound session bytes. $sessionWindowString") require(0 <= count) @@ -117,7 +118,7 @@ private class SessionFlowControlImpl( } /** Update the session inbound window */ - final override def sessionInboundAcked(count: Int): Unit = { + override final def sessionInboundAcked(count: Int): Unit = { logger.trace(s"Acked $count inbound session bytes. $sessionWindowString") require(0 <= count) @@ -125,7 +126,7 @@ private class SessionFlowControlImpl( } /** Signal that inbound bytes have been consumed that are not tracked by a stream */ - final override def sessionInboundConsumed(count: Int): Unit = { + override final def sessionInboundConsumed(count: Int): Unit = { logger.trace(s"Consumed $count inbound session bytes. $sessionWindowString") require(0 <= count) if (count > _sessionUnconsumedInbound) { @@ -139,10 +140,10 @@ private class SessionFlowControlImpl( } /** Get the total number of inbound bytes that have yet to be consumed by the streams */ - final override def sessionUnconsumedBytes: Int = _sessionUnconsumedInbound + override final def sessionUnconsumedBytes: Int = _sessionUnconsumedInbound /** Get the remaining bytes in the sessions outbound flow window */ - final override def sessionOutboundWindow: Int = _sessionOutboundWindow + override final def sessionOutboundWindow: Int = _sessionOutboundWindow /** Update the session outbound window * @@ -150,7 +151,7 @@ private class SessionFlowControlImpl( * there is no way to withdraw outbound bytes directly from the session as there should always * be an associated stream when sending flow control counted bytes outbound. */ - final override def sessionOutboundAcked(count: Int): Option[Http2Exception] = { + override final def sessionOutboundAcked(count: Int): Option[Http2Exception] = { logger.trace(s"$count outbound session bytes were ACKed. $sessionWindowString") // Updates MUST be greater than 0, otherwise its protocol error // https://tools.ietf.org/html/rfc7540#section-6.9 @@ -204,7 +205,8 @@ private class SessionFlowControlImpl( override def remoteSettingsInitialWindowChange(delta: Int): Option[Http2Exception] = { logger.trace( - s"Stream($streamId) outbound window adjusted by $delta bytes. $streamWindowString") + s"Stream($streamId) outbound window adjusted by $delta bytes. $streamWindowString" + ) // A sender MUST NOT allow a flow-control window to exceed 2^31-1 octets. // https://tools.ietf.org/html/rfc7540#section-6.9.2 if (Int.MaxValue - streamOutboundWindow < delta) @@ -224,7 +226,8 @@ private class SessionFlowControlImpl( _streamOutboundWindow -= withdrawal logger.trace( - s"Stream($streamId) requested $request outbound bytes, $withdrawal were granted. $streamWindowString") + s"Stream($streamId) requested $request outbound bytes, $withdrawal were granted. $streamWindowString" + ) withdrawal } @@ -235,7 +238,8 @@ private class SessionFlowControlImpl( require(0 <= count) if (count > streamInboundWindow || count > sessionInboundWindow) { logger.info( - s"Stream($streamId) observed $count inbound bytes which overflowed inbound window. $streamWindowString") + s"Stream($streamId) observed $count inbound bytes which overflowed inbound window. $streamWindowString" + ) false } else { _streamUnconsumedInbound += count diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/SessionFrameListener.scala b/http/src/main/scala/org/http4s/blaze/http/http2/SessionFrameListener.scala index 8d2e6a99e..e9d305272 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/SessionFrameListener.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/SessionFrameListener.scala @@ -31,15 +31,16 @@ import org.http4s.blaze.http.http2.Http2Settings.Setting private class SessionFrameListener( session: SessionCore, isClient: Boolean, - headerDecoder: HeaderDecoder) - extends HeaderAggregatingFrameListener(session.localSettings, headerDecoder) { + headerDecoder: HeaderDecoder +) extends HeaderAggregatingFrameListener(session.localSettings, headerDecoder) { // Concrete methods //////////////////////////////////////////////////////////////////// override def onCompleteHeadersFrame( streamId: Int, priority: Priority, endStream: Boolean, - headers: Headers): Result = + headers: Headers + ): Result = session.streamManager.get(streamId) match { case Some(stream) => stream.invokeInboundHeaders(priority, endStream, headers) @@ -56,7 +57,8 @@ private class SessionFrameListener( override def onCompletePushPromiseFrame( streamId: Int, promisedId: Int, - headers: Headers): Result = + headers: Headers + ): Result = if (!isClient) // A client cannot push. Thus, servers MUST treat the receipt of a // PUSH_PROMISE frame as a connection error of type PROTOCOL_ERROR. diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/SettingsDecoder.scala b/http/src/main/scala/org/http4s/blaze/http/http2/SettingsDecoder.scala index a4f5f2f74..c7c775ba0 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/SettingsDecoder.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/SettingsDecoder.scala @@ -69,7 +69,8 @@ private[blaze] object SettingsDecoder { def decodeSettingsFrame( buffer: ByteBuffer, streamId: Int, - flags: Byte): Either[Http2Exception, SettingsFrame] = { + flags: Byte + ): Either[Http2Exception, SettingsFrame] = { import Http2Exception._ val len = buffer.remaining diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/StreamIdManager.scala b/http/src/main/scala/org/http4s/blaze/http/http2/StreamIdManager.scala index 94434528c..1585389a2 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/StreamIdManager.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/StreamIdManager.scala @@ -35,7 +35,8 @@ private[http2] object StreamIdManager { private final class StreamIdManager private ( isClient: Boolean, private var nextInbound: Int, - private var nextOutbound: Int) { + private var nextOutbound: Int +) { /** Get the last inbound stream to be observed, or 0 if no streams have been processed */ def lastInboundStream: Int = math.max(0, nextInbound - 2) diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/StreamManagerImpl.scala b/http/src/main/scala/org/http4s/blaze/http/http2/StreamManagerImpl.scala index 24648d7dc..a92282794 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/StreamManagerImpl.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/StreamManagerImpl.scala @@ -106,7 +106,9 @@ private final class StreamManagerImpl( } else if (inboundStreamBuilder.isEmpty) Left( PROTOCOL_ERROR.goaway( - s"Client received request for new inbound stream ($streamId) without push promise")) + s"Client received request for new inbound stream ($streamId) without push promise" + ) + ) else if (drainingP.isDefined) Left(REFUSED_STREAM.rst(streamId, "Session draining")) else if (session.localSettings.maxConcurrentStreams <= size) @@ -169,11 +171,12 @@ private final class StreamManagerImpl( override def handlePushPromise(streamId: Int, promisedId: Int, headers: Headers): Result = if (session.idManager.isIdleOutboundId(streamId)) Error( - PROTOCOL_ERROR.goaway( - s"Received PUSH_PROMISE for associated to an idle stream ($streamId)")) + PROTOCOL_ERROR.goaway(s"Received PUSH_PROMISE for associated to an idle stream ($streamId)") + ) else if (!session.idManager.isInboundId(promisedId)) Error( - PROTOCOL_ERROR.goaway(s"Received PUSH_PROMISE frame with illegal stream id: $promisedId")) + PROTOCOL_ERROR.goaway(s"Received PUSH_PROMISE frame with illegal stream id: $promisedId") + ) else if (!session.idManager.observeInboundId(promisedId)) Error(PROTOCOL_ERROR.goaway("Received PUSH_PROMISE frame on non-idle stream")) else { diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/StreamStateImpl.scala b/http/src/main/scala/org/http4s/blaze/http/http2/StreamStateImpl.scala index 90fcf2f44..927881cd7 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/StreamStateImpl.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/StreamStateImpl.scala @@ -84,7 +84,8 @@ private abstract class StreamStateImpl(session: SessionCore) extends StreamState if (pendingRead != null) { doCloseWithError(Some(INTERNAL_ERROR.rst(streamId))) p.failure( - new IllegalStateException(s"Already have an outstanding read on a stream ($streamId)")) + new IllegalStateException(s"Already have an outstanding read on a stream ($streamId)") + ) () } else if (streamIsClosed) { // `.get` is safe since it must be Some if `streamIsClosed == true` @@ -107,7 +108,7 @@ private abstract class StreamStateImpl(session: SessionCore) extends StreamState () } - final override def writeRequest(msg: StreamFrame): Future[Unit] = { + override final def writeRequest(msg: StreamFrame): Future[Unit] = { val p = Promise[Unit]() // Move the work into the session executor session.serialExecutor.execute(new Runnable { @@ -144,12 +145,12 @@ private abstract class StreamStateImpl(session: SessionCore) extends StreamState /** Called when the outbound flow window of the session or this stream has had some data acked and * we may now be able to make forward progress. */ - final override def outboundFlowWindowChanged(): Unit = + override final def outboundFlowWindowChanged(): Unit = if (writePromise != null && flowWindow.outboundWindowAvailable) doRegisterWriteInterest() /** Must be called by the [[WriteController]] from within the session executor */ - final override def performStreamWrite(): collection.Seq[ByteBuffer] = { + override final def performStreamWrite(): collection.Seq[ByteBuffer] = { interestRegistered = false // Nothing waiting to go out, so return fast @@ -208,10 +209,11 @@ private abstract class StreamStateImpl(session: SessionCore) extends StreamState // /////////////////// Inbound messages /////////////////////////////// - final override def invokeInboundData( + override final def invokeInboundData( endStream: Boolean, data: ByteBuffer, - flowBytes: Int): MaybeError = + flowBytes: Int + ): MaybeError = if (receivedEndStream) // https://tools.ietf.org/html/rfc7540#section-5.1 section 'half-closed' Error(STREAM_CLOSED.rst(streamId, s"Stream($streamId) received DATA frame after EOS")) @@ -232,10 +234,11 @@ private abstract class StreamStateImpl(session: SessionCore) extends StreamState Error(FLOW_CONTROL_ERROR.goaway(s"stream($streamId) flow control error")) // Must be called with a complete headers block, either the prelude or trailers - final override def invokeInboundHeaders( + override final def invokeInboundHeaders( priority: Priority, endStream: Boolean, - headers: Headers): MaybeError = + headers: Headers + ): MaybeError = if (receivedEndStream) // https://tools.ietf.org/html/rfc7540#section-5.1 section 'half-closed' Error(STREAM_CLOSED.rst(streamId, s"Stream($streamId received HEADERS frame after EOS")) @@ -251,12 +254,12 @@ private abstract class StreamStateImpl(session: SessionCore) extends StreamState // //////////////////////////////////////////////////////////////////// - final override protected def doClosePipeline(cause: Option[Throwable]): Unit = + override protected final def doClosePipeline(cause: Option[Throwable]): Unit = session.serialExecutor.execute(new Runnable { def run(): Unit = doCloseWithError(cause) }) // Shuts down the stream and calls `StreamManager.streamFinished` with any potential errors. // WARNING: this must be called from within the session executor. - final override def doCloseWithError(cause: Option[Throwable]): Unit = + override final def doCloseWithError(cause: Option[Throwable]): Unit = if (!streamIsClosed) { closedReason = cause match { case None => StreamStateImpl.SomeEOF diff --git a/http/src/main/scala/org/http4s/blaze/http/http2/WriteControllerImpl.scala b/http/src/main/scala/org/http4s/blaze/http/http2/WriteControllerImpl.scala index 261bd94b2..4169a6f1d 100644 --- a/http/src/main/scala/org/http4s/blaze/http/http2/WriteControllerImpl.scala +++ b/http/src/main/scala/org/http4s/blaze/http/http2/WriteControllerImpl.scala @@ -109,7 +109,8 @@ private final class WriteControllerImpl( private[this] def addBuffs( dest: ArrayBuffer[ByteBuffer], - data: collection.Seq[ByteBuffer]): Int = { + data: collection.Seq[ByteBuffer] + ): Int = { var written = 0 data.foreach { buf => val rem = buf.remaining 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 bab97a666..22095b471 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 @@ -49,7 +49,8 @@ final class ALPNServerSelector( logger.debug("Available protocols: " + available) selector(available.toSet) } - }) + } + ) override def name: String = "PipelineSelector" 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 39a32a95f..21eba12d1 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 @@ -28,8 +28,8 @@ import scala.util.Failure final class ServerPriorKnowledgeHandshaker( localSettings: ImmutableHttp2Settings, flowStrategy: FlowStrategy, - nodeBuilder: Int => LeafBuilder[StreamFrame]) - extends PriorKnowledgeHandshaker[Unit](localSettings) { + nodeBuilder: Int => LeafBuilder[StreamFrame] +) extends PriorKnowledgeHandshaker[Unit](localSettings) { override protected def stageStartup(): Unit = synchronized { super.stageStartup() @@ -43,7 +43,8 @@ final class ServerPriorKnowledgeHandshaker( override protected def handshakeComplete( remoteSettings: MutableHttp2Settings, - data: ByteBuffer): Future[Unit] = + data: ByteBuffer + ): Future[Unit] = Future(installHttp2ServerStage(remoteSettings, data)) override protected def handlePreface(): Future[ByteBuffer] = @@ -63,7 +64,8 @@ final class ServerPriorKnowledgeHandshaker( // Setup the pipeline with a new Http2ClientStage and start it up, then return it. private def installHttp2ServerStage( remoteSettings: MutableHttp2Settings, - remainder: ByteBuffer): Unit = { + remainder: ByteBuffer + ): Unit = { logger.debug(s"Installing pipeline with settings: $remoteSettings") val tail = new BasicTail[ByteBuffer]("http2ServerTail") diff --git a/http/src/main/scala/org/http4s/blaze/http/util/HeaderTools.scala b/http/src/main/scala/org/http4s/blaze/http/util/HeaderTools.scala index 23144a99c..dd2f55bd1 100644 --- a/http/src/main/scala/org/http4s/blaze/http/util/HeaderTools.scala +++ b/http/src/main/scala/org/http4s/blaze/http/util/HeaderTools.scala @@ -50,7 +50,8 @@ private[blaze] object HeaderTools { case class SpecialHeaders( transferEncoding: Option[String], contentLength: Option[String], - connection: Option[String]) + connection: Option[String] + ) def isKeepAlive(connectionHeader: Option[String], minorVersion: Int): Boolean = connectionHeader match { diff --git a/http/src/main/scala/org/http4s/blaze/http/util/UrlTools.scala b/http/src/main/scala/org/http4s/blaze/http/util/UrlTools.scala index cc1dc3335..17988344e 100644 --- a/http/src/main/scala/org/http4s/blaze/http/util/UrlTools.scala +++ b/http/src/main/scala/org/http4s/blaze/http/util/UrlTools.scala @@ -45,8 +45,8 @@ private[blaze] object UrlTools { def getAddress: InetSocketAddress = { val port = if (uri.getPort > 0) uri.getPort - else (if (uri.getScheme.equalsIgnoreCase("http")) 80 - else 443) + else if (uri.getScheme.equalsIgnoreCase("http")) 80 + else 443 new InetSocketAddress(uri.getHost, port) } } 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 9a94b25d3..c8510154a 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 @@ -174,7 +174,8 @@ class ConnectionImplSuite extends BlazeTestSuite { } test( - "A ConnectionImpl.invokeShutdownWithError won't send a GOAWAY frame if a GOAWAY has been sent") { + "A ConnectionImpl.invokeShutdownWithError won't send a GOAWAY frame if a GOAWAY has been sent" + ) { val ctx = new Ctx import ctx._ 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 c5025679d..8aea65dc1 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 @@ -37,7 +37,8 @@ class FrameDecoderSuite extends BlazeTestSuite { streamId: Int, endStream: Boolean, data: ByteBuffer, - flowSize: Int): Result = { + flowSize: Int + ): Result = { this.streamId = Some(streamId) this.endStream = Some(endStream) this.data = data @@ -113,7 +114,8 @@ class FrameDecoderSuite extends BlazeTestSuite { 0x00, 0x00, 0x00, - 0x00) + 0x00 + ) val listener = new DataListener val dec = new FrameDecoder(Http2Settings.default, listener) assertEquals(dec.decodeBuffer(testData), Continue) @@ -141,7 +143,8 @@ class FrameDecoderSuite extends BlazeTestSuite { 0x00, 0x00, 0x00, - 0x00) + 0x00 + ) val listener = new DataListener val dec = new FrameDecoder(Http2Settings.default, listener) assertEquals(dec.decodeBuffer(testData), Continue) @@ -172,7 +175,8 @@ class FrameDecoderSuite extends BlazeTestSuite { 0x00, 0x00, 0x00, - 0x00) + 0x00 + ) val listener = new DataListener val dec = new FrameDecoder(Http2Settings.default, listener) assertEquals(dec.decodeBuffer(testData), Continue) @@ -203,7 +207,8 @@ class FrameDecoderSuite extends BlazeTestSuite { 0x00, 0x00, 0x00, - 0x00) + 0x00 + ) val listener = new DataListener val dec = new FrameDecoder(Http2Settings.default, listener) dec.decodeBuffer(testData) match { @@ -240,7 +245,8 @@ class FrameDecoderSuite extends BlazeTestSuite { priority: Priority, end_headers: Boolean, end_stream: Boolean, - buffer: ByteBuffer): Result = { + buffer: ByteBuffer + ): Result = { this.streamId = Some(streamId) this.priority = Some(priority) this.endHeaders = Some(end_headers) @@ -331,7 +337,8 @@ class FrameDecoderSuite extends BlazeTestSuite { 0x00, 0x00, 0x00, - 0x00) + 0x00 + ) val listener = new HeadersListener val dec = new FrameDecoder(Http2Settings.default, listener) @@ -394,7 +401,8 @@ class FrameDecoderSuite extends BlazeTestSuite { 0x00, 0x00, 0x00, - 0x01) + 0x01 + ) val listener = new HeadersListener val dec = new FrameDecoder(Http2Settings.default, listener) @@ -526,7 +534,8 @@ class FrameDecoderSuite extends BlazeTestSuite { 0x00, 0x00, 0x02, // stream dependency 2 - 0x00) + 0x00 + ) val listener = new PriorityListener val dec = new FrameDecoder(Http2Settings.default, listener) @@ -817,7 +826,8 @@ class FrameDecoderSuite extends BlazeTestSuite { streamId: Int, promisedId: Int, end_headers: Boolean, - data: ByteBuffer): Result = { + data: ByteBuffer + ): Result = { this.streamId = Some(streamId) this.promisedId = Some(promisedId) this.endHeaders = Some(end_headers) @@ -1325,7 +1335,8 @@ class FrameDecoderSuite extends BlazeTestSuite { override def onContinuationFrame( streamId: Int, endHeaders: Boolean, - data: ByteBuffer): Result = { + data: ByteBuffer + ): Result = { this.streamId = Some(streamId) this.endHeaders = Some(endHeaders) this.data = data @@ -1444,7 +1455,8 @@ class FrameDecoderSuite extends BlazeTestSuite { _code: Byte, _streamId: Int, _flags: Byte, - buffer: ByteBuffer): Result = { + buffer: ByteBuffer + ): Result = { data = buffer code = Some(_code) streamId = Some(_streamId) 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 f4b43c992..48eb66bb9 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 @@ -44,7 +44,8 @@ class FrameEncoderSuite extends BlazeTestSuite { priority: Priority, endHeaders: Boolean, endStream: Boolean, - data: ByteBuffer): Result = + data: ByteBuffer + ): Result = onHeadersFrameMock(streamId, priority, endHeaders, endStream, data) def onContinuationFrame(streamId: Int, endHeaders: Boolean, data: ByteBuffer): Result = @@ -60,7 +61,8 @@ class FrameEncoderSuite extends BlazeTestSuite { streamId: Int, promisedId: Int, end_headers: Boolean, - data: ByteBuffer): Result = ??? + data: ByteBuffer + ): Result = ??? def onPingFrame(ack: Boolean, data: Array[Byte]): Result = ??? @@ -96,7 +98,8 @@ class FrameEncoderSuite extends BlazeTestSuite { } test( - "An Http2FrameEncoder should fragments data frames if they exceed the localSettings.maxFrameSize") { + "An Http2FrameEncoder should fragments data frames if they exceed the localSettings.maxFrameSize" + ) { val tools = new MockTools(true) val zeroBuffer5 = zeroBuffer(5) val zeroBuffer10 = zeroBuffer(10) 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 b08e71ae7..c74dbb654 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 @@ -59,7 +59,8 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { streamId: Int, isLast: Boolean, data: ByteBuffer, - flowSize: Int): org.http4s.blaze.http.http2.Result = { + flowSize: Int + ): org.http4s.blaze.http.http2.Result = { assertEquals(streamId, dataFrame.streamId) assertEquals(isLast, dataFrame.endStream) assert(compare(data :: Nil, dataFrame.data.duplicate :: Nil)) @@ -77,7 +78,9 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { dataFrame.streamId, dataFrame.endStream, dataFrame.padding, - dataFrame.data.duplicate())) + dataFrame.data.duplicate() + ) + ) dec(dataFrame).decodeBuffer(frame) == Continue } } @@ -96,7 +99,8 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { endHeaders: Boolean, endStream: Boolean, data: ByteBuffer, - padding: Int) { + padding: Int + ) { def flowSize: Int = data.remaining + padding } @@ -105,8 +109,8 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { streamId <- Gen.posNum[Int] hasDep <- tfGen priority <- - (if (hasDep) genPriority.filter(_.dependentStreamId != streamId) - else Gen.const(Priority.NoPriority)) + if (hasDep) genPriority.filter(_.dependentStreamId != streamId) + else Gen.const(Priority.NoPriority) endHeaders <- tfGen endStream <- tfGen padding <- Gen.choose(0, 256) @@ -123,7 +127,8 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { priority: Priority, end_headers: Boolean, end_stream: Boolean, - buffer: ByteBuffer): org.http4s.blaze.http.http2.Result = { + buffer: ByteBuffer + ): org.http4s.blaze.http.http2.Result = { assertEquals(headerFrame.streamId, streamId) assertEquals(headerFrame.priority, priority) assertEquals(headerFrame.endHeaders, end_headers) @@ -144,7 +149,9 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { headerFrame.endHeaders, headerFrame.endStream, headerFrame.padding, - headerFrame.data.duplicate)) + headerFrame.data.duplicate + ) + ) assertEquals(dec(headerFrame).decodeBuffer(buff1), Continue) } @@ -156,7 +163,8 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { assertEquals( dec(HeadersFrame(1, Priority.NoPriority, true, true, dat, 0)) .decodeBuffer(buff1), - Continue) + Continue + ) assertEquals(buff1.remaining(), 0) val priority = Priority.Dependent(3, false, 6) @@ -168,23 +176,27 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { 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, true, true, paddingSize, dat) + ) assertEquals( dec(HeadersFrame(1, Priority.NoPriority, true, true, dat, paddingSize)) .decodeBuffer(buff), - Continue) + Continue + ) } test("HEADERS frame should fail on bad stream ID") { intercept[Throwable]( FrameSerializer - .mkHeaderFrame(0, Priority.NoPriority, true, true, 0, dat)) + .mkHeaderFrame(0, Priority.NoPriority, true, 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, true, true, -10, dat) + ) } case class PriorityFrame(streamId: Int, priority: Priority.Dependent) @@ -193,7 +205,8 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { decoder(new MockFrameListener(false) { override def onPriorityFrame( streamId: Int, - priority: Priority.Dependent): org.http4s.blaze.http.http2.Result = { + priority: Priority.Dependent + ): org.http4s.blaze.http.http2.Result = { assertEquals(priorityFrame.streamId, streamId) assertEquals(priorityFrame.priority, priority) Continue @@ -241,7 +254,8 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { decoder(new MockFrameListener(false) { override def onRstStreamFrame( streamId: Int, - code: Long): org.http4s.blaze.http.http2.Result = { + code: Long + ): org.http4s.blaze.http.http2.Result = { assertEquals(rstFrame.streamId, streamId) assertEquals(rstFrame.code, code) Continue @@ -263,7 +277,8 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { def dec(settingsFrame: SettingsFrame) = decoder(new MockFrameListener(false) { override def onSettingsFrame( - settings: Option[Seq[Setting]]): org.http4s.blaze.http.http2.Result = { + settings: Option[Seq[Setting]] + ): org.http4s.blaze.http.http2.Result = { assertEquals(settingsFrame.settings, settings) Continue } @@ -296,7 +311,8 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { decoder(new MockHeaderAggregatingFrameListener { override def onPingFrame( ack: Boolean, - data: Array[Byte]): org.http4s.blaze.http.http2.Result = { + data: Array[Byte] + ): org.http4s.blaze.http.http2.Result = { assertEquals(pingFrame.ack, ack) assert(util.Arrays.equals(pingFrame.data, data)) Continue @@ -326,7 +342,8 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { override def onGoAwayFrame( lastStream: Int, errorCode: Long, - debugData: Array[Byte]): org.http4s.blaze.http.http2.Result = { + debugData: Array[Byte] + ): org.http4s.blaze.http.http2.Result = { assertEquals(goAway.lastStream, lastStream) assertEquals(goAway.err, errorCode) assert(util.Arrays.equals(goAway.data, debugData)) @@ -354,7 +371,8 @@ class FrameSerializerSuite extends BlazeTestSuite with ScalaCheckSuite { decoder(new MockHeaderAggregatingFrameListener { override def onWindowUpdateFrame( streamId: Int, - sizeIncrement: Int): org.http4s.blaze.http.http2.Result = { + sizeIncrement: Int + ): org.http4s.blaze.http.http2.Result = { assertEquals(update.streamId, streamId) assertEquals(update.increment, sizeIncrement) Continue 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 d8523931e..955ba8e3f 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 @@ -38,7 +38,8 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { streamId: Int, priority: Priority, end_stream: Boolean, - headers: Headers): Result = { + headers: Headers + ): Result = { assertEquals(sId, streamId) assertEquals(p, priority) assertEquals(es, end_stream) @@ -55,7 +56,8 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { assertEquals( mkDecoder(1, Priority.NoPriority, true, hs).decodeBuffer(BufferTools.joinBuffers(bs)), - Halt) + Halt + ) } test("HEADERS frame with compressors should make a round trip with a continuation frame") { @@ -155,7 +157,8 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { streamId: Int, promisedId: Int, end_headers: Boolean, - data: ByteBuffer): Result = { + data: ByteBuffer + ): Result = { assertEquals(sId, streamId) assertEquals(pId, promisedId) assertEquals(end_h, end_headers) @@ -195,7 +198,8 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { override def onCompletePushPromiseFrame( streamId: Int, promisedId: Int, - headers: Headers): Result = { + headers: Headers + ): Result = { assertEquals(sId, streamId) assertEquals(pId, promisedId) assertEquals(hs, headers) @@ -214,7 +218,8 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { } test( - "PUSH_PROMISE frame with header decoder should make a round trip with a continuation frame") { + "PUSH_PROMISE frame with header decoder should make a round trip with a continuation frame" + ) { val hs = Seq("foo" -> "bar", "biz" -> "baz") val hsBuf = encodeHeaders(hs) val bs = FrameSerializer.mkPushPromiseFrame(1, 2, false, 0, hsBuf) @@ -232,7 +237,8 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { } test( - "PUSH_PROMISE frame with header decoder should make a round trip with a zero leanth HEADERS and a continuation frame") { + "PUSH_PROMISE frame with header decoder should make a round trip with a zero leanth HEADERS and a continuation frame" + ) { val hs = Seq("foo" -> "bar", "biz" -> "baz") val bs = FrameSerializer.mkPushPromiseFrame(1, 2, false, 0, BufferTools.emptyBuffer) @@ -250,7 +256,8 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { } test( - "PUSH_PROMISE frame with header decoder should make a round trip with a continuation frame") { + "PUSH_PROMISE frame with header decoder should make a round trip with a continuation frame" + ) { val hs1 = Seq("foo" -> "bar") val hs2 = Seq("biz" -> "baz") val bs = FrameSerializer.mkPushPromiseFrame(1, 2, false, 0, encodeHeaders(hs1)) @@ -268,7 +275,8 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { } test( - "PUSH_PROMISE frame with header decoder should fail on invalid frame sequence (wrong streamId)") { + "PUSH_PROMISE frame with header decoder should fail on invalid frame sequence (wrong streamId)" + ) { val hs1 = Seq("foo" -> "bar") val hs2 = Seq("biz" -> "baz") val bs = FrameSerializer.mkPushPromiseFrame(1, 2, false, 0, encodeHeaders(hs1)) @@ -285,7 +293,8 @@ class HeaderAggregatingFrameListenerSuite extends BlazeTestSuite { } test( - "PUSH_PROMISE frame with header decoder should fail on invalid frame sequence (wrong frame type)") { + "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)) 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 2cddecfd1..c228154c5 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 @@ -74,10 +74,12 @@ class HeaderDecoderSuite extends BlazeTestSuite { test("A HeaderDecoder should now overflow the maxHeaderBlockSize") { val bb = HeaderCodecHelpers.encodeHeaders( testHeaders ++ testHeaders, - Http2Settings.DefaultSettings.HEADER_TABLE_SIZE) + Http2Settings.DefaultSettings.HEADER_TABLE_SIZE + ) val dec = new HeaderDecoder( headersBlockSize, /*discardOnOverflow*/ true, - Http2Settings.DefaultSettings.HEADER_TABLE_SIZE) + Http2Settings.DefaultSettings.HEADER_TABLE_SIZE + ) assertEquals(dec.decode(bb, -1, true), Continue) assert(dec.headerListSizeOverflow) diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/HeaderEncoderSuite.scala b/http/src/test/scala/org/http4s/blaze/http/http2/HeaderEncoderSuite.scala index 60555b8c6..f1e64312d 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/HeaderEncoderSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/HeaderEncoderSuite.scala @@ -27,6 +27,7 @@ class HeaderEncoderSuite extends BlazeTestSuite { assertEquals( HeaderCodecHelpers.decodeHeaders(bb, Http2Settings.DefaultSettings.HEADER_TABLE_SIZE), - headers) + headers + ) } } diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/ServerPriorKnowledgeHandshakerSuite.scala b/http/src/test/scala/org/http4s/blaze/http/http2/ServerPriorKnowledgeHandshakerSuite.scala index f350e29ba..776a11b0d 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/ServerPriorKnowledgeHandshakerSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/ServerPriorKnowledgeHandshakerSuite.scala @@ -26,7 +26,8 @@ import scala.util.{Failure, Success} class ServerPriorKnowledgeHandshakerSuite extends BlazeTestSuite { private def makeHandshaker( - localSettings: ImmutableHttp2Settings): ServerPriorKnowledgeHandshaker = { + localSettings: ImmutableHttp2Settings + ): ServerPriorKnowledgeHandshaker = { val flowStrategy = new DefaultFlowStrategy(localSettings) new ServerPriorKnowledgeHandshaker( localSettings = localSettings, @@ -79,7 +80,8 @@ class ServerPriorKnowledgeHandshakerSuite extends BlazeTestSuite { test( "A ServerPriorKnowledgeHandshaker should sends a GOAWAY(PROTOCOL_ERROR) " + - "if settings frame that exceeds the local MAX_FRAME_SIZE") { + "if settings frame that exceeds the local MAX_FRAME_SIZE" + ) { val localSettings = Http2Settings.default.copy(maxFrameSize = 0) val head = new MockByteBufferHeadStage val handshaker = makeHandshaker(localSettings) @@ -120,7 +122,8 @@ class ServerPriorKnowledgeHandshakerSuite extends BlazeTestSuite { test( "A ServerPriorKnowledgeHandshaker should sends a GOAWAY(PROTOCOL_ERROR) " + - "if the first frame isn't a settings frame") { + "if the first frame isn't a settings frame" + ) { val localSettings = Http2Settings.default val head = new MockByteBufferHeadStage val handshaker = makeHandshaker(localSettings) 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 81118da78..ab88af612 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 @@ -51,7 +51,8 @@ class SessionFlowControlSuite extends BlazeTestSuite { } test( - "A SessionFlowControl session inbound window should start with the http2 default flow windows") { + "A SessionFlowControl session inbound window should start with the http2 default flow windows" + ) { val flow = flowControl() assertEquals(flow.sessionInboundWindow, DefaultSettings.INITIAL_WINDOW_SIZE) assertEquals(flow.sessionOutboundWindow, DefaultSettings.INITIAL_WINDOW_SIZE) @@ -84,7 +85,8 @@ class SessionFlowControlSuite extends BlazeTestSuite { test( "A SessionFlowControl session inbound withdrawals greater than " + - "the window result in false and don't deplete the window") { + "the window result in false and don't deplete the window" + ) { val flow = flowControl() assertEquals(flow.sessionInboundObserved(DefaultSettings.INITIAL_WINDOW_SIZE + 1), false) assertEquals(flow.sessionInboundWindow, DefaultSettings.INITIAL_WINDOW_SIZE) @@ -122,7 +124,8 @@ class SessionFlowControlSuite extends BlazeTestSuite { // https://tools.ietf.org/html/rfc7540#section-6.9 test( - "A SessionFlowControl session outbound deposits of 0 throw Http2Exception with flag FLOW_CONTROL") { + "A SessionFlowControl session outbound deposits of 0 throw Http2Exception with flag FLOW_CONTROL" + ) { val flow = flowControl() flow.sessionOutboundAcked(0) match { case Some(Http2SessionException(code, _)) => @@ -136,7 +139,8 @@ class SessionFlowControlSuite extends BlazeTestSuite { // https://tools.ietf.org/html/rfc7540#section-6.9.1 test( "A SessionFlowControl session outbound deposits that overflow " + - "the window throw Http2Exception with flag FLOW_CONTROL") { + "the window throw Http2Exception with flag FLOW_CONTROL" + ) { val flow = flowControl() val overflowBy1 = Int.MaxValue - flow.sessionOutboundWindow + 1 flow.sessionOutboundAcked(overflowBy1) match { @@ -150,7 +154,8 @@ class SessionFlowControlSuite extends BlazeTestSuite { // //////////////// Streams //////////////////////////// test( - "A SessionFlowControl.StreamFlowWindow inbound window should start with the config initial flow windows") { + "A SessionFlowControl.StreamFlowWindow inbound window should start with the config initial flow windows" + ) { val inbound = Http2Settings.default.copy(initialWindowSize = 2) val outbound = Http2Settings.default.copy(initialWindowSize = 1) val flow = flowControl(inbound, outbound).newStreamFlowWindow(1) @@ -190,7 +195,8 @@ class SessionFlowControlSuite extends BlazeTestSuite { } test( - "A SessionFlowControl.StreamFlowWindow inbound withdrawals less than the window are successful") { + "A SessionFlowControl.StreamFlowWindow inbound withdrawals less than the window are successful" + ) { val session = flowControl() val flow = session.newStreamFlowWindow(1) assert(flow.inboundObserved(1)) @@ -201,7 +207,8 @@ class SessionFlowControlSuite extends BlazeTestSuite { test( "A SessionFlowControl.StreamFlowWindow inbound withdrawals greater than " + - "the window result in false and don't deplete the window") { + "the window result in false and don't deplete the window" + ) { val session = flowControl() val flow = session.newStreamFlowWindow(1) assertEquals(flow.inboundObserved(DefaultSettings.INITIAL_WINDOW_SIZE + 1), false) @@ -211,7 +218,8 @@ class SessionFlowControlSuite extends BlazeTestSuite { } test( - "A SessionFlowControl.StreamFlowWindow inbound withdrawals equal than the window are successful") { + "A SessionFlowControl.StreamFlowWindow inbound withdrawals equal than the window are successful" + ) { val session = flowControl() val flow = session.newStreamFlowWindow(1) @@ -259,7 +267,8 @@ class SessionFlowControlSuite extends BlazeTestSuite { // https://tools.ietf.org/html/rfc7540#section-6.9 test( - "A SessionFlowControlStreamFlowWindow outbound deposits of 0 throw Http2Exception with flag FLOW_CONTROL") { + "A SessionFlowControlStreamFlowWindow outbound deposits of 0 throw Http2Exception with flag FLOW_CONTROL" + ) { val flow = flowControl().newStreamFlowWindow(1) flow.streamOutboundAcked(0) match { @@ -273,7 +282,8 @@ class SessionFlowControlSuite extends BlazeTestSuite { // https://tools.ietf.org/html/rfc7540#section-6.9.1 test( "A SessionFlowControlStreamFlowWindow outbound deposits that overflow " + - "the window throw Http2Exception with flag FLOW_CONTROL") { + "the window throw Http2Exception with flag FLOW_CONTROL" + ) { val flow = flowControl().newStreamFlowWindow(1) val overflowBy1 = Int.MaxValue - flow.streamOutboundWindow + 1 @@ -302,7 +312,8 @@ class SessionFlowControlSuite extends BlazeTestSuite { assertEquals( flow.outboundRequest(DefaultSettings.INITIAL_WINDOW_SIZE), - DefaultSettings.INITIAL_WINDOW_SIZE) + DefaultSettings.INITIAL_WINDOW_SIZE + ) assertEquals(flow.streamOutboundWindow, 0) assertEquals(session.sessionOutboundWindow, 0) } @@ -313,14 +324,16 @@ class SessionFlowControlSuite extends BlazeTestSuite { assertEquals( flow.outboundRequest(DefaultSettings.INITIAL_WINDOW_SIZE + 1), - DefaultSettings.INITIAL_WINDOW_SIZE) + DefaultSettings.INITIAL_WINDOW_SIZE + ) assertEquals(flow.streamOutboundWindow, 0) assertEquals(session.sessionOutboundWindow, 0) } test( "A SessionFlowControlStreamFlowWindow outbound withdrawals that exceed " + - "the window consume the max from stream or session") { + "the window consume the max from stream or session" + ) { val config = Http2Settings.default.copy(initialWindowSize = 1) val session = flowControl(config, config) val flow = session.newStreamFlowWindow(1) 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 75774feae..19769e336 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 @@ -34,7 +34,8 @@ class SessionFrameListenerSuite extends BlazeTestSuite { new HeaderDecoder( localSettings.maxHeaderListSize, true, // discard overflow headers - localSettings.headerTableSize) + localSettings.headerTableSize + ) lazy val newInboundStream: Option[Int => LeafBuilder[StreamFrame]] = None @@ -57,7 +58,8 @@ class SessionFrameListenerSuite extends BlazeTestSuite { streamId = os.streamId, priority = Priority.NoPriority, endStream = false, - headers = hs) + headers = hs + ) os.readRequest(1).value match { case Some(Success(HeadersFrame(Priority.NoPriority, false, hss))) => @@ -68,7 +70,8 @@ class SessionFrameListenerSuite extends BlazeTestSuite { } test( - "A SessionFrameListener should on HEADERS frame initiate a new stream for idle inbound stream (server)") { + "A SessionFrameListener should on HEADERS frame initiate a new stream for idle inbound stream (server)" + ) { val head = new BasicTail[StreamFrame]("") val tools = new MockTools(isClient = false) { override lazy val newInboundStream = Some((_: Int) => LeafBuilder(head)) @@ -80,7 +83,8 @@ class SessionFrameListenerSuite extends BlazeTestSuite { streamId = 1, priority = Priority.NoPriority, endStream = false, - headers = hs) + headers = hs + ) assert(tools.streamManager.get(1).isDefined) head.channelRead().value match { @@ -158,7 +162,8 @@ class SessionFrameListenerSuite extends BlazeTestSuite { } test( - "A SessionFrameListener on DATA frame update session flow bytes as consumed for closed streams") { + "A SessionFrameListener on DATA frame update session flow bytes as consumed for closed streams" + ) { val tools = new MockTools(isClient = true) val os = tools.streamManager.newOutboundStream() @@ -296,7 +301,8 @@ class SessionFrameListenerSuite extends BlazeTestSuite { assertEquals( tools.frameListener.onGoAwayFrame(1, NO_ERROR.code, "lol".getBytes(StandardCharsets.UTF_8)), - Continue) + Continue + ) observedGoAway match { case Some((1, Http2SessionException(NO_ERROR.code, "lol"))) => () diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/StreamFlowWindowSuite.scala b/http/src/test/scala/org/http4s/blaze/http/http2/StreamFlowWindowSuite.scala index 895fc0577..407a0f352 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/StreamFlowWindowSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/StreamFlowWindowSuite.scala @@ -52,7 +52,8 @@ class StreamFlowWindowSuite extends BlazeTestSuite { tools.sessionFlowControl .newStreamFlowWindow(1) .outboundRequest(initialSessionWindow), - initialSessionWindow) + initialSessionWindow + ) assertEquals(window.outboundWindow, 0) } @@ -88,7 +89,8 @@ class StreamFlowWindowSuite extends BlazeTestSuite { tools.sessionFlowControl .newStreamFlowWindow(1) .outboundRequest(initialSessionWindow), - initialSessionWindow) + initialSessionWindow + ) assertEquals(window2.outboundWindowAvailable, false) // both depleted assertEquals(window1.outboundWindowAvailable, false) // session depleted 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 359e7d72b..9e0f3d5fc 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 @@ -57,7 +57,8 @@ class StreamManagerImplSuite extends BlazeTestSuite { assert( tools.streamManager .drain(100, Http2Exception.NO_ERROR.goaway("whatever")) - .isCompleted) + .isCompleted + ) // Since the streams are closed stream operations should fail val hs = HeadersFrame(Priority.NoPriority, false, Seq.empty) @@ -98,7 +99,8 @@ class StreamManagerImplSuite extends BlazeTestSuite { } test( - "A StreamManagerImpl close streams should new streams are rejected after a GOAWAY is issued") { + "A StreamManagerImpl close streams should new streams are rejected after a GOAWAY is issued" + ) { val tools = new MockTools(isClient = false) // Need a stream so it doesn't all shut down @@ -149,7 +151,8 @@ class StreamManagerImplSuite extends BlazeTestSuite { } test( - "A StreamManagerImpl create streams should reject inbound streams with for non-idle streams") { + "A StreamManagerImpl create streams should reject inbound streams with for non-idle streams" + ) { val tools = new MockTools(isClient = false) assert(tools.streamManager.newInboundStream(1).isRight) @@ -164,7 +167,8 @@ class StreamManagerImplSuite extends BlazeTestSuite { } test( - "A StreamManagerImpl create streams should reject inbound streams when MAX_CONCURRENT_STREAMS hit") { + "A StreamManagerImpl create streams should reject inbound streams when MAX_CONCURRENT_STREAMS hit" + ) { val tools = new MockTools(isClient = false) tools.localSettings.maxConcurrentStreams = 1 @@ -211,18 +215,20 @@ class StreamManagerImplSuite extends BlazeTestSuite { } test( - "A StreamManagerImpl flow windows should update streams flow window on a successful initial flow window change") { + "A StreamManagerImpl flow windows should update streams flow window on a successful initial flow window change" + ) { // https://tools.ietf.org/html/rfc7540#section-6.9.2 val tools = new MockTools(isClient = false) val Right(s) = tools.streamManager.newInboundStream(1) val startFlowWindow = s.flowWindow.outboundWindow assertEquals(tools.streamManager.initialFlowWindowChange(1), Continue) - assertEquals(s.flowWindow.streamOutboundWindow, (startFlowWindow + 1)) + assertEquals(s.flowWindow.streamOutboundWindow, startFlowWindow + 1) } test( - "A StreamManagerImpl flow windows should close streams flow window on a failed initial flow window change") { + "A StreamManagerImpl flow windows should close streams flow window on a failed initial flow window change" + ) { // https://tools.ietf.org/html/rfc7540#section-6.9.2 val tools = new MockTools(isClient = false) @@ -240,7 +246,8 @@ class StreamManagerImplSuite extends BlazeTestSuite { } test( - "A StreamManagerImpl flow windows should results in GOAWAY(PROTOCOL_ERROR) for update on idle stream") { + "A StreamManagerImpl flow windows should results in GOAWAY(PROTOCOL_ERROR) for update on idle stream" + ) { new MockTools(isClient = true).streamManager .flowWindowUpdate(1, 1) match { case Error(ex: Http2SessionException) => @@ -251,13 +258,14 @@ class StreamManagerImplSuite extends BlazeTestSuite { } test( - "A StreamManagerImpl flow windows should handle successful flow window updates for streams") { + "A StreamManagerImpl flow windows should handle successful flow window updates for streams" + ) { val tools = new MockTools(isClient = false) val Right(s) = tools.streamManager.newInboundStream(1) val initFlowWindow = s.flowWindow.outboundWindow assertEquals(tools.streamManager.flowWindowUpdate(streamId = 1, sizeIncrement = 1), Continue) - assertEquals(s.flowWindow.streamOutboundWindow, (initFlowWindow + 1)) + assertEquals(s.flowWindow.streamOutboundWindow, initFlowWindow + 1) } test("A StreamManagerImpl flow windows should handle failed flow window updates for streams") { @@ -265,7 +273,8 @@ class StreamManagerImplSuite extends BlazeTestSuite { val Right(s) = tools.streamManager.newInboundStream(1) assert( - s.flowWindow.streamOutboundAcked(Int.MaxValue - s.flowWindow.streamOutboundWindow).isEmpty) + s.flowWindow.streamOutboundAcked(Int.MaxValue - s.flowWindow.streamOutboundWindow).isEmpty + ) tools.streamManager.flowWindowUpdate(streamId = 1, sizeIncrement = 1) match { case Error(ex: Http2StreamException) => @@ -276,7 +285,8 @@ class StreamManagerImplSuite extends BlazeTestSuite { } test( - "A StreamManagerImpl flow windows should handle successful flow window updates for the session") { + "A StreamManagerImpl flow windows should handle successful flow window updates for the session" + ) { var sessionAcked: Option[Int] = None val tools = new MockTools(true) { override lazy val sessionFlowControl: SessionFlowControl = new MockSessionFlowControl { @@ -292,7 +302,8 @@ class StreamManagerImplSuite extends BlazeTestSuite { } test( - "A StreamManagerImpl flow windows should handle failed flow window updates for the session") { + "A StreamManagerImpl flow windows should handle failed flow window updates for the session" + ) { var sessionAcked: Option[Int] = None val tools = new MockTools(true) { override lazy val sessionFlowControl: SessionFlowControl = new MockSessionFlowControl { @@ -313,7 +324,8 @@ class StreamManagerImplSuite extends BlazeTestSuite { } test( - "A StreamManagerImpl flow windows should PUSH_PROMISE frames are rejected by default by the client") { + "A StreamManagerImpl flow windows should PUSH_PROMISE frames are rejected by default by the client" + ) { val tools = new MockTools(isClient = true) tools.streamManager @@ -368,7 +380,8 @@ class StreamManagerImplSuite extends BlazeTestSuite { } test( - "A StreamManagerImpl flow windows should PUSH_PROMISE with promised stream which is not idle") { + "A StreamManagerImpl flow windows should PUSH_PROMISE with promised stream which is not idle" + ) { val promisedId = 2 val tools = new MockTools(isClient = true) val streamId = tools.idManager.takeOutboundId().getOrElse(sys.error("failed to acquire id")) 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 22933f7a7..47157c92e 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 @@ -40,7 +40,8 @@ class StreamStateImplSuite extends BlazeTestSuite { } override protected def onStreamBytesConsumed( stream: StreamFlowWindow, - consumed: Int): Unit = { + consumed: Int + ): Unit = { streamConsumed += consumed () } @@ -52,7 +53,8 @@ class StreamStateImplSuite extends BlazeTestSuite { lazy val streamState: StreamStateImpl = new InboundStreamStateImpl( session = tools, streamId = streamId, - flowWindow = tools.sessionFlowControl.newStreamFlowWindow(streamId)) + flowWindow = tools.sessionFlowControl.newStreamFlowWindow(streamId) + ) } test("A StreamState should register a write interest when it is written to") { @@ -126,7 +128,8 @@ class StreamStateImplSuite extends BlazeTestSuite { } test( - "A StreamState should close down when receiving Disconnect Command with RST if stream not finished") { + "A StreamState should close down when receiving Disconnect Command with RST if stream not finished" + ) { val ctx = new Ctx import ctx._ @@ -138,7 +141,8 @@ class StreamStateImplSuite extends BlazeTestSuite { } test( - "A StreamState should close down when receiving Disconnect Command without RST if stream is finished") { + "A StreamState should close down when receiving Disconnect Command without RST if stream is finished" + ) { val ctx = new Ctx import ctx._ @@ -180,7 +184,8 @@ class StreamStateImplSuite extends BlazeTestSuite { } test( - "A StreamState should signal that flow bytes have been consumed to the flow control on complete pending read") { + "A StreamState should signal that flow bytes have been consumed to the flow control on complete pending read" + ) { val ctx = new Ctx import ctx._ @@ -195,17 +200,17 @@ class StreamStateImplSuite extends BlazeTestSuite { // We should count the flow bytes size, not the actual buffer size assertEquals( - streamState.invokeInboundData( - endStream = false, - data = BufferTools.allocate(1), - flowBytes = 1), - Continue) + streamState + .invokeInboundData(endStream = false, data = BufferTools.allocate(1), flowBytes = 1), + Continue + ) assertEquals(streamConsumed.dequeue(), 1) } test( - "A StreamState should signal that flow bytes have been consumed to the flow control on complete non-pending read") { + "A StreamState should signal that flow bytes have been consumed to the flow control on complete non-pending read" + ) { val ctx = new Ctx import ctx._ @@ -227,14 +232,16 @@ class StreamStateImplSuite extends BlazeTestSuite { test( "A StreamState should fail result in an session exception if the inbound " + - "stream flow window is violated by an inbound message") { + "stream flow window is violated by an inbound message" + ) { val ctx = new Ctx import ctx._ tools.sessionFlowControl.sessionInboundAcked(10) assert( - streamState.flowWindow.streamInboundWindow < tools.sessionFlowControl.sessionInboundWindow) + streamState.flowWindow.streamInboundWindow < tools.sessionFlowControl.sessionInboundWindow + ) // Need to open the stream assertEquals(streamState.invokeInboundHeaders(Priority.NoPriority, false, Seq.empty), Continue) @@ -243,7 +250,8 @@ class StreamStateImplSuite extends BlazeTestSuite { streamState.invokeInboundData( endStream = false, data = BufferTools.emptyBuffer, - flowBytes = streamState.flowWindow.streamInboundWindow + 1) match { + flowBytes = streamState.flowWindow.streamInboundWindow + 1 + ) match { case Error(ex: Http2SessionException) => assertEquals(ex.code, Http2Exception.FLOW_CONTROL_ERROR.code) case _ => @@ -253,7 +261,8 @@ class StreamStateImplSuite extends BlazeTestSuite { test( "A StreamState should fail result in an session exception if the inbound session " + - "flow window is violated by an inbound message") { + "flow window is violated by an inbound message" + ) { val ctx = new Ctx import ctx._ @@ -263,7 +272,8 @@ class StreamStateImplSuite extends BlazeTestSuite { streamState.flowWindow.streamInboundAcked(10) assert( - streamState.flowWindow.streamInboundWindow > tools.sessionFlowControl.sessionInboundWindow) + streamState.flowWindow.streamInboundWindow > tools.sessionFlowControl.sessionInboundWindow + ) // Need to open the stream assertEquals(streamState.invokeInboundHeaders(Priority.NoPriority, false, Seq.empty), Continue) @@ -272,7 +282,8 @@ class StreamStateImplSuite extends BlazeTestSuite { streamState.invokeInboundData( endStream = false, data = BufferTools.emptyBuffer, - flowBytes = tools.sessionFlowControl.sessionInboundWindow + 1) match { + flowBytes = tools.sessionFlowControl.sessionInboundWindow + 1 + ) match { case Error(ex: Http2SessionException) => assertEquals(ex.code, Http2Exception.FLOW_CONTROL_ERROR.code) case _ => diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockFrameListener.scala b/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockFrameListener.scala index c1415fc2b..0dc247a46 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockFrameListener.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockFrameListener.scala @@ -29,7 +29,8 @@ private[http2] class MockFrameListener(inHeaders: Boolean) extends FrameListener streamId: Int, promisedId: Int, end_headers: Boolean, - data: ByteBuffer): Result = ??? + data: ByteBuffer + ): Result = ??? // For handling unknown stream frames override def onHeadersFrame( @@ -37,7 +38,8 @@ private[http2] class MockFrameListener(inHeaders: Boolean) extends FrameListener priority: Priority, end_headers: Boolean, end_stream: Boolean, - buffer: ByteBuffer): Result = ??? + buffer: ByteBuffer + ): Result = ??? override def onSettingsFrame(settings: Option[Seq[Setting]]): Result = ??? override def onRstStreamFrame(streamId: Int, code: Long): Result = ??? override def onPriorityFrame(streamId: Int, priority: Priority.Dependent): Result = ??? @@ -47,6 +49,7 @@ private[http2] class MockFrameListener(inHeaders: Boolean) extends FrameListener streamId: Int, isLast: Boolean, data: ByteBuffer, - flowSize: Int): Result = ??? + flowSize: Int + ): Result = ??? override def onWindowUpdateFrame(streamId: Int, sizeIncrement: Int): Result = ??? } 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 4bb25e72b..53823a1f3 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,16 +25,19 @@ import org.http4s.blaze.http.http2._ private[http2] class MockHeaderAggregatingFrameListener extends HeaderAggregatingFrameListener( Http2Settings.default, - new HeaderDecoder(20 * 1024, true, 4096)) { + new HeaderDecoder(20 * 1024, true, 4096) + ) { override def onCompletePushPromiseFrame( streamId: Int, promisedId: Int, - headers: Headers): Result = ??? + headers: Headers + ): Result = ??? override def onCompleteHeadersFrame( streamId: Int, priority: Priority, end_stream: Boolean, - headers: Headers): Result = ??? + headers: Headers + ): Result = ??? override def onGoAwayFrame(lastStream: Int, errorCode: Long, debugData: Array[Byte]): Result = ??? override def onPingFrame(ack: Boolean, data: Array[Byte]): Result = ??? override def onSettingsFrame(settings: Option[Seq[Setting]]): Result = ??? @@ -45,7 +48,8 @@ private[http2] class MockHeaderAggregatingFrameListener streamId: Int, isLast: Boolean, data: ByteBuffer, - flowSize: Int): Result = ??? + flowSize: Int + ): Result = ??? override def onPriorityFrame(streamId: Int, priority: Priority.Dependent): Result = ??? override def onWindowUpdateFrame(streamId: Int, sizeIncrement: Int): Result = ??? } diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockWriteController.scala b/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockWriteController.scala index e9160dcff..3166cef0a 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockWriteController.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/mocks/MockWriteController.scala @@ -48,6 +48,6 @@ private[http2] class MockWriteController extends WriteController { } /** Queue a buffer for writing */ - final override def write(data: ByteBuffer): Boolean = + override final def write(data: ByteBuffer): Boolean = write(data :: Nil) } diff --git a/http/src/test/scala/org/http4s/blaze/http/http2/mocks/ObservingSessionFlowControl.scala b/http/src/test/scala/org/http4s/blaze/http/http2/mocks/ObservingSessionFlowControl.scala index 6a57049ec..363ee4fa7 100644 --- a/http/src/test/scala/org/http4s/blaze/http/http2/mocks/ObservingSessionFlowControl.scala +++ b/http/src/test/scala/org/http4s/blaze/http/http2/mocks/ObservingSessionFlowControl.scala @@ -23,7 +23,8 @@ private[http2] class ObservingSessionFlowControl( session: SessionCore ) extends SessionFlowControlImpl( session = session, - flowStrategy = null /* only used on two overridden methods */ ) { + flowStrategy = null /* only used on two overridden methods */ + ) { override protected def onSessonBytesConsumed(consumed: Int): Unit = () override protected def onStreamBytesConsumed(stream: StreamFlowWindow, consumed: Int): Unit = () } diff --git a/http/src/test/scala/org/http4s/blaze/http/parser/BenchParser.scala b/http/src/test/scala/org/http4s/blaze/http/parser/BenchParser.scala index ac33badfa..569ad7e26 100644 --- a/http/src/test/scala/org/http4s/blaze/http/parser/BenchParser.scala +++ b/http/src/test/scala/org/http4s/blaze/http/parser/BenchParser.scala @@ -34,7 +34,8 @@ class BenchParser(maxReq: Int = 1034, maxHeader: Int = 1024) uri: String, scheme: String, majorversion: Int, - minorversion: Int): Boolean = false + minorversion: Int + ): Boolean = false def headerComplete(name: String, value: String) = false } diff --git a/http/src/test/scala/org/http4s/blaze/http/parser/Benchmarks.scala b/http/src/test/scala/org/http4s/blaze/http/parser/Benchmarks.scala index abe106f52..ea5065f6e 100644 --- a/http/src/test/scala/org/http4s/blaze/http/parser/Benchmarks.scala +++ b/http/src/test/scala/org/http4s/blaze/http/parser/Benchmarks.scala @@ -36,7 +36,8 @@ class Benchmarks extends BlazeTestSuite { val mockChunked = request + chunked + headers + toChunk(body) + toChunk( - ", " + body + " again!") + "0 \r\n" + "\r\n" + ", " + body + " again!" + ) + "0 \r\n" + "\r\n" def toChunk(str: String): String = { val len = Integer.toHexString(str.length) + "\r\n" diff --git a/http/src/test/scala/org/http4s/blaze/http/parser/ClientParserSuite.scala b/http/src/test/scala/org/http4s/blaze/http/parser/ClientParserSuite.scala index 46155dbd7..dcf200aa4 100644 --- a/http/src/test/scala/org/http4s/blaze/http/parser/ClientParserSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/parser/ClientParserSuite.scala @@ -61,7 +61,8 @@ class ClientParserSuite extends BlazeTestSuite { reason: String, scheme: String, majorversion: Int, - minorversion: Int): Unit = { + minorversion: Int + ): Unit = { this.code = code this.reason = reason this.scheme = scheme @@ -162,7 +163,8 @@ class ClientParserSuite extends BlazeTestSuite { } test( - "A client parser should throw invalid state if trying to parse the response line more than once") { + "A client parser should throw invalid state if trying to parse the response line more than once" + ) { val p = new TestParser assert(p.parseResponse(wrap(resp.getBytes(ISO_8859_1)))) @@ -251,7 +253,8 @@ class ClientParserSuite extends BlazeTestSuite { } test( - "A client parser should parse a body with a Content-Length and `Transfer-Encoding: identity` header") { + "A client parser should parse a body with a Content-Length and `Transfer-Encoding: identity` header" + ) { val p = new TestParser val full = resp + content_length + "Transfer-Encoding: identity\r\n" + l_headersstr + body val bts = wrap(full.getBytes(ISO_8859_1)) diff --git a/http/src/test/scala/org/http4s/blaze/http/parser/HttpTokensSuite.scala b/http/src/test/scala/org/http4s/blaze/http/parser/HttpTokensSuite.scala index 66f8cff48..35e91f028 100644 --- a/http/src/test/scala/org/http4s/blaze/http/parser/HttpTokensSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/parser/HttpTokensSuite.scala @@ -37,8 +37,8 @@ class HttpTokensSuite extends BlazeTestSuite { assert( (0 until 256) .forall { i => - HttpTokens.isHexChar(i.toByte) == (smalChrs.contains(i.toChar) || bigChrs.contains( - i.toChar)) + HttpTokens + .isHexChar(i.toByte) == (smalChrs.contains(i.toChar) || bigChrs.contains(i.toChar)) } ) } diff --git a/http/src/test/scala/org/http4s/blaze/http/parser/ResponseParser.scala b/http/src/test/scala/org/http4s/blaze/http/parser/ResponseParser.scala index 1200b6364..257029500 100644 --- a/http/src/test/scala/org/http4s/blaze/http/parser/ResponseParser.scala +++ b/http/src/test/scala/org/http4s/blaze/http/parser/ResponseParser.scala @@ -75,7 +75,8 @@ class ResponseParser extends Http1ClientParser { reason: String, scheme: String, majorversion: Int, - minorversion: Int): Unit = { + minorversion: Int + ): Unit = { this.code = code this.reason = reason this.majorversion = majorversion diff --git a/http/src/test/scala/org/http4s/blaze/http/parser/ServerParserSuite.scala b/http/src/test/scala/org/http4s/blaze/http/parser/ServerParserSuite.scala index 32b20cd76..dbc711918 100644 --- a/http/src/test/scala/org/http4s/blaze/http/parser/ServerParserSuite.scala +++ b/http/src/test/scala/org/http4s/blaze/http/parser/ServerParserSuite.scala @@ -26,7 +26,7 @@ import org.http4s.blaze.testkit.BlazeTestSuite import scala.collection.mutable.ListBuffer class ServerParserSuite extends BlazeTestSuite { - private implicit def strToBuffer(str: String): ByteBuffer = + implicit private def strToBuffer(str: String): ByteBuffer = ByteBuffer.wrap(str.getBytes(StandardCharsets.ISO_8859_1)) private class Parser(maxReq: Int = 1034, maxHeader: Int = 1024) @@ -56,7 +56,8 @@ class ServerParserSuite extends BlazeTestSuite { uri: String, scheme: String, majorversion: Int, - minorversion: Int) = { + minorversion: Int + ) = { // println(s"$methodString, $uri, $scheme/$majorversion.$minorversion") minorv = minorversion false @@ -99,7 +100,8 @@ class ServerParserSuite extends BlazeTestSuite { private val mockChunked = request + host + chunked + headers + toChunk(body) + toChunk( - body + " again!") + "0 \r\n" + "\r\n" + body + " again!" + ) + "0 \r\n" + "\r\n" test("An Http1ServerParser should fail on non-ascii char in request line") { val p = new Parser() @@ -160,14 +162,16 @@ class ServerParserSuite extends BlazeTestSuite { } test( - "An Http1ServerParser should give bad request on multiple different content-length headers") { + "An Http1ServerParser should give bad request on multiple different content-length headers" + ) { val p = new Parser() val line = "GET /enlighten/calais.asmx HTTPS/1.0\r\n" assert(p.parseLine(line)) intercept[BadMessage]( - p.parseheaders(buildHeaderString(Seq("content-length" -> "1", "content-length" -> "2")))) + p.parseheaders(buildHeaderString(Seq("content-length" -> "1", "content-length" -> "2"))) + ) } test("An Http1ServerParser should match Http1.0 requests") { diff --git a/project/plugins.sbt b/project/plugins.sbt index 23c2c6db7..02decfee4 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,5 +1,5 @@ addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % "0.7.0") addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1") -addSbtPlugin("org.http4s" %% "sbt-http4s-org" % "0.13.2") +addSbtPlugin("org.http4s" %% "sbt-http4s-org" % "0.14.2") addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") diff --git a/testkit/src/main/scala/org/http4s/blaze/testkit/BlazeTestSuite.scala b/testkit/src/main/scala/org/http4s/blaze/testkit/BlazeTestSuite.scala index 806cdbd87..c095031c0 100644 --- a/testkit/src/main/scala/org/http4s/blaze/testkit/BlazeTestSuite.scala +++ b/testkit/src/main/scala/org/http4s/blaze/testkit/BlazeTestSuite.scala @@ -31,19 +31,19 @@ trait BlazeAssertions { self: Assertions => def assertFuture[A, B]( obtained: => Future[A], returns: B, - clue: => Any = "values are not the same" + clue: => Any = "values are not the same", )(implicit ev: B <:< A, loc: Location, ec: ExecutionContext): Future[Unit] = obtained.flatMap(a => Future(assertEquals(a, returns, clue))) def assertFuture_( obtained: => Future[Unit], - clue: => Any = "values are not the same" + clue: => Any = "values are not the same", )(implicit loc: Location, ec: ExecutionContext): Future[Unit] = obtained.flatMap(a => Future(assertEquals(a, (), clue))) protected def assertFutureBoolean( obtained: => Future[Boolean], - clue: => Any = "values are not the same" + clue: => Any = "values are not the same", )(implicit loc: Location, ec: ExecutionContext): Future[Unit] = assertFuture(obtained, true, clue) @@ -54,15 +54,16 @@ trait BlazeAssertions { self: Assertions => private def runInterceptFuture[T <: Throwable]( exceptionMessage: Option[String], - body: => Future[Any] + body: => Future[Any], )(implicit T: ClassTag[T], loc: Location, ec: ExecutionContext): Future[T] = body.transformWith { case Success(value) => Future( fail( s"intercept failed, expected exception of type '${T.runtimeClass.getName}' but body evaluated successfully", - clues(value) - )) + clues(value), + ) + ) case Failure(e: FailExceptionLike[_]) if !T.runtimeClass.isAssignableFrom(e.getClass) => Future.failed(e) @@ -78,7 +79,7 @@ trait BlazeAssertions { self: Assertions => s"intercept failed, exception '$obtained' had message '${e.getMessage}', which was different from expected message '${exceptionMessage.get}'", cause = e, isStackTracesEnabled = false, - location = loc + location = loc, ) ) } @@ -92,7 +93,7 @@ trait BlazeAssertions { self: Assertions => s"intercept failed, exception '$obtained' is not a subtype of '$expected", cause = e, isStackTracesEnabled = false, - location = loc + location = loc, ) )