Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,28 @@ func TLS(versions ...int) Matcher {

const maxHTTPRead = 4096

var httpMethodByte = map[byte]struct{}{'G': {}, 'P': {}, 'H': {}, 'D': {}, 'C': {}, 'O': {}, 'T': {}}

// HTTP1 parses the first line or upto 4096 bytes of the request to see if
// the conection contains an HTTP request.
func HTTP1() Matcher {
return func(r io.Reader) bool {
br := bufio.NewReader(&io.LimitedReader{R: r, N: maxHTTPRead})
firstByte, err := br.ReadByte()
if err != nil {
return false
}
_, ok := httpMethodByte[firstByte]
if !ok {
return false
}

l, part, err := br.ReadLine()
if err != nil || part {
return false
}

_, _, proto, ok := parseRequestLine(string(l))
_, _, proto, ok := parseRequestLine(string(firstByte) + string(l))
if !ok {
return false
}
Expand Down