Skip to content

Commit

Permalink
write trailers directly into headers on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
NavidJalali committed Oct 23, 2024
1 parent f5bbf39 commit 88dc99d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ object GrpcEntityHelpers {
TrailerFrame(trailers = statusHeaders(status))

def trailer(status: Status, metadata: Metadata): TrailerFrame =
TrailerFrame(trailers = statusHeaders(status) ++ metadataHeaders(metadata))
TrailerFrame(trailers = trailers(status, metadata))

def trailers(status: Status, metadata: Metadata): List[HttpHeader] =
statusHeaders(status) ++ metadataHeaders(metadata)

def statusHeaders(status: Status): List[HttpHeader] =
List(headers.`Status`(status.getCode.value.toString)) ++ Option(status.getDescription).map(d =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ object GrpcResponseHelpers {
entity = HttpEntity.Chunked(writer.contentType, entity))
}

def status(trailer: Trailers)(implicit writer: GrpcProtocolWriter): HttpResponse =
response(Source.single(writer.encodeFrame(GrpcEntityHelpers.trailer(trailer.status, trailer.metadata))))
def status(trailer: Trailers)(implicit writer: GrpcProtocolWriter): HttpResponse = {
HttpResponse(
headers =
headers.`Message-Encoding`(writer.messageEncoding.name) ::
GrpcEntityHelpers.trailers(trailer.status, trailer.metadata),
entity = HttpEntity.empty(writer.contentType)
)
}
}

0 comments on commit 88dc99d

Please sign in to comment.