mirror of
https://github.com/aler9/gortsplib
synced 2025-10-06 23:52:46 +08:00
support control paths that start with '?'
This commit is contained in:
@@ -160,6 +160,12 @@ func (u *URL) SetUser(user *url.Userinfo) {
|
|||||||
|
|
||||||
// AddControlPath adds a control path to a RTSP url.
|
// AddControlPath adds a control path to a RTSP url.
|
||||||
func (u *URL) AddControlPath(controlPath string) {
|
func (u *URL) AddControlPath(controlPath string) {
|
||||||
|
// special case: query
|
||||||
|
if controlPath[0] == '?' {
|
||||||
|
u.inner.RawQuery += controlPath[1:]
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// always insert the control path at the end of the url
|
// always insert the control path at the end of the url
|
||||||
if u.inner.RawQuery != "" {
|
if u.inner.RawQuery != "" {
|
||||||
if !strings.HasSuffix(u.inner.RawQuery, "/") {
|
if !strings.HasSuffix(u.inner.RawQuery, "/") {
|
||||||
|
@@ -79,31 +79,47 @@ func TestURLBaseControlPath(t *testing.T) {
|
|||||||
|
|
||||||
func TestURLAddControlPath(t *testing.T) {
|
func TestURLAddControlPath(t *testing.T) {
|
||||||
for _, ca := range []struct {
|
for _, ca := range []struct {
|
||||||
u *URL
|
control string
|
||||||
ou *URL
|
u *URL
|
||||||
|
ou *URL
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
"trackID=1",
|
||||||
MustParseURL("rtsp://localhost:8554/teststream"),
|
MustParseURL("rtsp://localhost:8554/teststream"),
|
||||||
MustParseURL("rtsp://localhost:8554/teststream/trackID=1"),
|
MustParseURL("rtsp://localhost:8554/teststream/trackID=1"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"trackID=1",
|
||||||
MustParseURL("rtsp://localhost:8554/test/stream"),
|
MustParseURL("rtsp://localhost:8554/test/stream"),
|
||||||
MustParseURL("rtsp://localhost:8554/test/stream/trackID=1"),
|
MustParseURL("rtsp://localhost:8554/test/stream/trackID=1"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"trackID=1",
|
||||||
MustParseURL("rtsp://192.168.1.99:554/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp"),
|
MustParseURL("rtsp://192.168.1.99:554/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp"),
|
||||||
MustParseURL("rtsp://192.168.1.99:554/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp/trackID=1"),
|
MustParseURL("rtsp://192.168.1.99:554/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp/trackID=1"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"trackID=1",
|
||||||
MustParseURL("rtsp://192.168.1.99:554/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp"),
|
MustParseURL("rtsp://192.168.1.99:554/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp"),
|
||||||
MustParseURL("rtsp://192.168.1.99:554/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1"),
|
MustParseURL("rtsp://192.168.1.99:554/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"trackID=1",
|
||||||
MustParseURL("rtsp://192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp"),
|
MustParseURL("rtsp://192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp"),
|
||||||
MustParseURL("rtsp://192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1"),
|
MustParseURL("rtsp://192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"?ctype=video",
|
||||||
|
MustParseURL("rtsp://192.168.1.99:554/"),
|
||||||
|
MustParseURL("rtsp://192.168.1.99:554/?ctype=video"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"?ctype=video",
|
||||||
|
MustParseURL("rtsp://192.168.1.99:554/test"),
|
||||||
|
MustParseURL("rtsp://192.168.1.99:554/test?ctype=video"),
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
ca.u.AddControlPath("trackID=1")
|
ca.u.AddControlPath(ca.control)
|
||||||
require.Equal(t, ca.ou, ca.u)
|
require.Equal(t, ca.ou, ca.u)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user