MCPcopy
hub / github.com/grpc/grpc-go / writeHeader

Method writeHeader

internal/transport/http2_server.go:1011–1038  ·  view source on GitHub ↗

WriteHeader sends the header metadata md back to the client.

(s *ServerStream, md metadata.MD)

Source from the content-addressed store, hash-verified

1009
1010// WriteHeader sends the header metadata md back to the client.
1011func (t *http2Server) writeHeader(s *ServerStream, md metadata.MD) error {
1012 s.hdrMu.Lock()
1013 defer s.hdrMu.Unlock()
1014 if s.getState() == streamDone {
1015 return t.streamContextErr(s)
1016 }
1017
1018 if s.updateHeaderSent() {
1019 return ErrIllegalHeaderWrite
1020 }
1021
1022 if md.Len() > 0 {
1023 if s.header.Len() > 0 {
1024 s.header = metadata.Join(s.header, md)
1025 } else {
1026 s.header = md
1027 }
1028 }
1029 if err := t.writeHeaderLocked(s); err != nil {
1030 switch e := err.(type) {
1031 case ConnectionError:
1032 return status.Error(codes.Unavailable, e.Desc)
1033 default:
1034 return status.Convert(err).Err()
1035 }
1036 }
1037 return nil
1038}
1039
1040func (t *http2Server) writeHeaderLocked(s *ServerStream) error {
1041 // TODO(mmukhi): Benchmark if the performance gets better if count the metadata and other header fields

Callers 1

writeMethod · 0.95

Calls 11

streamContextErrMethod · 0.95
writeHeaderLockedMethod · 0.95
JoinFunction · 0.92
ErrorFunction · 0.92
ConvertFunction · 0.92
updateHeaderSentMethod · 0.80
ErrMethod · 0.80
LenMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
getStateMethod · 0.45

Tested by

no test coverage detected