View Source Membrane.RTSP.Response (Membrane RTSP v0.6.2)

This module represents a RTSP response.

Summary

Functions

Retrieves the first header matching given name from a response.

Returns true if the response is a success.

Parses RTSP response.

Renders an RTSP response struct into a binary that is a valid RTSP response string that can be transmitted via communication channel.

Verifies if raw response binary has got proper length by comparing Content-Length header value to actual size of body in response. Returns tuple with verdict, expected size and actual size of body

Adds a body to the response and sets Content-Length header

Attaches a header to a RTSP response struct.

Types

@type result() :: {:ok, t()} | {:error, atom()}
@type t() :: %Membrane.RTSP.Response{
  body: ExSDP.t() | binary(),
  headers: Membrane.RTSP.headers(),
  status: non_neg_integer(),
  version: term()
}

Functions

Link to this function

get_header(response, name)

View Source
@spec get_header(t(), binary()) :: {:error, :no_such_header} | {:ok, binary()}

Retrieves the first header matching given name from a response.

  iex> response = %Response{
  ...>   status: 200,
  ...>   version: "1.0",
  ...>   headers: [{"header_name", "header_value"}]
  ...> }
  iex> Response.get_header(response, "header_name")
  {:ok, "header_value"}
  iex> Response.get_header(response, "non_existent_header")
  {:error, :no_such_header}
@spec new(non_neg_integer()) :: t()
@spec ok?(t()) :: boolean()

Returns true if the response is a success.

  iex> Response.ok?(Response.new(204))
  true

  iex> Response.ok?(Response.new(400))
  false
@spec parse(binary()) ::
  {:ok, t()} | {:error, :invalid_start_line | :malformed_header}

Parses RTSP response.

If the body is present it will be parsed according to Content-Type header. Currently only the application/sdp is supported.

@spec stringify(t()) :: binary()

Renders an RTSP response struct into a binary that is a valid RTSP response string that can be transmitted via communication channel.

  iex> Response.stringify(%Response{version: "1.0", status: 200, headers: []})
  "RTSP/1.0 200 OK\r\n\r\n"

  iex> Response.stringify(%Response{version: "1.0", status: 200, headers: [{"Content-Length", "11"}, {"Session", "15569"}], body: "Hello World"})
  "RTSP/1.0 200 OK\r\nContent-Length: 11\r\nSession: 15569\r\n\r\nHello World"
Link to this function

verify_content_length(response)

View Source
@spec verify_content_length(binary()) ::
  {:ok, non_neg_integer(), non_neg_integer()}
  | {:error, non_neg_integer(), non_neg_integer()}

Verifies if raw response binary has got proper length by comparing Content-Length header value to actual size of body in response. Returns tuple with verdict, expected size and actual size of body

Example responses: {:ok, 512, 512} - Content-Length header value and body size matched. A response is complete. {:ok, 0, 0} - Content-Length header missing or set to 0 and no body. A response is complete. {:error, 512, 123} - Missing part of body in response. {:error, 512, 0} - Missing whole body in response. {:error, 0, 0} - Missing part of header or missing delimiter at the and of header part.

Link to this function

with_body(response, body)

View Source
@spec with_body(t(), binary()) :: t()

Adds a body to the response and sets Content-Length header

  iex> Response.with_body(Response.new(200), "Hello World")
  %Response{version: "1.0", status: 200, headers: [{"Content-Length", "11"}], body: "Hello World"}
Link to this function

with_header(request, name, value)

View Source
@spec with_header(t(), binary(), binary()) :: t()

Attaches a header to a RTSP response struct.

  iex> Response.with_header(Response.new(200), "header_name", "header_value")
  %Response{version: "1.0", status: 200, headers: [{"header_name","header_value"}]}