(s *ServerStream)
| 1038 | } |
| 1039 | |
| 1040 | func (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. |
no test coverage detected