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

Method writeHeaderLocked

internal/transport/http2_server.go:1040–1073  ·  view source on GitHub ↗
(s *ServerStream)

Source from the content-addressed store, hash-verified

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
1042 // first and create a slice of that exact size.
1043 headerFields := make([]hpack.HeaderField, 0, 2) // at least :status, content-type will be there if none else.
1044 headerFields = append(headerFields, hpack.HeaderField{Name: ":status", Value: "200"})
1045 headerFields = append(headerFields, hpack.HeaderField{Name: "content-type", Value: grpcutil.ContentType(s.contentSubtype)})
1046 if s.sendCompress != "" {
1047 headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-encoding", Value: s.sendCompress})
1048 }
1049 headerFields = appendHeaderFieldsFromMD(headerFields, s.header)
1050 hf := &headerFrame{
1051 streamID: s.id,
1052 hf: headerFields,
1053 endStream: false,
1054 onWrite: t.setResetPingStrikes,
1055 }
1056 success, err := t.controlBuf.executeAndPut(func() bool { return t.checkForHeaderListSize(hf.hf) }, hf)
1057 if !success {
1058 if err != nil {
1059 return err
1060 }
1061 t.closeStream(s, true, http2.ErrCodeInternal, false)
1062 return ErrHeaderListSizeLimitViolation
1063 }
1064 if t.stats != nil {
1065 // Note: Headers are compressed with hpack after this call returns.
1066 // No WireLength field is set here.
1067 t.stats.HandleRPC(s.Context(), &stats.OutHeader{
1068 Header: s.header.Copy(),
1069 Compression: s.sendCompress,
1070 })
1071 }
1072 return nil
1073}
1074
1075// writeStatus sends stream status to the client and terminates the stream.
1076// There is no further I/O operations being able to perform on this stream.

Callers 2

writeHeaderMethod · 0.95
writeStatusMethod · 0.95

Calls 8

closeStreamMethod · 0.95
ContentTypeFunction · 0.92
appendHeaderFieldsFromMDFunction · 0.85
executeAndPutMethod · 0.80
CopyMethod · 0.80
HandleRPCMethod · 0.65
ContextMethod · 0.65

Tested by

no test coverage detected