From a43e0a4d8b5cea6124acb0a3dac14e259a154a50 Mon Sep 17 00:00:00 2001 From: Sergey Nastich Date: Thu, 14 Jun 2018 01:36:52 -0400 Subject: Add `Connection: close` header to all responses in order to mitigate connection pool issues with envoy (#175) --- .../scala/xyz/driver/core/rest/DriverRouteTest.scala | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/scala/xyz/driver/core/rest/DriverRouteTest.scala b/src/test/scala/xyz/driver/core/rest/DriverRouteTest.scala index aca8fdc..d32fefd 100644 --- a/src/test/scala/xyz/driver/core/rest/DriverRouteTest.scala +++ b/src/test/scala/xyz/driver/core/rest/DriverRouteTest.scala @@ -2,8 +2,9 @@ package xyz.driver.core.rest import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport import akka.http.scaladsl.model.StatusCodes +import akka.http.scaladsl.model.headers.Connection import akka.http.scaladsl.server.Directives.{complete => akkaComplete} -import akka.http.scaladsl.server.{Directives, Route} +import akka.http.scaladsl.server.{Directives, Rejection, RejectionHandler, Route} import akka.http.scaladsl.testkit.ScalatestRouteTest import com.typesafe.scalalogging.Logger import org.scalatest.{AsyncFlatSpec, Matchers} @@ -12,6 +13,7 @@ import xyz.driver.core.json.serviceExceptionFormat import xyz.driver.core.FutureExtensions import xyz.driver.core.rest.errors._ +import scala.collection.immutable import scala.concurrent.Future class DriverRouteTest @@ -103,4 +105,19 @@ class DriverRouteTest responseAs[ServiceException] shouldBe DatabaseException() } } + + it should "add a `Connection: close` header to avoid clashing with envoy's timeouts" in { + val rejectionHandler = RejectionHandler.newBuilder().handleNotFound(complete(StatusCodes.NotFound)).result() + val route = new TestRoute(handleRejections(rejectionHandler)((get & path("foo"))(complete("OK")))) + + Get("/foo") ~> route.routeWithDefaults ~> check { + status shouldBe StatusCodes.OK + headers should contain(Connection("close")) + } + + Get("/bar") ~> route.routeWithDefaults ~> check { + status shouldBe StatusCodes.NotFound + headers should contain(Connection("close")) + } + } } -- cgit v1.2.3