From 6a409faa99c5bd5b45db8796cb0455f975e2ac4d Mon Sep 17 00:00:00 2001 From: Krzysztof Zmij Date: Tue, 19 Dec 2023 09:10:53 +0100 Subject: [PATCH] test discard response --- .../proxy/handler/RequestHandlerS3.scala | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/scala/com/ing/wbaa/rokku/proxy/handler/RequestHandlerS3.scala b/src/main/scala/com/ing/wbaa/rokku/proxy/handler/RequestHandlerS3.scala index 6de8fd9d..969618ac 100644 --- a/src/main/scala/com/ing/wbaa/rokku/proxy/handler/RequestHandlerS3.scala +++ b/src/main/scala/com/ing/wbaa/rokku/proxy/handler/RequestHandlerS3.scala @@ -8,14 +8,14 @@ import akka.http.scaladsl.model.headers.RawHeader import com.amazonaws.Request import com.amazonaws.auth.BasicAWSCredentials import com.ing.wbaa.rokku.proxy.config.StorageS3Settings -import com.ing.wbaa.rokku.proxy.data.{RequestId, S3Request, User} +import com.ing.wbaa.rokku.proxy.data.{ RequestId, S3Request, User } import com.ing.wbaa.rokku.proxy.handler.exception.RokkuThrottlingException import com.ing.wbaa.rokku.proxy.provider.aws.S3Client import com.ing.wbaa.rokku.proxy.provider.aws.SignatureHelpersCommon.awsVersion import com.ing.wbaa.rokku.proxy.queue.UserRequestQueue -import scala.concurrent.{ExecutionContext, Future} -import scala.util.{Failure, Success} +import scala.concurrent.{ ExecutionContext, Future } +import scala.util.{ Failure, Success } trait RequestHandlerS3 extends S3Client with UserRequestQueue { @@ -81,17 +81,20 @@ trait RequestHandlerS3 extends S3Client with UserRequestQueue { protected[this] def fireRequestToS3(request: HttpRequest)(implicit id: RequestId): Future[HttpResponse] = { logger.info(s"Request sent to backend storage: method: {} uri: {}, {}", request.method.value, request.uri.toString(), request) println(request.uri.path) - if(request.method == HttpMethods.PUT && request.uri.path.startsWith(Path("/acckz")) ) { + if (request.method == HttpMethods.PUT && request.uri.path.startsWith(Path("/acckz"))) { + request.entity.discardBytes() Future(HttpResponse.apply(StatusCodes.BadGateway, entity = HttpEntity(ContentTypes.`text/html(UTF-8)`, "\n502 Bad Gateway\n\n

502 Bad Gateway

\n
nginx/1.23.4
\n\n\n\n\n\n\n\n"))) - }else { + } else { Http() .singleRequest(request) .andThen { - case Success(r) => logger.info(s"Received response from backend storage: {}", r.status) - case Failure(exception) => logger.error("Backend error e={}", exception) + case Success(r) => logger.info(s"Received response from backend storage: {}", r.status) + case Failure(exception) => + request.entity.discardBytes() + logger.error("Backend error e={}", exception) } .map(r => r.withEntity(r.entity.withoutSizeLimit())) - } + } }