10var crlf2x = []byte("\r\n\r\n")
12var ErrHeaderSeparator = errors.New("no header separator found")
14// ReadHeaders returns the headers of a message, ending with a single crlf.
15// Returns ErrHeaderSeparator if no header separator is found.
16func ReadHeaders(msg *bufio.Reader) ([]byte, error) {
19 line, err := msg.ReadBytes('\n')
20 if err != io.EOF && err != nil {
23 buf = append(buf, line...)
24 if bytes.HasSuffix(buf, crlf2x) {
25 return buf[:len(buf)-2], nil
28 return nil, ErrHeaderSeparator