From 90f8cf7eb2a814593e7650d19623150bba0e8b3f Mon Sep 17 00:00:00 2001 From: Billal GHILAS Date: Sun, 18 Feb 2024 20:51:42 +0100 Subject: [PATCH] Add request body --- lib/membrane_rtsp/request.ex | 5 ++++- lib/membrane_rtsp/session/logic.ex | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/membrane_rtsp/request.ex b/lib/membrane_rtsp/request.ex index 228b596..9ff81d2 100644 --- a/lib/membrane_rtsp/request.ex +++ b/lib/membrane_rtsp/request.ex @@ -69,6 +69,8 @@ defmodule Membrane.RTSP.Request do "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" ``` @@ -89,7 +91,8 @@ defmodule Membrane.RTSP.Request do process_uri(request, uri), " RTSP/1.0", render_headers(headers), - "\r\n\r\n" + "\r\n\r\n", + request.body ]) end diff --git a/lib/membrane_rtsp/session/logic.ex b/lib/membrane_rtsp/session/logic.ex index d1a8a86..2b2463e 100644 --- a/lib/membrane_rtsp/session/logic.ex +++ b/lib/membrane_rtsp/session/logic.ex @@ -50,6 +50,7 @@ defmodule Membrane.RTSP.Logic do request |> inject_session_header(session_id) + |> inject_content_length() |> Request.with_header("CSeq", cseq |> to_string()) |> Request.with_header("User-Agent", @user_agent) |> apply_credentials(uri, state.auth) @@ -65,6 +66,14 @@ defmodule Membrane.RTSP.Logic do end end + @spec inject_content_length(Request.t()) :: Request.t() + def inject_content_length(request) do + case request.body do + "" -> request + body -> Request.with_header(request, "Content-Length", to_string(byte_size(body))) + end + end + @spec apply_credentials(Request.t(), URI.t(), State.auth_t()) :: Request.t() def apply_credentials(request, %URI{userinfo: nil}, _auth_options), do: request