View Source Membrane.RTSP.Request (Membrane RTSP v0.6.2)
This module represents a RTSP 1.0 request.
Summary
Functions
Retrieves the first header matching given name from a request.
Parse a binary request into RTSP Request struct
Parse the Transport header.
Returns the encoded URI as a binary. This is handy for digest auth since this value must be encoded as per the digest algorithm
Renders the a RTSP request struct into a binary that is a valid RTSP request string that can be transmitted via communication channel.
Attaches a header to a RTSP request struct.
Types
@type t() :: %Membrane.RTSP.Request{ body: binary(), headers: Membrane.RTSP.headers(), method: binary(), path: nil | binary() }
@type transport_header() :: [ transport: :TCP | :UDP, mode: :unicast | :multicast, parameters: map() ]
Functions
Retrieves the first header matching given name from a request.
iex> request = %Request{
...> method: "OPTIONS",
...> headers: [{"header_name", "header_value"}]
...> }
iex> Request.get_header(request, "header_name")
{:ok, "header_value"}
iex> Request.get_header(request, "non_existent_header")
{:error, :no_such_header}
Parse a binary request into RTSP Request struct
iex> Request.parse("DESCRIBE rtsp://domain.net:554/path:movie.mov RTSP/1.0\r\n\r\n")
{:ok, %Request{method: "DESCRIBE", path: "rtsp://domain.net:554/path:movie.mov", headers: [], body: nil}}
iex> Request.parse("DESCRIBE rtsp://domain.net:554/path:movie.mov RTSP/1.0\r\nCSeq: 1\r\n\r\n")
{:ok, %Request{method: "DESCRIBE", path: "rtsp://domain.net:554/path:movie.mov", headers: [{"CSeq", "1"}], body: nil}}
iex> Request.parse("DESCRIBE rtsp://domain.net:554/path:movie.mov RTSP/1.0\r\nContent-Length: 11\r\n\r\nHello World")
{:ok, %Request{method: "DESCRIBE", path: "rtsp://domain.net:554/path:movie.mov", headers: [{"Content-Length", "11"}], body: "Hello World"}}
iex> Request.parse("DESCRIBE rtsp://domain.net:554/path:movie.mov RTSP/1.1\r\n\r\n")
{:error, "expected string \"RTSP/1.0\""}
@spec parse_transport_header(t()) :: {:ok, transport_header()} | {:error, :no_such_header | :invalid_header}
Parse the Transport header.
iex> req = %Request{method: "SETUP", headers: [{"Transport", "RTP/AVP;unicast;client_port=30001-30002"}]}
iex> Request.parse_transport_header(req)
{:ok, [transport: :UDP, mode: :unicast, parameters: %{"client_port" => {30001, 30002}}]}
iex> req = %Request{method: "SETUP", headers: [{"Transport", "RTP/AVP;ttl=15"}]}
iex> Request.parse_transport_header(req)
{:ok, [transport: :UDP, mode: :multicast, parameters: %{"ttl" => 15}]}
iex> req = %Request{method: "SETUP", headers: [{"Transport", "RTP/AVP/TCP;unicast;interleaved=0-1"}]}
iex> Request.parse_transport_header(req)
{:ok, [transport: :TCP, mode: :unicast, parameters: %{"interleaved" => {0, 1}}]}
iex> req = %Request{method: "SETUP", headers: [{"Transport", "RTP/AVP"}]}
iex> Request.parse_transport_header(req)
{:ok, [transport: :UDP, mode: :multicast, parameters: %{}]}
iex> req = %Request{method: "SETUP", headers: [{"Transport", "RTP/AV"}]}
iex> Request.parse_transport_header(req)
{:error, :invalid_header}
iex> Request.parse_transport_header(%Request{method: "SETUP"})
{:error, :no_such_header}
Returns the encoded URI as a binary. This is handy for digest auth since this value must be encoded as per the digest algorithm
Renders the a RTSP request struct into a binary that is a valid RTSP request string that can be transmitted via communication channel.
iex> uri = URI.parse("rtsp://domain.net:554/path:movie.mov")
iex> Request.stringify(%Request{method: "DESCRIBE"}, uri)
"DESCRIBE rtsp://domain.net:554/path:movie.mov RTSP/1.0\r\n\r\n"
iex> Request.stringify(%Request{method: "PLAY", path: "trackID=2"}, uri)
"PLAY rtsp://domain.net:554/path:movie.mov/trackID=2 RTSP/1.0\r\n\r\n"
iex> Request.stringify(%Request{method: "SET_PARAMETER", body: "parameter:value"}, uri)
"SET_PARAMETER rtsp://domain.net:554/path:movie.mov RTSP/1.0\r\n\r\nparameter:value"
Access credentials won't be rendered into an url present in a RTSP start line.
iex> uri = URI.parse("rtsp://user:password@domain.net:554/path:movie.mov")
iex> Request.stringify(%Request{method: "DESCRIBE"}, uri)
"DESCRIBE rtsp://domain.net:554/path:movie.mov RTSP/1.0\r\n\r\n"
Attaches a header to a RTSP request struct.
iex> Request.with_header(%Request{method: "DESCRIBE"}, "header_name", "header_value")
%Request{method: "DESCRIBE", headers: [{"header_name","header_value"}]}