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)
| 39 | // should be reading from an io.LimitReader or similar textprotoReader to bound |
| 40 | // the size of responses. |
| 41 | func 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. |
no test coverage detected
searching dependent graphs…