mirror of
https://github.com/aler9/gortsplib
synced 2025-10-10 17:40:28 +08:00
fix error when using vlc, authentication and urls with query parameters
This commit is contained in:
@@ -47,16 +47,30 @@ func TestAuthMethods(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAuthVLC(t *testing.T) {
|
||||
authServer := NewServer("testuser", "testpass",
|
||||
[]headers.AuthMethod{headers.AuthBasic, headers.AuthDigest})
|
||||
wwwAuthenticate := authServer.GenerateHeader()
|
||||
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()
|
||||
|
||||
ac, err := NewClient(wwwAuthenticate, url.UserPassword("testuser", "testpass"))
|
||||
require.NoError(t, err)
|
||||
authorization := ac.GenerateHeader(base.ANNOUNCE,
|
||||
base.MustParseURL("rtsp://myhost/mypath/"))
|
||||
ac, err := NewClient(wwwAuthenticate, url.UserPassword("testuser", "testpass"))
|
||||
require.NoError(t, err)
|
||||
authorization := ac.GenerateHeader(base.ANNOUNCE,
|
||||
base.MustParseURL(ca.clientURL))
|
||||
|
||||
err = authServer.ValidateHeader(authorization, base.ANNOUNCE,
|
||||
base.MustParseURL("rtsp://myhost/mypath/trackId=0"))
|
||||
require.NoError(t, err)
|
||||
err = authServer.ValidateHeader(authorization, base.ANNOUNCE,
|
||||
base.MustParseURL(ca.serverURL))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
@@ -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 + "/")
|
||||
uri = ur.String()
|
||||
}
|
||||
ur = ur.Clone()
|
||||
ur.RemoveControlPath()
|
||||
uri = ur.String()
|
||||
|
||||
if *auth.URI != uri {
|
||||
return fmt.Errorf("wrong url")
|
||||
|
37
base/url.go
37
base/url.go
@@ -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)]
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user