mirror of
https://github.com/soheilhy/cmux.git
synced 2024-11-14 11:31:28 +08:00
Eliminate blocking reads in the HTTP2 matcher.
The HTTP2 matcher uses io.ReadFull to read the client preface. If the client sends a string shorter than the preface (e.g., SSL version) io.ReadFull will block. Replace io.ReadFull with Read and assume partial reads will not match Fixes #44
This commit is contained in:
parent
b6ec57c1a4
commit
c0f3570a02
16
matchers.go
16
matchers.go
@ -123,11 +123,23 @@ func HTTP2MatchHeaderFieldSendSettings(name, value string) MatchWriter {
|
|||||||
|
|
||||||
func hasHTTP2Preface(r io.Reader) bool {
|
func hasHTTP2Preface(r io.Reader) bool {
|
||||||
var b [len(http2.ClientPreface)]byte
|
var b [len(http2.ClientPreface)]byte
|
||||||
if _, err := io.ReadFull(r, b[:]); err != nil {
|
last := 0
|
||||||
|
|
||||||
|
for {
|
||||||
|
n, err := r.Read(b[last:])
|
||||||
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(b[:]) == http2.ClientPreface
|
last += n
|
||||||
|
eq := string(b[:last]) == http2.ClientPreface[:last]
|
||||||
|
if last == len(http2.ClientPreface) {
|
||||||
|
return eq
|
||||||
|
}
|
||||||
|
if !eq {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func matchHTTP1Field(r io.Reader, name, value string) (matched bool) {
|
func matchHTTP1Field(r io.Reader, name, value string) (matched bool) {
|
||||||
|
Loading…
Reference in New Issue
Block a user