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

Function newTextprotoReader

textproto_reader.go:41–70  ·  view source on GitHub ↗

NewReader returns a new textprotoReader reading from r. To avoid denial of service attacks, the provided bufio.Reader should be reading from an io.LimitReader or similar textprotoReader to bound the size of responses.

(r *bufio.Reader, ds dump.Dumpers)

Source from the content-addressed store, hash-verified

39// should be reading from an io.LimitReader or similar textprotoReader to bound
40// the size of responses.
41func newTextprotoReader(r *bufio.Reader, ds dump.Dumpers) *textprotoReader {
42 commonHeaderOnce.Do(initCommonHeader)
43 t := &textprotoReader{R: r}
44
45 if ds.ShouldDump() {
46 t.readLine = func() (line []byte, isPrefix bool, err error) {
47 line, err = t.R.ReadSlice('\n')
48 if len(line) == 0 {
49 if err != nil {
50 line = nil
51 }
52 return
53 }
54 err = nil
55 ds.DumpResponseHeader(line)
56 if line[len(line)-1] == '\n' {
57 drop := 1
58 if len(line) > 1 && line[len(line)-2] == '\r' {
59 drop = 2
60 }
61 line = line[:len(line)-drop]
62 }
63 return
64 }
65 } else {
66 t.readLine = t.R.ReadLine
67 }
68
69 return t
70}
71
72// ReadLine reads a single line from r,
73// eliding the final \n or \r\n from the returned string.

Callers 1

_readResponseMethod · 0.85

Calls 3

ShouldDumpMethod · 0.80
DoMethod · 0.45
DumpResponseHeaderMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…