mirror of
https://github.com/aler9/gortsplib
synced 2025-10-11 10:00:25 +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) {
|
func TestAuthVLC(t *testing.T) {
|
||||||
authServer := NewServer("testuser", "testpass",
|
for _, ca := range []struct {
|
||||||
[]headers.AuthMethod{headers.AuthBasic, headers.AuthDigest})
|
clientURL string
|
||||||
wwwAuthenticate := authServer.GenerateHeader()
|
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"))
|
ac, err := NewClient(wwwAuthenticate, url.UserPassword("testuser", "testpass"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
authorization := ac.GenerateHeader(base.ANNOUNCE,
|
authorization := ac.GenerateHeader(base.ANNOUNCE,
|
||||||
base.MustParseURL("rtsp://myhost/mypath/"))
|
base.MustParseURL(ca.clientURL))
|
||||||
|
|
||||||
err = authServer.ValidateHeader(authorization, base.ANNOUNCE,
|
err = authServer.ValidateHeader(authorization, base.ANNOUNCE,
|
||||||
base.MustParseURL("rtsp://myhost/mypath/trackId=0"))
|
base.MustParseURL(ca.serverURL))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -126,12 +126,9 @@ func (as *Server) ValidateHeader(v base.HeaderValue, method base.Method, ur *bas
|
|||||||
|
|
||||||
if *auth.URI != uri {
|
if *auth.URI != uri {
|
||||||
// VLC strips the control path; do another try without the control path
|
// VLC strips the control path; do another try without the control path
|
||||||
base, _, ok := ur.BaseControlPath()
|
ur = ur.Clone()
|
||||||
if ok {
|
ur.RemoveControlPath()
|
||||||
ur = ur.Clone()
|
uri = ur.String()
|
||||||
ur.SetPath("/" + base + "/")
|
|
||||||
uri = ur.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
if *auth.URI != uri {
|
if *auth.URI != uri {
|
||||||
return fmt.Errorf("wrong url")
|
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
|
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.
|
// AddControlPath adds a control path to a RTSP url.
|
||||||
func (u *URL) AddControlPath(controlPath string) {
|
func (u *URL) AddControlPath(controlPath string) {
|
||||||
// always insert the control path at the end of the url
|
// 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.
|
// RemoveControlPath removes a control path from an URL.
|
||||||
func (u *URL) SetHost(host string) {
|
func (u *URL) RemoveControlPath() {
|
||||||
u.inner.Host = host
|
_, controlPath, ok := u.BaseControlPath()
|
||||||
}
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// SetUser sets the credentials of a RTSP URL.
|
if strings.HasSuffix(u.inner.RawQuery, controlPath) {
|
||||||
func (u *URL) SetUser(user *url.Userinfo) {
|
u.inner.RawQuery = u.inner.RawQuery[:len(u.inner.RawQuery)-len(controlPath)]
|
||||||
u.inner.User = user
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetPath sets the path of a RTSP URL.
|
} else if strings.HasSuffix(u.inner.RawPath, controlPath) {
|
||||||
func (u *URL) SetPath(path string) {
|
u.inner.RawPath = u.inner.RawPath[:len(u.inner.RawPath)-len(controlPath)]
|
||||||
if u.inner.RawPath != "" {
|
|
||||||
u.inner.RawPath = path
|
} else if strings.HasSuffix(u.inner.Path, controlPath) {
|
||||||
} else {
|
u.inner.Path = u.inner.Path[:len(u.inner.Path)-len(controlPath)]
|
||||||
u.inner.Path = path
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user