mirror of
https://github.com/soheilhy/cmux.git
synced 2025-09-17 20:20:20 +08:00
Return not-match on different field values in HTTP2
Retun as soon as we have the matched field in the HTTP2 matcher regardless of weather the value is matched or not. Fixes #35. Issue #35 reports that cmux leaks memory when the client is HTTP2 but does not sends the expected header field. For example, when the non-gRPC client sends a large field in the header and we are matching for gRPC, we waste a lot of memory in the sniff buffer.
This commit is contained in:
23
matchers.go
23
matchers.go
@@ -144,10 +144,14 @@ func matchHTTP2Field(w io.Writer, r io.Reader, name, value string) (matched bool
|
||||
return false
|
||||
}
|
||||
|
||||
done := false
|
||||
framer := http2.NewFramer(w, r)
|
||||
hdec := hpack.NewDecoder(uint32(4<<10), func(hf hpack.HeaderField) {
|
||||
if hf.Name == name && hf.Value == value {
|
||||
matched = true
|
||||
if hf.Name == name {
|
||||
done = true
|
||||
if hf.Value == value {
|
||||
matched = true
|
||||
}
|
||||
}
|
||||
})
|
||||
for {
|
||||
@@ -161,17 +165,20 @@ func matchHTTP2Field(w io.Writer, r io.Reader, name, value string) (matched bool
|
||||
if err := framer.WriteSettings(); err != nil {
|
||||
return false
|
||||
}
|
||||
case *http2.ContinuationFrame:
|
||||
if _, err := hdec.Write(f.HeaderBlockFragment()); err != nil {
|
||||
return false
|
||||
}
|
||||
done = done || f.FrameHeader.Flags&http2.FlagHeadersEndHeaders != 0
|
||||
case *http2.HeadersFrame:
|
||||
if _, err := hdec.Write(f.HeaderBlockFragment()); err != nil {
|
||||
return false
|
||||
}
|
||||
if matched {
|
||||
return true
|
||||
}
|
||||
done = done || f.FrameHeader.Flags&http2.FlagHeadersEndHeaders != 0
|
||||
}
|
||||
|
||||
if f.FrameHeader.Flags&http2.FlagHeadersEndHeaders != 0 {
|
||||
return false
|
||||
}
|
||||
if done {
|
||||
return matched
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user