MCPcopy
hub / github.com/nats-io/nats.go / DecodeHeadersMsg

Function DecodeHeadersMsg

nats.go:4300–4327  ·  view source on GitHub ↗

DecodeHeadersMsg will decode and headers.

(data []byte)

Source from the content-addressed store, hash-verified

4298
4299// DecodeHeadersMsg will decode and headers.
4300func DecodeHeadersMsg(data []byte) (Header, error) {
4301 br := bufio.NewReaderSize(bytes.NewReader(data), 128)
4302 tp := textproto.NewReader(br)
4303 l, err := tp.ReadLine()
4304 if err != nil || len(l) < hdrPreEnd || l[:hdrPreEnd] != hdrLine[:hdrPreEnd] {
4305 return nil, ErrBadHeaderMsg
4306 }
4307
4308 mh, err := readMIMEHeader(tp)
4309 if err != nil {
4310 return nil, err
4311 }
4312
4313 // Check if we have an inlined status.
4314 if len(l) > hdrPreEnd {
4315 var description string
4316 status := strings.TrimSpace(l[hdrPreEnd:])
4317 if len(status) != statusLen {
4318 description = strings.TrimSpace(status[statusLen:])
4319 status = status[:statusLen]
4320 }
4321 mh.Add(statusHdr, status)
4322 if len(description) > 0 {
4323 mh.Add(descrHdr, description)
4324 }
4325 }
4326 return Header(mh), nil
4327}
4328
4329// readMIMEHeader returns a MIMEHeader that preserves the
4330// original case of the MIME header, based on the implementation

Callers 4

TestHeaderParserFunction · 0.85
BenchmarkHeaderDecodeFunction · 0.85
getMsgMethod · 0.85
processMsgMethod · 0.85

Calls 3

readMIMEHeaderFunction · 0.85
HeaderTypeAlias · 0.85
AddMethod · 0.65

Tested by 2

TestHeaderParserFunction · 0.68
BenchmarkHeaderDecodeFunction · 0.68