Support RTSP redirects #1909 by @eddielth
This commit is contained in:
+30
-6
@@ -93,7 +93,35 @@ func (c *Conn) Do(req *tcp.Request) (*tcp.Response, error) {
|
|||||||
|
|
||||||
c.Fire(res)
|
c.Fire(res)
|
||||||
|
|
||||||
if res.StatusCode == http.StatusUnauthorized {
|
switch res.StatusCode {
|
||||||
|
case http.StatusOK:
|
||||||
|
return res, nil
|
||||||
|
|
||||||
|
case http.StatusMovedPermanently, http.StatusFound:
|
||||||
|
rawURL := res.Header.Get("Location")
|
||||||
|
|
||||||
|
var u *url.URL
|
||||||
|
if u, err = url.Parse(rawURL); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if u.User == nil {
|
||||||
|
u.User = c.auth.UserInfo() // restore auth if we don't have it in the new URL
|
||||||
|
}
|
||||||
|
|
||||||
|
c.uri = u.String() // so auth will be saved on reconnect
|
||||||
|
|
||||||
|
_ = c.conn.Close()
|
||||||
|
|
||||||
|
if err = c.Dial(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req.URL = c.URL // because path was changed
|
||||||
|
|
||||||
|
return c.Do(req)
|
||||||
|
|
||||||
|
case http.StatusUnauthorized:
|
||||||
switch c.auth.Method {
|
switch c.auth.Method {
|
||||||
case tcp.AuthNone:
|
case tcp.AuthNone:
|
||||||
if c.auth.ReadNone(res) {
|
if c.auth.ReadNone(res) {
|
||||||
@@ -109,11 +137,7 @@ func (c *Conn) Do(req *tcp.Request) (*tcp.Response, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode != http.StatusOK {
|
return res, fmt.Errorf("wrong response on %s", req.Method)
|
||||||
return res, fmt.Errorf("wrong response on %s", req.Method)
|
|
||||||
}
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) Options() error {
|
func (c *Conn) Options() error {
|
||||||
|
|||||||
@@ -112,6 +112,10 @@ func (a *Auth) ReadNone(res *Response) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Auth) UserInfo() *url.Userinfo {
|
||||||
|
return url.UserPassword(a.user, a.pass)
|
||||||
|
}
|
||||||
|
|
||||||
func Between(s, sub1, sub2 string) string {
|
func Between(s, sub1, sub2 string) string {
|
||||||
i := strings.Index(s, sub1)
|
i := strings.Index(s, sub1)
|
||||||
if i < 0 {
|
if i < 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user