Co-authored-by: Kevin Wan <wanjunfeng@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
guonaihong
2025-08-14 22:32:09 +08:00
committed by GitHub
parent 31b749ab67
commit d68cf4920c
2 changed files with 165 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package internal
import (
"io"
"net/http"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
@@ -33,15 +34,32 @@ func (h *EventHandler) OnReceiveResponse(message proto.Message) {
}
}
func (h *EventHandler) OnReceiveTrailers(status *status.Status, _ metadata.MD) {
func (h *EventHandler) OnReceiveTrailers(status *status.Status, md metadata.MD) {
w, ok := h.writer.(http.ResponseWriter)
if ok {
for k, v := range md {
for _, v2 := range v {
w.Header().Add(http.CanonicalHeaderKey(k), v2)
}
}
}
h.Status = status
}
func (h *EventHandler) OnResolveMethod(_ *desc.MethodDescriptor) {
}
func (h *EventHandler) OnSendHeaders(_ metadata.MD) {
}
func (h *EventHandler) OnReceiveHeaders(_ metadata.MD) {
func (h *EventHandler) OnReceiveHeaders(md metadata.MD) {
w, ok := h.writer.(http.ResponseWriter)
if ok {
for k, v := range md {
for _, v2 := range v {
canonicalKey := http.CanonicalHeaderKey(k)
for _, v2 := range v {
w.Header().Add(canonicalKey, v2)
}
}
}
}