Skip to content

Commit

Permalink
fix: using request content type as fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
MoeQuadrat committed Apr 29, 2024
1 parent 934fbb1 commit 48f1e2b
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ class SmithyPlayEndpoint[Alg[_[_, _, _, _, _]], F[_] <: ContextRoute[_], Op[_, _

private def mapToEndpointResult(
statusCode: Int
)(output: O): HttpResponse[Blob] = {
)(output: O)(implicit defaultContentType: ContentType): HttpResponse[Blob] = {
val outputMetadata = outputMetadataEncoder.encode(output).headers.get(CaseInsensitive("content-type")) match {
case Some(value) => value
case None => Seq(serviceContentType)
case None => Seq(defaultContentType.value)
}
codecDecider
.httpMessageEncoder(outputMetadata)
Expand Down Expand Up @@ -144,13 +144,13 @@ class SmithyPlayEndpoint[Alg[_[_, _, _, _, _]], F[_] <: ContextRoute[_], Op[_, _
.withHeaders(error.status.headers.toList: _*)
.as(error.contentType)

private def handleSuccess(output: HttpResponse[Blob]): Result = {
private def handleSuccess(output: HttpResponse[Blob])(implicit defaultContentType: ContentType): Result = {
val status = Results.Status(output.statusCode)
val contentTypeKey = CaseInsensitive("content-type")
val outputHeadersWithoutContentType =
output.headers.-(contentTypeKey).toList.map(h => (h._1.toString, h._2.head))
val contentType =
output.headers.getOrElse(contentTypeKey, Seq(serviceContentType))
output.headers.getOrElse(contentTypeKey, Seq(defaultContentType.value))

if (!output.body.isEmpty) {
status(output.body.toArray)
Expand Down

0 comments on commit 48f1e2b

Please sign in to comment.