mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-29 06:22:00 -08:00
support query parameteres when publishing or reading (#74)
This commit is contained in:
parent
79d0f2d053
commit
8c06c9a414
5 changed files with 61 additions and 3 deletions
16
client.go
16
client.go
|
|
@ -357,6 +357,12 @@ func (c *client) handleRequest(req *gortsplib.Request) error {
|
|||
}
|
||||
pathName = pathName[1:] // strip leading slash
|
||||
|
||||
// in RTSP, the control path is inserted after the query.
|
||||
// therefore, path and query can't be threated separately
|
||||
if req.Url.RawQuery != "" {
|
||||
pathName += "?" + req.Url.RawQuery
|
||||
}
|
||||
|
||||
switch req.Method {
|
||||
case gortsplib.OPTIONS:
|
||||
c.conn.WriteResponse(&gortsplib.Response{
|
||||
|
|
@ -382,6 +388,8 @@ func (c *client) handleRequest(req *gortsplib.Request) error {
|
|||
return errRunTerminate
|
||||
}
|
||||
|
||||
pathName = removeQueryFromPath(pathName)
|
||||
|
||||
confp := c.p.findConfForPathName(pathName)
|
||||
if confp == nil {
|
||||
c.writeResError(cseq, gortsplib.StatusBadRequest,
|
||||
|
|
@ -411,6 +419,8 @@ func (c *client) handleRequest(req *gortsplib.Request) error {
|
|||
return errRunTerminate
|
||||
}
|
||||
|
||||
pathName = removeQueryFromPath(pathName)
|
||||
|
||||
if len(pathName) == 0 {
|
||||
c.writeResError(cseq, gortsplib.StatusBadRequest, fmt.Errorf("empty base path"))
|
||||
return errRunTerminate
|
||||
|
|
@ -495,6 +505,8 @@ func (c *client) handleRequest(req *gortsplib.Request) error {
|
|||
return errRunTerminate
|
||||
}
|
||||
|
||||
basePath = removeQueryFromPath(basePath)
|
||||
|
||||
switch c.state {
|
||||
// play
|
||||
case clientStateInitial, clientStatePrePlay:
|
||||
|
|
@ -752,6 +764,8 @@ func (c *client) handleRequest(req *gortsplib.Request) error {
|
|||
return errRunTerminate
|
||||
}
|
||||
|
||||
pathName = removeQueryFromPath(pathName)
|
||||
|
||||
// path can end with a slash, remove it
|
||||
pathName = strings.TrimSuffix(pathName, "/")
|
||||
|
||||
|
|
@ -785,6 +799,8 @@ func (c *client) handleRequest(req *gortsplib.Request) error {
|
|||
return errRunTerminate
|
||||
}
|
||||
|
||||
pathName = removeQueryFromPath(pathName)
|
||||
|
||||
// path can end with a slash, remove it
|
||||
pathName = strings.TrimSuffix(pathName, "/")
|
||||
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -5,7 +5,7 @@ go 1.12
|
|||
require (
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
|
||||
github.com/aler9/gortsplib v0.0.0-20200905123647-6d46442a79c9
|
||||
github.com/aler9/gortsplib v0.0.0-20200905183437-37e3a1f29f40
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/stretchr/testify v1.6.1
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -2,8 +2,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo
|
|||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
||||
github.com/aler9/gortsplib v0.0.0-20200905123647-6d46442a79c9 h1:0igRBY+6YHv6YoAB5WTftCf6pFnoItrSy7NrQV8tfco=
|
||||
github.com/aler9/gortsplib v0.0.0-20200905123647-6d46442a79c9/go.mod h1:XybE/Zt1yFtnNEjNhAyg2w6VjD8aJ79GFfpSjkfLNd8=
|
||||
github.com/aler9/gortsplib v0.0.0-20200905183437-37e3a1f29f40 h1:l6De9lyccqCRoIlUrTi5XfHku8oO2V1LAbqROGeJuo4=
|
||||
github.com/aler9/gortsplib v0.0.0-20200905183437-37e3a1f29f40/go.mod h1:XybE/Zt1yFtnNEjNhAyg2w6VjD8aJ79GFfpSjkfLNd8=
|
||||
github.com/aler9/sdp-dirty/v3 v3.0.0-20200905103724-214b7cc25cfd h1:s/l20rPNGiyjggMdkhsLu0aQ0K0OFcROUMBDu7fGT+I=
|
||||
github.com/aler9/sdp-dirty/v3 v3.0.0-20200905103724-214b7cc25cfd/go.mod h1:5bO/aUQr9m3OasDatNNcVqKAgs7r5hgGXmszWHaC6mI=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
|
|
|
|||
33
main_test.go
33
main_test.go
|
|
@ -281,6 +281,39 @@ func TestPathWithSlash(t *testing.T) {
|
|||
require.Equal(t, 0, code)
|
||||
}
|
||||
|
||||
func TestPathWithQuery(t *testing.T) {
|
||||
p, err := newProgram([]string{}, bytes.NewBuffer(nil))
|
||||
require.NoError(t, err)
|
||||
defer p.close()
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
cnt1, err := newContainer("ffmpeg", "publish", []string{
|
||||
"-re",
|
||||
"-stream_loop", "-1",
|
||||
"-i", "/emptyvideo.ts",
|
||||
"-c", "copy",
|
||||
"-f", "rtsp",
|
||||
"-rtsp_transport", "udp",
|
||||
"rtsp://" + ownDockerIp + ":8554/test?param1=val¶m2=val",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
defer cnt1.close()
|
||||
|
||||
cnt2, err := newContainer("ffmpeg", "read", []string{
|
||||
"-rtsp_transport", "udp",
|
||||
"-i", "rtsp://" + ownDockerIp + ":8554/test?param3=otherval",
|
||||
"-vframes", "1",
|
||||
"-f", "image2",
|
||||
"-y", "/dev/null",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
defer cnt2.close()
|
||||
|
||||
code := cnt2.wait()
|
||||
require.Equal(t, 0, code)
|
||||
}
|
||||
|
||||
func TestAuth(t *testing.T) {
|
||||
t.Run("publish", func(t *testing.T) {
|
||||
stdin := []byte("\n" +
|
||||
|
|
|
|||
9
utils.go
9
utils.go
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func parseIpCidrList(in []string) ([]interface{}, error) {
|
||||
|
|
@ -100,6 +101,14 @@ func splitPath(path string) (string, string, error) {
|
|||
return basePath, controlPath, nil
|
||||
}
|
||||
|
||||
func removeQueryFromPath(path string) string {
|
||||
i := strings.Index(path, "?")
|
||||
if i >= 0 {
|
||||
return path[:i]
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
var rePathName = regexp.MustCompile("^[0-9a-zA-Z_\\-/]+$")
|
||||
|
||||
func checkPathName(name string) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue