mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
server: support publishing/reading to/from path '/' or ''
This commit is contained in:
@@ -61,7 +61,7 @@ func TestMediaURL(t *testing.T) {
|
|||||||
mustParseURL("rtsp://myuser:mypass@192.168.1.99:554/sub/path/trackID=5"),
|
mustParseURL("rtsp://myuser:mypass@192.168.1.99:554/sub/path/trackID=5"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"relative control, url without slash",
|
"relative control, subpath, without slash",
|
||||||
[]byte("v=0\r\n" +
|
[]byte("v=0\r\n" +
|
||||||
"m=video 0 RTP/AVP 96\r\n" +
|
"m=video 0 RTP/AVP 96\r\n" +
|
||||||
"a=rtpmap:96 H264/90000\r\n" +
|
"a=rtpmap:96 H264/90000\r\n" +
|
||||||
|
@@ -87,11 +87,5 @@ func (u *URL) RTSPPathAndQuery() (string, bool) {
|
|||||||
pathAndQuery += "?" + u.RawQuery
|
pathAndQuery += "?" + u.RawQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove leading slash
|
|
||||||
if len(pathAndQuery) == 0 || pathAndQuery[0] != '/' {
|
|
||||||
return "", false
|
|
||||||
}
|
|
||||||
pathAndQuery = pathAndQuery[1:]
|
|
||||||
|
|
||||||
return pathAndQuery, true
|
return pathAndQuery, true
|
||||||
}
|
}
|
||||||
|
@@ -113,28 +113,49 @@ func TestURLCloneWithoutCredentials(t *testing.T) {
|
|||||||
|
|
||||||
func TestURLRTSPPathAndQuery(t *testing.T) {
|
func TestURLRTSPPathAndQuery(t *testing.T) {
|
||||||
for _, ca := range []struct {
|
for _, ca := range []struct {
|
||||||
u *URL
|
name string
|
||||||
b string
|
u *URL
|
||||||
|
b string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
"standard",
|
||||||
mustParse("rtsp://localhost:8554/teststream/trackID=1"),
|
mustParse("rtsp://localhost:8554/teststream/trackID=1"),
|
||||||
"teststream/trackID=1",
|
"/teststream/trackID=1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"subpath",
|
||||||
mustParse("rtsp://localhost:8554/test/stream/trackID=1"),
|
mustParse("rtsp://localhost:8554/test/stream/trackID=1"),
|
||||||
"test/stream/trackID=1",
|
"/test/stream/trackID=1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"path and query",
|
||||||
mustParse("rtsp://192.168.1.99:554/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp/trackID=1"),
|
mustParse("rtsp://192.168.1.99:554/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp/trackID=1"),
|
||||||
"test?user=tmp&password=BagRep1&channel=1&stream=0.sdp/trackID=1",
|
"/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp/trackID=1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"path and query with special chars",
|
||||||
mustParse("rtsp://192.168.1.99:554/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1"),
|
mustParse("rtsp://192.168.1.99:554/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1"),
|
||||||
"te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1",
|
"/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"path and query attached",
|
||||||
mustParse("rtsp://192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1"),
|
mustParse("rtsp://192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1"),
|
||||||
"user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1",
|
"/user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"no path",
|
||||||
|
mustParse("rtsp://192.168.1.99:554"),
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"single slash",
|
||||||
|
mustParse("rtsp://192.168.1.99:554/"),
|
||||||
|
"/",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"no slash and query",
|
||||||
|
mustParse("rtsp://192.168.1.99:554?testing"),
|
||||||
|
"?testing",
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
b, ok := ca.u.RTSPPathAndQuery()
|
b, ok := ca.u.RTSPPathAndQuery()
|
||||||
|
@@ -82,42 +82,61 @@ func doDescribe(conn *conn.Conn) (*sdp.SessionDescription, error) {
|
|||||||
return &desc, err
|
return &desc, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServerPlaySetupPath(t *testing.T) {
|
func TestServerPlayPath(t *testing.T) {
|
||||||
for _, ca := range []struct {
|
for _, ca := range []struct {
|
||||||
name string
|
name string
|
||||||
url string
|
setupURL string
|
||||||
path string
|
playURL string
|
||||||
|
path string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"normal",
|
"normal",
|
||||||
"rtsp://localhost:8554/teststream/[control2]",
|
"rtsp://localhost:8554/teststream[control]",
|
||||||
"teststream",
|
"rtsp://localhost:8554/teststream/",
|
||||||
|
"/teststream",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"with query",
|
"with query",
|
||||||
"rtsp://localhost:8554/teststream?testing=123/[control4]",
|
"rtsp://localhost:8554/teststream?testing=123[control]",
|
||||||
"teststream",
|
"rtsp://localhost:8554/teststream/",
|
||||||
|
"/teststream",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// this is needed to support reading mpegts with ffmpeg
|
// this is needed to support reading mpegts with ffmpeg
|
||||||
"without media id",
|
"without media id",
|
||||||
"rtsp://localhost:8554/teststream/",
|
"rtsp://localhost:8554/teststream/",
|
||||||
"teststream",
|
"rtsp://localhost:8554/teststream/",
|
||||||
|
"/teststream",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"subpath",
|
"subpath",
|
||||||
"rtsp://localhost:8554/test/stream/[control0]",
|
"rtsp://localhost:8554/test/stream[control]",
|
||||||
"test/stream",
|
"rtsp://localhost:8554/test/stream/",
|
||||||
|
"/test/stream",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"subpath without media id",
|
"subpath without media id",
|
||||||
"rtsp://localhost:8554/test/stream/",
|
"rtsp://localhost:8554/test/stream/",
|
||||||
"test/stream",
|
"rtsp://localhost:8554/test/stream/",
|
||||||
|
"/test/stream",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"subpath with query",
|
"subpath with query",
|
||||||
"rtsp://localhost:8554/test/stream?testing=123/[control4]",
|
"rtsp://localhost:8554/test/stream?testing=123[control]",
|
||||||
"test/stream",
|
"rtsp://localhost:8554/test/stream",
|
||||||
|
"/test/stream",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"no slash",
|
||||||
|
"rtsp://localhost:8554[control]",
|
||||||
|
"rtsp://localhost:8554/",
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"single slash",
|
||||||
|
"rtsp://localhost:8554/[control]",
|
||||||
|
"rtsp://localhost:8554//",
|
||||||
|
"/",
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(ca.name, func(t *testing.T) {
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
@@ -126,7 +145,6 @@ func TestServerPlaySetupPath(t *testing.T) {
|
|||||||
testH264Media,
|
testH264Media,
|
||||||
testH264Media,
|
testH264Media,
|
||||||
testH264Media,
|
testH264Media,
|
||||||
testH264Media,
|
|
||||||
})
|
})
|
||||||
defer stream.Close()
|
defer stream.Close()
|
||||||
|
|
||||||
@@ -139,10 +157,18 @@ func TestServerPlaySetupPath(t *testing.T) {
|
|||||||
},
|
},
|
||||||
onSetup: func(ctx *ServerHandlerOnSetupCtx) (*base.Response, *ServerStream, error) {
|
onSetup: func(ctx *ServerHandlerOnSetupCtx) (*base.Response, *ServerStream, error) {
|
||||||
require.Equal(t, ca.path, ctx.Path)
|
require.Equal(t, ca.path, ctx.Path)
|
||||||
|
|
||||||
return &base.Response{
|
return &base.Response{
|
||||||
StatusCode: base.StatusOK,
|
StatusCode: base.StatusOK,
|
||||||
}, stream, nil
|
}, stream, nil
|
||||||
},
|
},
|
||||||
|
onPlay: func(ctx *ServerHandlerOnPlayCtx) (*base.Response, error) {
|
||||||
|
require.Equal(t, ca.path, ctx.Path)
|
||||||
|
|
||||||
|
return &base.Response{
|
||||||
|
StatusCode: base.StatusOK,
|
||||||
|
}, nil
|
||||||
|
},
|
||||||
},
|
},
|
||||||
RTSPAddress: "localhost:8554",
|
RTSPAddress: "localhost:8554",
|
||||||
}
|
}
|
||||||
@@ -172,14 +198,11 @@ func TestServerPlaySetupPath(t *testing.T) {
|
|||||||
InterleavedIDs: &[2]int{0, 1},
|
InterleavedIDs: &[2]int{0, 1},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, md := range desc.MediaDescriptions {
|
v, _ := desc.MediaDescriptions[1].Attribute("control")
|
||||||
v, _ := md.Attribute("control")
|
|
||||||
ca.url = strings.ReplaceAll(ca.url, "[control"+strconv.FormatInt(int64(i), 10)+"]", v)
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := writeReqReadRes(conn, base.Request{
|
res, err := writeReqReadRes(conn, base.Request{
|
||||||
Method: base.Setup,
|
Method: base.Setup,
|
||||||
URL: mustParseURL(ca.url),
|
URL: mustParseURL(strings.ReplaceAll(ca.setupURL, "[control]", "/"+v)),
|
||||||
Header: base.Header{
|
Header: base.Header{
|
||||||
"CSeq": base.HeaderValue{"2"},
|
"CSeq": base.HeaderValue{"2"},
|
||||||
"Transport": th.Marshal(),
|
"Transport": th.Marshal(),
|
||||||
@@ -187,6 +210,21 @@ func TestServerPlaySetupPath(t *testing.T) {
|
|||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, base.StatusOK, res.StatusCode)
|
require.Equal(t, base.StatusOK, res.StatusCode)
|
||||||
|
|
||||||
|
var sx headers.Session
|
||||||
|
err = sx.Unmarshal(res.Header["Session"])
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
res, err = writeReqReadRes(conn, base.Request{
|
||||||
|
Method: base.Play,
|
||||||
|
URL: mustParseURL(ca.playURL),
|
||||||
|
Header: base.Header{
|
||||||
|
"CSeq": base.HeaderValue{"3"},
|
||||||
|
"Session": base.HeaderValue{sx.Session},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, base.StatusOK, res.StatusCode)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -100,15 +100,10 @@ func TestServerRecordErrorAnnounce(t *testing.T) {
|
|||||||
invalidURLAnnounceReq(t, "rtsp:// aaaaa"),
|
invalidURLAnnounceReq(t, "rtsp:// aaaaa"),
|
||||||
"unable to generate media URL",
|
"unable to generate media URL",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"invalid URL 2",
|
|
||||||
invalidURLAnnounceReq(t, "rtsp://host"),
|
|
||||||
"invalid media URL (rtsp://localhost:8554)",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"invalid URL 3",
|
"invalid URL 3",
|
||||||
invalidURLAnnounceReq(t, "rtsp://host/otherpath"),
|
invalidURLAnnounceReq(t, "rtsp://host/otherpath"),
|
||||||
"invalid media path: must begin with 'teststream', but is 'otherpath'",
|
"invalid media path: must begin with '/teststream', but is '/otherpath'",
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(ca.name, func(t *testing.T) {
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
@@ -146,30 +141,54 @@ func TestServerRecordErrorAnnounce(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServerRecordSetupPath(t *testing.T) {
|
func TestServerRecordPath(t *testing.T) {
|
||||||
for _, ca := range []struct {
|
for _, ca := range []struct {
|
||||||
name string
|
name string
|
||||||
control string
|
control string
|
||||||
url string
|
announceURL string
|
||||||
path string
|
setupURL string
|
||||||
|
path string
|
||||||
|
query string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"normal",
|
"normal",
|
||||||
"bbb=ccc",
|
"bbb=ccc",
|
||||||
|
"rtsp://localhost:8554/teststream",
|
||||||
"rtsp://localhost:8554/teststream/bbb=ccc",
|
"rtsp://localhost:8554/teststream/bbb=ccc",
|
||||||
"teststream",
|
"/teststream",
|
||||||
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"subpath",
|
"subpath",
|
||||||
"ddd=eee",
|
"ddd=eee",
|
||||||
|
"rtsp://localhost:8554/test/stream",
|
||||||
"rtsp://localhost:8554/test/stream/ddd=eee",
|
"rtsp://localhost:8554/test/stream/ddd=eee",
|
||||||
"test/stream",
|
"/test/stream",
|
||||||
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"subpath and query",
|
"subpath and query",
|
||||||
"fff=ggg",
|
"fff=ggg",
|
||||||
|
"rtsp://localhost:8554/test/stream?testing=0",
|
||||||
"rtsp://localhost:8554/test/stream?testing=0/fff=ggg",
|
"rtsp://localhost:8554/test/stream?testing=0/fff=ggg",
|
||||||
"test/stream?testing=0",
|
"/test/stream",
|
||||||
|
"testing=0",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"no path",
|
||||||
|
"streamid=1",
|
||||||
|
"rtsp://localhost:8554",
|
||||||
|
"rtsp://localhost:8554/streamid=1",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"single slash",
|
||||||
|
"streamid=1",
|
||||||
|
"rtsp://localhost:8554/",
|
||||||
|
"rtsp://localhost:8554//streamid=1",
|
||||||
|
"/",
|
||||||
|
"",
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(ca.name, func(t *testing.T) {
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
@@ -185,15 +204,21 @@ func TestServerRecordSetupPath(t *testing.T) {
|
|||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
onSetup: func(ctx *ServerHandlerOnSetupCtx) (*base.Response, *ServerStream, error) {
|
onSetup: func(ctx *ServerHandlerOnSetupCtx) (*base.Response, *ServerStream, error) {
|
||||||
p := ctx.Path
|
require.Equal(t, ca.path, ctx.Path)
|
||||||
if ctx.Query != "" {
|
require.Equal(t, ca.query, ctx.Query)
|
||||||
p += "?" + ctx.Query
|
|
||||||
}
|
|
||||||
require.Equal(t, ca.path, p)
|
|
||||||
return &base.Response{
|
return &base.Response{
|
||||||
StatusCode: base.StatusOK,
|
StatusCode: base.StatusOK,
|
||||||
}, nil, nil
|
}, nil, nil
|
||||||
},
|
},
|
||||||
|
onRecord: func(ctx *ServerHandlerOnRecordCtx) (*base.Response, error) {
|
||||||
|
require.Equal(t, ca.path, ctx.Path)
|
||||||
|
require.Equal(t, ca.query, ctx.Query)
|
||||||
|
|
||||||
|
return &base.Response{
|
||||||
|
StatusCode: base.StatusOK,
|
||||||
|
}, nil
|
||||||
|
},
|
||||||
},
|
},
|
||||||
RTSPAddress: "localhost:8554",
|
RTSPAddress: "localhost:8554",
|
||||||
}
|
}
|
||||||
@@ -230,7 +255,7 @@ func TestServerRecordSetupPath(t *testing.T) {
|
|||||||
|
|
||||||
res, err := writeReqReadRes(conn, base.Request{
|
res, err := writeReqReadRes(conn, base.Request{
|
||||||
Method: base.Announce,
|
Method: base.Announce,
|
||||||
URL: mustParseURL("rtsp://localhost:8554/" + ca.path),
|
URL: mustParseURL(ca.announceURL),
|
||||||
Header: base.Header{
|
Header: base.Header{
|
||||||
"CSeq": base.HeaderValue{"1"},
|
"CSeq": base.HeaderValue{"1"},
|
||||||
"Content-Type": base.HeaderValue{"application/sdp"},
|
"Content-Type": base.HeaderValue{"application/sdp"},
|
||||||
@@ -255,7 +280,7 @@ func TestServerRecordSetupPath(t *testing.T) {
|
|||||||
|
|
||||||
res, err = writeReqReadRes(conn, base.Request{
|
res, err = writeReqReadRes(conn, base.Request{
|
||||||
Method: base.Setup,
|
Method: base.Setup,
|
||||||
URL: mustParseURL(ca.url),
|
URL: mustParseURL(ca.setupURL),
|
||||||
Header: base.Header{
|
Header: base.Header{
|
||||||
"CSeq": base.HeaderValue{"2"},
|
"CSeq": base.HeaderValue{"2"},
|
||||||
"Transport": th.Marshal(),
|
"Transport": th.Marshal(),
|
||||||
@@ -263,6 +288,21 @@ func TestServerRecordSetupPath(t *testing.T) {
|
|||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, base.StatusOK, res.StatusCode)
|
require.Equal(t, base.StatusOK, res.StatusCode)
|
||||||
|
|
||||||
|
var sx headers.Session
|
||||||
|
err = sx.Unmarshal(res.Header["Session"])
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
res, err = writeReqReadRes(conn, base.Request{
|
||||||
|
Method: base.Record,
|
||||||
|
URL: mustParseURL(ca.announceURL),
|
||||||
|
Header: base.Header{
|
||||||
|
"CSeq": base.HeaderValue{"3"},
|
||||||
|
"Session": base.HeaderValue{sx.Session},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, base.StatusOK, res.StatusCode)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1114,100 +1114,6 @@ func TestServerSessionTeardown(t *testing.T) {
|
|||||||
require.Equal(t, base.StatusOK, res.StatusCode)
|
require.Equal(t, base.StatusOK, res.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServerErrorInvalidPath(t *testing.T) {
|
|
||||||
for _, ca := range []string{"inside session", "outside session"} {
|
|
||||||
t.Run(ca, func(t *testing.T) {
|
|
||||||
nconnClosed := make(chan struct{})
|
|
||||||
|
|
||||||
stream := NewServerStream(media.Medias{testH264Media})
|
|
||||||
defer stream.Close()
|
|
||||||
|
|
||||||
s := &Server{
|
|
||||||
Handler: &testServerHandler{
|
|
||||||
onConnClose: func(ctx *ServerHandlerOnConnCloseCtx) {
|
|
||||||
require.EqualError(t, ctx.Error, "invalid path")
|
|
||||||
close(nconnClosed)
|
|
||||||
},
|
|
||||||
onDescribe: func(ctx *ServerHandlerOnDescribeCtx) (*base.Response, *ServerStream, error) {
|
|
||||||
return &base.Response{
|
|
||||||
StatusCode: base.StatusOK,
|
|
||||||
}, stream, nil
|
|
||||||
},
|
|
||||||
onSetup: func(ctx *ServerHandlerOnSetupCtx) (*base.Response, *ServerStream, error) {
|
|
||||||
return &base.Response{
|
|
||||||
StatusCode: base.StatusOK,
|
|
||||||
}, stream, nil
|
|
||||||
},
|
|
||||||
},
|
|
||||||
RTSPAddress: "localhost:8554",
|
|
||||||
}
|
|
||||||
|
|
||||||
err := s.Start()
|
|
||||||
require.NoError(t, err)
|
|
||||||
defer s.Close()
|
|
||||||
|
|
||||||
nconn, err := net.Dial("tcp", "localhost:8554")
|
|
||||||
require.NoError(t, err)
|
|
||||||
defer nconn.Close()
|
|
||||||
conn := conn.NewConn(nconn)
|
|
||||||
|
|
||||||
desc, err := doDescribe(conn)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
if ca == "inside session" {
|
|
||||||
res, err := writeReqReadRes(conn, base.Request{
|
|
||||||
Method: base.Setup,
|
|
||||||
URL: mustParseURL("rtsp://localhost:8554/teststream/" + controlAttribute(desc.MediaDescriptions[0])),
|
|
||||||
Header: base.Header{
|
|
||||||
"CSeq": base.HeaderValue{"1"},
|
|
||||||
"Transport": headers.Transport{
|
|
||||||
Protocol: headers.TransportProtocolTCP,
|
|
||||||
Delivery: func() *headers.TransportDelivery {
|
|
||||||
v := headers.TransportDeliveryUnicast
|
|
||||||
return &v
|
|
||||||
}(),
|
|
||||||
Mode: func() *headers.TransportMode {
|
|
||||||
v := headers.TransportModePlay
|
|
||||||
return &v
|
|
||||||
}(),
|
|
||||||
InterleavedIDs: &[2]int{0, 1},
|
|
||||||
}.Marshal(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, base.StatusOK, res.StatusCode)
|
|
||||||
|
|
||||||
var sx headers.Session
|
|
||||||
err = sx.Unmarshal(res.Header["Session"])
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
res, err = writeReqReadRes(conn, base.Request{
|
|
||||||
Method: base.SetParameter,
|
|
||||||
URL: mustParseURL("rtsp://localhost:8554"),
|
|
||||||
Header: base.Header{
|
|
||||||
"CSeq": base.HeaderValue{"2"},
|
|
||||||
"Session": base.HeaderValue{sx.Session},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, base.StatusBadRequest, res.StatusCode)
|
|
||||||
} else {
|
|
||||||
res, err := writeReqReadRes(conn, base.Request{
|
|
||||||
Method: base.SetParameter,
|
|
||||||
URL: mustParseURL("rtsp://localhost:8554"),
|
|
||||||
Header: base.Header{
|
|
||||||
"CSeq": base.HeaderValue{"1"},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, base.StatusBadRequest, res.StatusCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
<-nconnClosed
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestServerAuth(t *testing.T) {
|
func TestServerAuth(t *testing.T) {
|
||||||
authValidator := auth.NewValidator("myuser", "mypass", nil)
|
authValidator := auth.NewValidator("myuser", "mypass", nil)
|
||||||
|
|
||||||
|
@@ -450,8 +450,8 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
|||||||
}, liberrors.ErrServerInvalidPath{}
|
}, liberrors.ErrServerInvalidPath{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Method != base.Announce {
|
// pathAndQuery can end with a slash due to Content-Base, remove it
|
||||||
// path can end with a slash due to Content-Base, remove it
|
if ss.state == ServerSessionStatePrePlay || ss.state == ServerSessionStatePlay {
|
||||||
pathAndQuery = strings.TrimSuffix(pathAndQuery, "/")
|
pathAndQuery = strings.TrimSuffix(pathAndQuery, "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -694,12 +694,20 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
|||||||
case ServerSessionStateInitial, ServerSessionStatePrePlay: // play
|
case ServerSessionStateInitial, ServerSessionStatePrePlay: // play
|
||||||
medi = findMediaByUUID(stream, mediaUUID)
|
medi = findMediaByUUID(stream, mediaUUID)
|
||||||
default: // record
|
default: // record
|
||||||
medi = findMediaByURL(ss.announcedMedias, &url.URL{
|
baseURL := &url.URL{
|
||||||
Scheme: req.URL.Scheme,
|
Scheme: req.URL.Scheme,
|
||||||
Host: req.URL.Host,
|
Host: req.URL.Host,
|
||||||
Path: path,
|
Path: path,
|
||||||
RawQuery: query,
|
RawQuery: query,
|
||||||
}, req.URL)
|
}
|
||||||
|
|
||||||
|
if baseURL.RawQuery != "" {
|
||||||
|
baseURL.RawQuery += "/"
|
||||||
|
} else {
|
||||||
|
baseURL.Path += "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
medi = findMediaByURL(ss.announcedMedias, baseURL, req.URL)
|
||||||
}
|
}
|
||||||
|
|
||||||
if medi == nil {
|
if medi == nil {
|
||||||
@@ -824,8 +832,7 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
|||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ss.State() == ServerSessionStatePrePlay &&
|
if ss.State() == ServerSessionStatePrePlay && path != *ss.setuppedPath {
|
||||||
path != *ss.setuppedPath {
|
|
||||||
return &base.Response{
|
return &base.Response{
|
||||||
StatusCode: base.StatusBadRequest,
|
StatusCode: base.StatusBadRequest,
|
||||||
}, liberrors.ErrServerPathHasChanged{Prev: *ss.setuppedPath, Cur: path}
|
}, liberrors.ErrServerPathHasChanged{Prev: *ss.setuppedPath, Cur: path}
|
||||||
|
Reference in New Issue
Block a user