From d821107d279325a09b67ffda4863a42a1a33e07b Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Thu, 20 May 2021 19:23:33 +0200 Subject: [PATCH] headers: check 'protocol not found' error properly in Transport header --- pkg/headers/transport.go | 16 ++++++++++------ pkg/headers/transport_test.go | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/headers/transport.go b/pkg/headers/transport.go index 19cac58b..776cef00 100644 --- a/pkg/headers/transport.go +++ b/pkg/headers/transport.go @@ -104,26 +104,26 @@ func (h *Transport) Read(v base.HeaderValue) error { return fmt.Errorf("value provided multiple times (%v)", v) } - if !strings.Contains(v[0], "RTP/AVP") && - !strings.Contains(v[0], "RTP/AVP/UDP") && - !strings.Contains(v[0], "RTP/AVP/TCP") { - return fmt.Errorf("invalid protocol (%v)", v[0]) - } + v0 := v[0] - kvs, err := keyValParse(v[0], ';') + kvs, err := keyValParse(v0, ';') if err != nil { return err } + protocolFound := false + for k, rv := range kvs { v := rv switch k { case "RTP/AVP", "RTP/AVP/UDP": h.Protocol = base.StreamProtocolUDP + protocolFound = true case "RTP/AVP/TCP": h.Protocol = base.StreamProtocolTCP + protocolFound = true case "unicast": v := base.StreamDeliveryUnicast @@ -210,6 +210,10 @@ func (h *Transport) Read(v base.HeaderValue) error { } } + if !protocolFound { + return fmt.Errorf("protocol not found (%v)", v[0]) + } + return nil } diff --git a/pkg/headers/transport_test.go b/pkg/headers/transport_test.go index ce5be58d..f213766d 100644 --- a/pkg/headers/transport_test.go +++ b/pkg/headers/transport_test.go @@ -171,9 +171,9 @@ func TestTransportReadError(t *testing.T) { "value provided multiple times ([a b])", }, { - "invalid protocol", + "protocol not found", base.HeaderValue{`invalid;unicast;client_port=14186-14187`}, - "invalid protocol (invalid;unicast;client_port=14186-14187)", + "protocol not found (invalid;unicast;client_port=14186-14187)", }, { "invalid interleaved port",