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)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@@ -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",
|
||||
|
Reference in New Issue
Block a user