headers: check 'protocol not found' error properly in Transport header

This commit is contained in:
aler9
2021-05-20 19:23:33 +02:00
parent 7a5d3ce47b
commit d821107d27
2 changed files with 12 additions and 8 deletions

View File

@@ -104,26 +104,26 @@ func (h *Transport) Read(v base.HeaderValue) error {
return fmt.Errorf("value provided multiple times (%v)", v) return fmt.Errorf("value provided multiple times (%v)", v)
} }
if !strings.Contains(v[0], "RTP/AVP") && v0 := v[0]
!strings.Contains(v[0], "RTP/AVP/UDP") &&
!strings.Contains(v[0], "RTP/AVP/TCP") {
return fmt.Errorf("invalid protocol (%v)", v[0])
}
kvs, err := keyValParse(v[0], ';') kvs, err := keyValParse(v0, ';')
if err != nil { if err != nil {
return err return err
} }
protocolFound := false
for k, rv := range kvs { for k, rv := range kvs {
v := rv v := rv
switch k { switch k {
case "RTP/AVP", "RTP/AVP/UDP": case "RTP/AVP", "RTP/AVP/UDP":
h.Protocol = base.StreamProtocolUDP h.Protocol = base.StreamProtocolUDP
protocolFound = true
case "RTP/AVP/TCP": case "RTP/AVP/TCP":
h.Protocol = base.StreamProtocolTCP h.Protocol = base.StreamProtocolTCP
protocolFound = true
case "unicast": case "unicast":
v := base.StreamDeliveryUnicast 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 return nil
} }

View File

@@ -171,9 +171,9 @@ func TestTransportReadError(t *testing.T) {
"value provided multiple times ([a b])", "value provided multiple times ([a b])",
}, },
{ {
"invalid protocol", "protocol not found",
base.HeaderValue{`invalid;unicast;client_port=14186-14187`}, 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", "invalid interleaved port",