MCPcopy
hub / github.com/connectrpc/connect-go / WriteRequestHeader

Method WriteRequestHeader

protocol_connect.go:319–347  ·  view source on GitHub ↗
(streamType StreamType, header http.Header)

Source from the content-addressed store, hash-verified

317}
318
319func (c *connectClient) WriteRequestHeader(streamType StreamType, header http.Header) {
320 // We know these header keys are in canonical form, so we can bypass all the
321 // checks in Header.Set.
322 if getHeaderCanonical(header, headerUserAgent) == "" {
323 header[headerUserAgent] = []string{defaultConnectUserAgent}
324 }
325 header[connectHeaderProtocolVersion] = []string{connectProtocolVersion}
326 header[headerContentType] = []string{
327 connectContentTypeForCodecName(streamType, c.Codec.Name()),
328 }
329 acceptCompressionHeader := connectUnaryHeaderAcceptCompression
330 if streamType != StreamTypeUnary {
331 // If we don't set Accept-Encoding, by default http.Client will ask the
332 // server to compress the whole stream. Since we're already compressing
333 // each message, this is a waste.
334 header[connectUnaryHeaderAcceptCompression] = []string{compressionIdentity}
335 acceptCompressionHeader = connectStreamingHeaderAcceptCompression
336 // We only write the request encoding header here for streaming calls,
337 // since the streaming envelope lets us choose whether to compress each
338 // message individually. For unary, we won't know whether we're compressing
339 // the request until we see how large the payload is.
340 if c.CompressionName != "" && c.CompressionName != compressionIdentity {
341 header[connectStreamingHeaderCompression] = []string{c.CompressionName}
342 }
343 }
344 if acceptCompression := c.CompressionPools.CommaSeparatedNames(); acceptCompression != "" {
345 header[acceptCompressionHeader] = []string{acceptCompression}
346 }
347}
348
349func (c *connectClient) NewConn(
350 ctx context.Context,

Callers

nothing calls this directly

Calls 4

getHeaderCanonicalFunction · 0.85
NameMethod · 0.65
CommaSeparatedNamesMethod · 0.65

Tested by

no test coverage detected