Closed spreeni closed 6 months ago
Is this native gRPC (i.e. in the mobile app) or a gRPC-Web (i.e. in the browser)?
In the browser you will not be able to access Set-Cookie
because it is a forbidden response header and will be hidden from the client code.
(The browser manages cookie itself - so normally you should not need to access Set-Cookie
, e.g. if the cookie is added by the response it will be used by subsequent requests automatically).
Ah sorry - this is native gRPC, I am trying to add a mobile app to a previous Web implementation, hence the issue.
So is it better to avoid accessing the set-cookie
header all together and push for a mobile-adjustment of the backend API? This is possible, but obviously I'd rather work with the existing API, if feasible.
Thanks for the quick reply!
On the native side I would have expected all headers to be passed back to the client without any filtering. Does response.headers
not contain cookie header?
Maybe I am missing something, but the deserialized response seems to not have a headers
attribute. It implements the abstract class protobuf.GeneratedMessage
and just contains a _fieldSet
.
I am talking about Response.headers
property.
You need to try something like:
final call = client.someMethod(...);
final headers = await call.headers;
final response = await call;
to get access to them.
Oh thanks for the solution! I was just executing
final response = await client.someMethod(...);
directly and skipping the header retrieval completely. 🙈 Thanks for the quick and very helpful answers, closing this issue again then.
I can't find a way to parse HTTP headers of a grpc client response.
I am trying to connect to an API which answers with a
set-cookie
header that I need to parse.grpc-dart version: 3.2.4
Repro steps
ClientInterceptor
(e.g. https://stackoverflow.com/questions/72949714/how-to-intercept-grpc-response/72949742#72949742)Expected result: I can somehow access header information of the response
Actual result: The response just contains the deserialized data and none of the header information
I am a Dart/gRPC newbie, so I might not be familiar with a possible solution here, but am open to any suggestions.