Closed dbblackdiamond closed 1 month ago
This OPTIONS
request is a so called CORS pre-flight request. It happens because browser has to ask the server if authorization
is an allowed header via Access-Control-Request-Headers
.
You can avoid that by setting WebCallOptions.bypassCorsPreflight
to true
which tells grpc-web to pack metadata into $httpHeaders
query parameter instead of sending it as headers. You will of course need to properly handle this in Envoy though.
Hi,
I am building a multi-platform application using Flutter. The app will be available on Android, IOS and web. I have migrated the backend over to gRPC and the Android and IOS versions work fine with that, but not the web. To get the web version working, I implemented Envoy sidecar on all of my services and it is working for the most part. I am using the
GrpcOrGrpcWebClientChannel.toSingleEndpoint
method to create a channel to my services. One of the services requires me to send a custom headerauthorization
with a JWT token. When I create my stub using theServiceClient
method, in theCallOptions
, I definemetadata: {'authorization': token}
. When I do this though, the underlying RPC call is done using theOPTIONS
method, but when I remove that line, it is done using thePOST
method as show below. With themetadata
line: this is what I see at my ingress gateway:and at the envoy sidecar:
but without the
metadata
line: this is what I see at my ingress gateway:and at the envoy sidecar:
The only difference between the 2 is the presence of the
metadata
definition inCallOptions
. By the way, on Android, whether the line is there or not, the call is made usingPOST
method.I am running
grpc
package version4.0.1
.My question is: Why does the
grpc-web
implementation useOPTIONS
vsPOST
when custom headers inmetadata
are defined?This is causing an issue where all the calls with
metadata
are failing, but all the calls without it are working fine.Thanks a lot in advance, Bertrand.