server: support publishing/reading to/from path '/' or ''

This commit is contained in:
aler9
2023-01-11 00:39:58 +01:00
parent e86bf26343
commit 645f9462e2
7 changed files with 161 additions and 155 deletions

View File

@@ -450,8 +450,8 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
}, liberrors.ErrServerInvalidPath{}
}
if req.Method != base.Announce {
// path can end with a slash due to Content-Base, remove it
// pathAndQuery can end with a slash due to Content-Base, remove it
if ss.state == ServerSessionStatePrePlay || ss.state == ServerSessionStatePlay {
pathAndQuery = strings.TrimSuffix(pathAndQuery, "/")
}
@@ -694,12 +694,20 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
case ServerSessionStateInitial, ServerSessionStatePrePlay: // play
medi = findMediaByUUID(stream, mediaUUID)
default: // record
medi = findMediaByURL(ss.announcedMedias, &url.URL{
baseURL := &url.URL{
Scheme: req.URL.Scheme,
Host: req.URL.Host,
Path: path,
RawQuery: query,
}, req.URL)
}
if baseURL.RawQuery != "" {
baseURL.RawQuery += "/"
} else {
baseURL.Path += "/"
}
medi = findMediaByURL(ss.announcedMedias, baseURL, req.URL)
}
if medi == nil {
@@ -824,8 +832,7 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
}, err
}
if ss.State() == ServerSessionStatePrePlay &&
path != *ss.setuppedPath {
if ss.State() == ServerSessionStatePrePlay && path != *ss.setuppedPath {
return &base.Response{
StatusCode: base.StatusBadRequest,
}, liberrors.ErrServerPathHasChanged{Prev: *ss.setuppedPath, Cur: path}