From c0f3570a0275aab5ff5bd20ff3d41155dae48d74 Mon Sep 17 00:00:00 2001 From: Soheil Hassas Yeganeh Date: Sat, 22 Apr 2017 23:58:46 -0400 Subject: [PATCH 1/2] 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 --- matchers.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/matchers.go b/matchers.go index 485ede8..cfc24c7 100644 --- a/matchers.go +++ b/matchers.go @@ -123,11 +123,23 @@ func HTTP2MatchHeaderFieldSendSettings(name, value string) MatchWriter { func hasHTTP2Preface(r io.Reader) bool { var b [len(http2.ClientPreface)]byte - if _, err := io.ReadFull(r, b[:]); err != nil { - return false - } + last := 0 - 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) { From 6a5d33255987ede57525db9ef132d7489f03582d Mon Sep 17 00:00:00 2001 From: Soheil Hassas Yeganeh Date: Mon, 24 Apr 2017 21:45:35 -0400 Subject: [PATCH 2/2] Remove Go 1.5 from travis builds. gRPC doesn't support Go 1.5 anymore, and the build would fail if we keep testing with Go 1.5. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d43e278..4bc48e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: go go: - - 1.5 - 1.6 - 1.7 - 1.8