-
Notifications
You must be signed in to change notification settings - Fork 425
In 2.x - is it possible to add metadata to a ServerReponse? Is it possible in a ServerInterceptor? #2119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That'll solve your immediate problem, but I think we should add an API to make this more convenient. |
@glbrntt Thank you! Could you maybe help someone who does not yet have many months of Swift experience out with a few more details? Here is what I've tried. It compiles, but the client gets "the http/2 server reset the stream", so I'm obviously doing something wrong. let oldResult = response.accepted
let old_res = try oldResult.get()
var new_metadata = old_res.metadata
new_metadata.addString("gRPC;dur=\(duration)", forKey: "Server-Timing")
return StreamingServerResponse<Output>(metadata: new_metadata, producer: old_res.producer) |
Absolutely :) Interesting, I suspect that happens because What you should do here is switch over var response = try await next(...)
switch response.accepted {
case .success(var contents):
contents.metadata.addString(...)
response.accepted = .success(contents)
case .failure(var error):
error.metadata.addString(...)
response.accepted = .failure(error)
}
return response |
I just opened #2120 to provide a convenience setter for this as well. |
Thank so much. Looks much better than my code :-) But I still get the error.
the call completes normally. I tried adding a do/catch block around the switch, but vscode says the catch-block is unreachable because no errors are thrown in the do block.
works, but
gives "the http/2 server reset the stream. |
Ah, so HTTP/2 header field names must be lowercase. I thought we did that conversion for you, but clearly we don't, so I'll fix that up too. |
What are you trying to achieve?
I would like to add metadata to the response sent back to the client. Preferably in a ServerInterceptor.
What have you tried so far?
Here is my attempt, but metadata is a get-only property
The addString (2nd-last line) gives: Cannot use mutating member on immutable value: 'metadata' is a get-only property
The text was updated successfully, but these errors were encountered: