MCPcopy Create free account
hub / github.com/imroc/req / WriteHeaders

Method WriteHeaders

internal/http2/frame.go:1155–1190  ·  view source on GitHub ↗

WriteHeaders writes a single HEADERS frame. This is a low-level header writing method. Encoding headers and splitting them into any necessary CONTINUATION frames is handled elsewhere. It will perform exactly one Write to the underlying Writer. It is the caller's responsibility to not call other Wr

(p HeadersFrameParam)

Source from the content-addressed store, hash-verified

1153// It will perform exactly one Write to the underlying Writer.
1154// It is the caller's responsibility to not call other Write methods concurrently.
1155func (h2f *Framer) WriteHeaders(p HeadersFrameParam) error {
1156 if !validStreamID(p.StreamID) && !h2f.AllowIllegalWrites {
1157 return errStreamID
1158 }
1159 var flags Flags
1160 if p.PadLength != 0 {
1161 flags |= FlagHeadersPadded
1162 }
1163 if p.EndStream {
1164 flags |= FlagHeadersEndStream
1165 }
1166 if p.EndHeaders {
1167 flags |= FlagHeadersEndHeaders
1168 }
1169 if !p.Priority.IsZero() {
1170 flags |= FlagHeadersPriority
1171 }
1172 h2f.startWrite(FrameHeaders, flags, p.StreamID)
1173 if p.PadLength != 0 {
1174 h2f.writeByte(p.PadLength)
1175 }
1176 if !p.Priority.IsZero() {
1177 v := p.Priority.StreamDep
1178 if !validStreamIDOrZero(v) && !h2f.AllowIllegalWrites {
1179 return errDepStreamID
1180 }
1181 if p.Priority.Exclusive {
1182 v |= 1 << 31
1183 }
1184 h2f.writeUint32(v)
1185 h2f.writeByte(p.Priority.Weight)
1186 }
1187 h2f.wbuf = append(h2f.wbuf, p.BlockFragment...)
1188 h2f.wbuf = append(h2f.wbuf, padZeros[:p.PadLength]...)
1189 return h2f.endWrite()
1190}
1191
1192// A PriorityFrame specifies the sender-advised priority of a stream.
1193// See https://httpwg.org/specs/rfc7540.html#rfc.section.6.3

Callers 1

writeHeadersMethod · 0.80

Calls 7

startWriteMethod · 0.95
writeByteMethod · 0.95
writeUint32Method · 0.95
endWriteMethod · 0.95
validStreamIDFunction · 0.85
validStreamIDOrZeroFunction · 0.85
IsZeroMethod · 0.80

Tested by

no test coverage detected