Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send the request body when provided #34

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/membrane_rtsp/request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"

```

Expand All @@ -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

Expand Down
9 changes: 9 additions & 0 deletions lib/membrane_rtsp/session/logic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
Loading