Skip to content

Commit

Permalink
Test for only continuation space when reading header lines.
Browse files Browse the repository at this point in the history
Feedly uses headers start with $, so should not test for ascii letters.
  • Loading branch information
cyfdecyf committed Aug 6, 2013
1 parent ec0bace commit 358e03c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 10 additions & 3 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,13 @@ func splitHeader(s []byte) (name, val []byte, err error) {
// ending '\n' in the returned line. Buf if there's only CRLF in the line,
// return nil for the line.
func readContinuedLineSlice(r *bufio.Reader) ([]byte, error) {
// feedly.com request headers contains things like:
// "$Authorization.feedly: $FeedlyAuth\r\n", so we must test for only
// continuation spaces.
isspace := func(b byte) bool {
return b == ' ' || b == '\t'
}

// Read the first line.
line, err := r.ReadSlice('\n')
if err != nil {
Expand All @@ -445,8 +452,8 @@ func readContinuedLineSlice(r *bufio.Reader) ([]byte, error) {
return nil, nil
}

if !IsASCIILetter(line[0]) {
return nil, fmt.Errorf("malformed header, start not ascii letter: %#v", string(line))
if isspace(line[0]) {
return nil, fmt.Errorf("malformed header, start with space: %#v", string(line))
}

// Optimistically assume that we have started to buffer the next line
Expand All @@ -455,7 +462,7 @@ func readContinuedLineSlice(r *bufio.Reader) ([]byte, error) {
// non-existent whitespace.
if r.Buffered() > 0 {
peek, err := r.Peek(1)
if err == nil && IsASCIILetter(peek[0]) {
if err == nil && !isspace(peek[0]) {
return line, nil
}
}
Expand Down
6 changes: 0 additions & 6 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ func IsSpace(b byte) bool {
return spaceTbl[b]
}

// Copied from net/textproto.go
func IsASCIILetter(b byte) bool {
b |= 0x20 // make lower case
return 'a' <= b && b <= 'z'
}

func TrimSpace(s []byte) []byte {
st := 0
end := len(s) - 1
Expand Down

0 comments on commit 358e03c

Please sign in to comment.