mirror of
https://github.com/soheilhy/cmux.git
synced 2025-01-19 03:06:07 +08:00
Merge pull request #45 from soheilhy/fix-44
Eliminate blocking reads in the HTTP2 matcher.
This commit is contained in:
commit
0068a46c9c
@ -1,7 +1,6 @@
|
|||||||
language: go
|
language: go
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- 1.5
|
|
||||||
- 1.6
|
- 1.6
|
||||||
- 1.7
|
- 1.7
|
||||||
- 1.8
|
- 1.8
|
||||||
|
20
matchers.go
20
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
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(b[:]) == http2.ClientPreface
|
for {
|
||||||
|
n, err := r.Read(b[last:])
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
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