Access-Control-Expose-Headers errors in browser when response from server
See original GitHub issueHi,
I’m playing with grpc-web and maybe I’m doing something wrong, but I’m geting this:
I’m sucessfully recieved request on server with all data… but response end with this errors in browser (Chrome) 😦
My test code:
I create good request from my js client:
import { RegistrationServicePromiseClient, RegistrationServiceClient, Data } from '~/api/registration_grpc_web_pb.js'
...
var data = new Data()
data.setEmail("test@example.com")
data.setPassword("abcd")
var client = new RegistrationServiceClient("https://localhost:8000")
client.newRegistration(data,null,(res) => {
console.log("res:",res)
})
and on my golang server (in main func):
func main() {
creds, err := credentials.NewServerTLSFromFile("localhost.pem", "localhost-key.pem")
if err != nil {
fmt.Print(err)
}
grpcServer := grpc.NewServer(grpc.Creds(creds))
wrappedGrpc := grpcweb.WrapServer(grpcServer, grpcweb.WithAllowedRequestHeaders([]string{"*"}), grpcweb.WithWebsockets(false))
srv := TestService{}
protos.RegisterRegistrationServiceServer(grpcServer, &srv)
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, x-user-agent, x-grpc-web, grpc-status, grpc-message")
w.Header().Set("Access-Control-Expose-Headers", "grpc-status, grpc-message")
if r.Method == "OPTIONS" {
return
}
if wrappedGrpc.IsGrpcWebRequest(r) {
wrappedGrpc.ServeHTTP(w, r)
} else {
// Fall back to other servers.
http.DefaultServeMux.ServeHTTP(w, r)
}
})
httpserver := http.Server{
Addr: ":8000",
Handler: handler,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
http2.ConfigureServer(&httpserver, nil)
err = httpserver.ListenAndServeTLS("localhost.pem", "localhost-key.pem")
if err != nil {
panic(err)
}
}
func (ser *TestService) NewRegistration(ctx context.Context, data *protos.Data) (*protos.Response, error) {
fmt.Printf("RECIEVED: %v\n", data)
res := protos.Response{}
res.Status = 123
res.Message = "Test"
return &res, nil
}
Verion grpc-web: 0.9.1
thanks for any help…
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Access-Control-Expose-Headers - HTTP - MDN Web Docs
The Access-Control-Expose-Headers response header allows a server to indicate which response headers should be made available to scripts ...
Read more >Preflight Access-Control-Expose-Headers ignored in CORS ...
The Access-Control-Expose-Headers header belongs, not in the response to a preflight request, but in the response to the associated actual ...
Read more >How to Debug Any CORS Error - HTTP Toolkit
Most CORS errors are quick & easy to debug and fix, once you understand the… ... Response to preflight request doesn't pass access...
Read more >What Is a CORS Error and How to Fix It (3 Ways) - Bannerbear
The server will return a response with some of these CORS headers to allow or block the ... header of the response, the...
Read more >A Simple Guide to CORS Errors in the Browser
There are both request and response HTTP headers that make up the CORS ... This tells the browser that any origin is allowed...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think a found the same problem in the past: https://github.com/grpc/grpc-web/issues/518
EDIT: So I think I will try use Envoy…
You shouldn’t have to call
http2.ConfigureServer
by the way, it will support http/2 automatically.