Allow setting response body in OnDescribe (#758)

* Allow setting response body in OnDescribe

Since commit 8c6495c33b, the server can no
longer directly specify the response body to DESCRIBE requests. This is
a breaking change and is a limitation for users who manually handle their
SDPs. This commit allows setting the body explicitly and takes it into
account if the `ServerStream` part of the `OnDecsribe` return value is
nil. If neither the stream, nor the body are set, the application panics.

* Add test for non-nil body for Describe
This commit is contained in:
Yuriy Gabuev
2025-04-17 12:43:01 +02:00
committed by GitHub
parent c3b5e0b76a
commit d162df21ec
2 changed files with 41 additions and 2 deletions

View File

@@ -354,6 +354,41 @@ func TestServerErrorNilURL(t *testing.T) {
<-nconnClosed
}
func TestServerDescribeNonNilBody(t *testing.T) {
sdpBody := []byte("foo-sdp")
s := &Server{
Handler: &testServerHandler{
onDescribe: func(_ *ServerHandlerOnDescribeCtx) (*base.Response, *ServerStream, error) {
return &base.Response{
StatusCode: base.StatusOK,
Body: sdpBody,
}, nil, 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)
res, err := writeReqReadRes(conn, base.Request{
Method: base.Describe,
URL: mustParseURL("rtsp://localhost:8554/"),
Header: base.Header{
"CSeq": base.HeaderValue{"1"},
},
})
require.NoError(t, err)
require.Equal(t, base.StatusOK, res.StatusCode)
require.Equal(t, sdpBody, res.Body)
}
type testServerErrMethodNotImplemented struct {
stream *ServerStream
}