Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cromwell.webservice

import akka.http.scaladsl.model.{HttpResponse, StatusCodes}
import akka.http.scaladsl.model.{HttpEntity, HttpResponse, StatusCodes}
import akka.http.scaladsl.server
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
Expand All @@ -23,14 +23,23 @@ trait SwaggerUiHttpService {
| operationsSorter: "alpha"
""".stripMargin

mapResponseEntity { entityFromJar =>
entityFromJar.transformDataBytes(Flow.fromFunction[ByteString, ByteString] { original: ByteString =>
ByteString(
original.utf8String
.replace("""url: "https://petstore.swagger.io/v2/swagger.json"""", "url: 'cromwell.yaml'")
.replace("""layout: "StandaloneLayout"""", s"""layout: "StandaloneLayout", $swaggerOptions""")
)
})
// Fix Issue #7763: Must intercept 304 BEFORE mapResponseEntity tries to transform it
mapResponse { response =>
if (response.status == StatusCodes.NotModified) {
// For 304, return immediately with empty entity, don't try to transform
response.withEntity(HttpEntity.Empty)
} else {
// For 200, transform the entity content
response.mapEntity { entityFromJar =>
entityFromJar.transformDataBytes(Flow.fromFunction[ByteString, ByteString] { original: ByteString =>
ByteString(
original.utf8String
.replace("""url: "https://petstore.swagger.io/v2/swagger.json"""", "url: 'cromwell.yaml'")
.replace("""layout: "StandaloneLayout"""", s"""layout: "StandaloneLayout", $swaggerOptions""")
)
})
}
}
} {
getFromResource(s"$resourceDirectory/index.html")
}
Expand Down