mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
headers: check 'protocol not found' error properly in Transport header
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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",
|
||||||
|
Reference in New Issue
Block a user