pass frame / stream type parsing errors to the hijacker callbacks

When a stream is reset, we might not have received the frame / stream
type yet. The callback might be able to identify if it was a stream
intended for that application by analyzing the stream reset error.
This commit is contained in:
Marten Seemann
2022-05-23 21:56:47 +02:00
parent 5cb2e8265c
commit 96c0daceca
7 changed files with 181 additions and 36 deletions

View File

@@ -2,6 +2,7 @@ package http3
import (
"bytes"
"errors"
"fmt"
"io"
@@ -11,6 +12,10 @@ import (
. "github.com/onsi/gomega"
)
type errReader struct{ err error }
func (e errReader) Read([]byte) (int, error) { return 0, e.err }
var _ = Describe("Frames", func() {
appendVarInt := func(b []byte, val uint64) []byte {
buf := &bytes.Buffer{}
@@ -189,7 +194,8 @@ var _ = Describe("Frames", func() {
buf.Write(customFrameContents)
var called bool
_, err := parseNextFrame(buf, func(ft FrameType) (hijacked bool, err error) {
_, err := parseNextFrame(buf, func(ft FrameType, e error) (hijacked bool, err error) {
Expect(e).ToNot(HaveOccurred())
Expect(ft).To(BeEquivalentTo(1337))
called = true
b := make([]byte, 3)
@@ -202,6 +208,19 @@ var _ = Describe("Frames", func() {
Expect(called).To(BeTrue())
})
It("passes on errors that occur when reading the frame type", func() {
testErr := errors.New("test error")
var called bool
_, err := parseNextFrame(errReader{err: testErr}, func(ft FrameType, e error) (hijacked bool, err error) {
Expect(e).To(MatchError(testErr))
Expect(ft).To(BeZero())
called = true
return true, nil
})
Expect(err).To(MatchError(errHijacked))
Expect(called).To(BeTrue())
})
It("reads a frame without hijacking the stream", func() {
buf := &bytes.Buffer{}
quicvarint.Write(buf, 1337)
@@ -212,7 +231,8 @@ var _ = Describe("Frames", func() {
buf.WriteString("foobar")
var called bool
frame, err := parseNextFrame(buf, func(ft FrameType) (hijacked bool, err error) {
frame, err := parseNextFrame(buf, func(ft FrameType, e error) (hijacked bool, err error) {
Expect(e).ToNot(HaveOccurred())
Expect(ft).To(BeEquivalentTo(1337))
called = true
return false, nil