Skip to content

Commit

Permalink
rewrite 502 as 503
Browse files Browse the repository at this point in the history
  • Loading branch information
Grekkq committed Nov 23, 2023
1 parent b70acde commit 32396bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/scala/com/ing/wbaa/rokku/proxy/api/ProxyService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import com.ing.wbaa.rokku.proxy.provider.aws.AwsErrorCodes

import java.util.UUID
import java.util.concurrent.TimeUnit
import scala.concurrent.Await
import scala.concurrent.{ ExecutionContext, Future }
import scala.concurrent.duration.Duration
import scala.util.{ Failure, Success }

trait ProxyService {
Expand Down Expand Up @@ -132,9 +134,16 @@ trait ProxyService {
updateHeadersForRequest(httpRequest) { newHttpRequest =>
val httpResponse = executeRequest(newHttpRequest, userSTS, s3Request).andThen {
case Success(response: HttpResponse) =>
logger.debug("Got response from S3 with headers: {}", response.headers)
handlePostRequestActions(response, httpRequest, s3Request, userSTS)
}
complete(httpResponse)
val evaluatedResponse = Await.result(httpResponse, Duration("60 seconds"))
if (evaluatedResponse.status == StatusCodes.BadGateway) {
logger.debug("Got 502, rewriting as 503 to indicate S3 overload")
throw new RokkuThrottlingException("Got 502, rewriting as 503")
}
logger.debug("Got response from S3 other then 502, returning it to user")
complete(evaluatedResponse)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ object ProxyDirectives extends LazyLogging {
RawHeader("Access-Control-Allow-Headers", "*")) ++ oldHeaders
}
} else {
logger.debug("Wont add CORS, request: {}", request)
pass
}
}
Expand Down

0 comments on commit 32396bc

Please sign in to comment.