fix error when using vlc, authentication and urls with query parameters

This commit is contained in:
aler9
2020-11-01 19:36:34 +01:00
parent b2de7dd899
commit 3225099239
3 changed files with 50 additions and 30 deletions

View File

@@ -47,6 +47,19 @@ func TestAuthMethods(t *testing.T) {
}
func TestAuthVLC(t *testing.T) {
for _, ca := range []struct {
clientURL string
serverURL string
}{
{
"rtsp://myhost/mypath/",
"rtsp://myhost/mypath/trackId=0",
},
{
"rtsp://myhost/mypath/test?testing/",
"rtsp://myhost/mypath/test?testing/trackId=0",
},
} {
authServer := NewServer("testuser", "testpass",
[]headers.AuthMethod{headers.AuthBasic, headers.AuthDigest})
wwwAuthenticate := authServer.GenerateHeader()
@@ -54,9 +67,10 @@ func TestAuthVLC(t *testing.T) {
ac, err := NewClient(wwwAuthenticate, url.UserPassword("testuser", "testpass"))
require.NoError(t, err)
authorization := ac.GenerateHeader(base.ANNOUNCE,
base.MustParseURL("rtsp://myhost/mypath/"))
base.MustParseURL(ca.clientURL))
err = authServer.ValidateHeader(authorization, base.ANNOUNCE,
base.MustParseURL("rtsp://myhost/mypath/trackId=0"))
base.MustParseURL(ca.serverURL))
require.NoError(t, err)
}
}

View File

@@ -126,12 +126,9 @@ func (as *Server) ValidateHeader(v base.HeaderValue, method base.Method, ur *bas
if *auth.URI != uri {
// VLC strips the control path; do another try without the control path
base, _, ok := ur.BaseControlPath()
if ok {
ur = ur.Clone()
ur.SetPath("/" + base + "/")
ur.RemoveControlPath()
uri = ur.String()
}
if *auth.URI != uri {
return fmt.Errorf("wrong url")

View File

@@ -148,6 +148,16 @@ func (u *URL) BaseControlPath() (string, string, bool) {
return basePath, controlPath, true
}
// SetHost sets the host of a RTSP URL.
func (u *URL) SetHost(host string) {
u.inner.Host = host
}
// SetUser sets the credentials of a RTSP URL.
func (u *URL) SetUser(user *url.Userinfo) {
u.inner.User = user
}
// AddControlPath adds a control path to a RTSP url.
func (u *URL) AddControlPath(controlPath string) {
// always insert the control path at the end of the url
@@ -172,21 +182,20 @@ func (u *URL) AddControlPath(controlPath string) {
}
}
// SetHost sets the host of a RTSP URL.
func (u *URL) SetHost(host string) {
u.inner.Host = host
// RemoveControlPath removes a control path from an URL.
func (u *URL) RemoveControlPath() {
_, controlPath, ok := u.BaseControlPath()
if !ok {
return
}
// SetUser sets the credentials of a RTSP URL.
func (u *URL) SetUser(user *url.Userinfo) {
u.inner.User = user
}
if strings.HasSuffix(u.inner.RawQuery, controlPath) {
u.inner.RawQuery = u.inner.RawQuery[:len(u.inner.RawQuery)-len(controlPath)]
// SetPath sets the path of a RTSP URL.
func (u *URL) SetPath(path string) {
if u.inner.RawPath != "" {
u.inner.RawPath = path
} else {
u.inner.Path = path
} else if strings.HasSuffix(u.inner.RawPath, controlPath) {
u.inner.RawPath = u.inner.RawPath[:len(u.inner.RawPath)-len(controlPath)]
} else if strings.HasSuffix(u.inner.Path, controlPath) {
u.inner.Path = u.inner.Path[:len(u.inner.Path)-len(controlPath)]
}
}