mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 20:07:17 +00:00
7f56ac6355
* Massive code cleanup * fix test issues * remove GetGenesis mock expectations * unused receiver * rename unused params Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
31 lines
694 B
Go
31 lines
694 B
Go
package gateway
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
gwruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func HttpResponseModifier(ctx context.Context, w http.ResponseWriter, _ proto.Message) error {
|
|
md, ok := gwruntime.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
|
|
}
|
|
// 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")
|
|
w.WriteHeader(code)
|
|
}
|
|
|
|
return nil
|
|
}
|