allow inter-frame padding

fixes #416
This commit is contained in:
Marten Seemann 2017-02-18 12:38:55 +07:00
parent 9e4f395a49
commit 5bddd84fae
No known key found for this signature in database
GPG key ID: 3603F40B121FCDEA
2 changed files with 20 additions and 6 deletions

View file

@ -33,9 +33,11 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *PublicHeader, da
fs := make([]frames.Frame, 0, 2)
// Read all frames in the packet
ReadLoop:
for r.Len() > 0 {
typeByte, _ := r.ReadByte()
if typeByte == 0x0 { // PADDING frame
continue
}
r.UnreadByte()
var frame frames.Frame
@ -53,8 +55,6 @@ ReadLoop:
err = errors.New("unimplemented: CONGESTION_FEEDBACK")
} else {
switch typeByte {
case 0x0: // PAD, end of frames
break ReadLoop
case 0x01:
frame, err = frames.ParseRstStreamFrame(r)
if err != nil {

View file

@ -48,7 +48,7 @@ var _ = Describe("Packet unpacker", func() {
Expect(packet.frames).To(Equal([]frames.Frame{f}))
})
It("unpacks stream frames", func() {
It("unpacks STREAM frames", func() {
f := &frames.StreamFrame{
StreamID: 1,
Data: []byte("foobar"),
@ -84,13 +84,27 @@ var _ = Describe("Packet unpacker", func() {
Expect(err).To(MatchError("unimplemented: CONGESTION_FEEDBACK"))
})
It("handles pad frames", func() {
setData([]byte{0, 0, 0})
It("handles PADDING frames", func() {
setData([]byte{0, 0, 0}) // 3 bytes PADDING
packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(BeEmpty())
})
It("handles PADDING between two other frames", func() {
f := &frames.PingFrame{}
err := f.Write(buf, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred())
_, err = buf.Write(bytes.Repeat([]byte{0}, 10)) // 10 bytes PADDING
Expect(err).ToNot(HaveOccurred())
err = f.Write(buf, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred())
setData(buf.Bytes())
packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(HaveLen(2))
})
It("unpacks RST_STREAM frames", func() {
setData([]byte{0x01, 0xEF, 0xBE, 0xAD, 0xDE, 0x44, 0x33, 0x22, 0x11, 0xAD, 0xFB, 0xCA, 0xDE, 0x34, 0x12, 0x37, 0x13})
packet, err := unpacker.Unpack(hdrBin, hdr, data)