Closed
Description
🐛 Bug Report
When forward response options are provided to the runtime, they are not executed.
To Reproduce
mux := runtime.NewServeMux(
runtime.WithForwardResponseOption(httpResponseModifier),
)
Here, httpResponseModifier
has the following definition (this is a direct copy of the related documentation):
func httpResponseModifier(ctx context.Context, w http.ResponseWriter, p protoiface.MessageV1) error {
fmt.Println("in response modifier") // debug:withContext(debugger::parent)
md, ok := runtime.ServerMetadataFromContext(ctx)
if !ok {
return nil
}
// set http status code
if vals := md.HeaderMD.Get("x-http-code"); len(vals) > 0 {
code, err := strconv.Atoi(vals[0])
if err != nil {
return err
}
w.WriteHeader(code)
// delete the headers to not expose any grpc-metadata in http response
delete(md.HeaderMD, "x-http-code")
delete(w.Header(), "Grpc-Metadata-X-Http-Code")
}
return nil
}
The piece in the documentation uses proto.Message
but that throws an error:
Expected behavior
The forward response options should be executed.
Actual Behavior
The httpResponseModifier
function does not execute. I tried adding code to the actual package to help me with debugging and mux.forwardResponseOptions
does have a len() > 1
so I am not sure what's happening here.
Your Environment
macOS 10.15.5 (19F101)
go version go1.14.7 darwin/amd64
grpc-gateway 1.14.7
Metadata
Metadata
Assignees
Labels
No labels