fs2-grpc icon indicating copy to clipboard operation
fs2-grpc copied to clipboard

Metadata with response

Open a-khakimov opened this issue 3 years ago • 6 comments

I correctly understand that there is no possibility to send metadata with response?

a-khakimov avatar Apr 20 '22 17:04 a-khakimov

Yep, I think grpc-java behaves similarily?

ahjohannessen avatar Apr 20 '22 17:04 ahjohannessen

Not really. Metadata can only be sent with errors. On a successful response, empty metadata is constructed and sent inside methods.

@Override
public void onError(Throwable t) {
      Metadata metadata = Status.trailersFromThrowable(t);
      if (metadata == null) {
          metadata = new Metadata();
      }
      call.close(Status.fromThrowable(t), metadata);
      aborted = true;
}

@Override
public void onCompleted() {
      call.close(Status.OK, new Metadata());
      completed = true;
}

And this limitation can be bypassed by returning an error with OK status code. For example:

foo.onError(
  StatusProto.toStatusRuntimeException(
    Status
      .newBuilder()
      .setCode(Code.OK.getNumber)
      .addDetails(...)
      .build()
    )
  )

a-khakimov avatar Apr 20 '22 17:04 a-khakimov

How do you feel about trying to make compatible changes to the library? I'm talking about the possibility of implementing a server whose method could return a response with metadata. This would be very useful for being able to place technical information in metadata.

a-khakimov avatar Apr 20 '22 18:04 a-khakimov

A PR would be nice to see, as long as it is non-breaking and opt-in

ahjohannessen avatar Apr 20 '22 18:04 ahjohannessen

@a-khakimov By any chance did you have a working branch or idea of how to add this? 🙏 My team is keen on getting this functionality as well.

choonkending avatar Aug 16 '22 01:08 choonkending

add in https://github.com/typelevel/fs2-grpc/pull/713

TalkingFoxMid avatar Mar 07 '24 12:03 TalkingFoxMid

Fixed in https://github.com/typelevel/fs2-grpc/pull/713

ahjohannessen avatar May 29 '24 09:05 ahjohannessen