@@ -14,9 +14,10 @@ import akka.annotation.InternalApi
14
14
import akka .event .LoggingAdapter
15
15
import akka .grpc .GrpcProtocol .GrpcProtocolReader
16
16
import akka .grpc .{ GrpcClientSettings , GrpcResponseMetadata , GrpcSingleResponse , ProtobufSerializer }
17
+ import akka .grpc .scaladsl .StringEntry
17
18
import akka .http .scaladsl .model .HttpEntity .{ Chunk , Chunked , LastChunk , Strict }
18
19
import akka .http .scaladsl .{ ClientTransport , ConnectionContext , Http }
19
- import akka .http .scaladsl .model .{ AttributeKey , HttpHeader , HttpRequest , HttpResponse , RequestResponseAssociation , Uri }
20
+ import akka .http .scaladsl .model ._
20
21
import akka .http .scaladsl .settings .ClientConnectionSettings
21
22
import akka .stream .{ Materializer , OverflowStrategy }
22
23
import akka .stream .scaladsl .{ Keep , Sink , Source }
@@ -220,7 +221,11 @@ object AkkaHttpClientUtils {
220
221
.watchTermination()((_, done) =>
221
222
done.onComplete(_ => trailerPromise.trySuccess(immutable.Seq .empty)))
222
223
case Strict (_, data) =>
223
- trailerPromise.success(immutable.Seq .empty)
224
+ val rawTrailers = response.attribute(AttributeKeys .trailer).map(_.headers).getOrElse(Seq .empty)
225
+ val trailers = rawTrailers.map(h => HttpHeader .parse(h._1, h._2)).collect {
226
+ case HttpHeader .ParsingResult .Ok (header, _) => header
227
+ }
228
+ trailerPromise.success(trailers)
224
229
Source .single[ByteString ](data)
225
230
case _ =>
226
231
response.entity.discardBytes()
@@ -281,19 +286,21 @@ object AkkaHttpClientUtils {
281
286
response : HttpResponse ,
282
287
trailers : Seq [HttpHeader ]): StatusRuntimeException = {
283
288
val allHeaders = response.headers ++ trailers
289
+ val metadata : io.grpc.Metadata =
290
+ new MetadataImpl (allHeaders.map(h => (h.name, StringEntry (h.value))).toList).toGoogleGrpcMetadata()
284
291
allHeaders.find(_.name == " grpc-status" ).map(_.value) match {
285
292
case None =>
286
- new StatusRuntimeException (
287
- mapHttpStatus(response )
288
- .withDescription( " No grpc-status found " )
289
- .augmentDescription( s " When calling rpc service: ${requestUri.toString()} " ) )
293
+ val status = mapHttpStatus(response)
294
+ .withDescription( " No grpc-status found " )
295
+ .augmentDescription( s " When calling rpc service: ${requestUri.toString()} " )
296
+ new StatusRuntimeException (status, metadata )
290
297
case Some (statusCode) =>
291
298
val description = allHeaders.find(_.name == " grpc-message" ).map(_.value)
292
- new StatusRuntimeException (
293
- Status
294
- .fromCodeValue(statusCode.toInt )
295
- .withDescription(description.orNull )
296
- .augmentDescription( s " When calling rpc service: ${requestUri.toString()} " ) )
299
+ val status = Status
300
+ .fromCodeValue(statusCode.toInt)
301
+ .withDescription(description.orNull )
302
+ .augmentDescription( s " When calling rpc service: ${requestUri.toString()} " )
303
+ new StatusRuntimeException (status, metadata )
297
304
}
298
305
}
299
306
0 commit comments