net: webrtc/webrtchttp: Respect HTTP redirects

Properly follow redirect URL. Before new request would be made, but with
original URL again.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1387>
This commit is contained in:
Sean DuBois 2023-09-26 19:17:29 +00:00 committed by Sebastian Dröge
parent d2e5cb43cc
commit 2aacc74a44
2 changed files with 18 additions and 20 deletions

View file

@ -755,11 +755,7 @@ impl WhepSrc {
redirect_url.as_str()
);
if let Err(err) =
wait_async(&self.canceller, self.do_post(sess_desc), timeout).await
{
self.handle_future_error(err);
}
self.do_post(sess_desc, redirect_url).await
}
Err(e) => self.raise_error(gst::ResourceError::Failed, e.to_string()),
}
@ -931,27 +927,30 @@ impl WhepSrc {
let sess_desc = WebRTCSessionDescription::new(WebRTCSDPType::Offer, offer_sdp.sdp());
let timeout;
let endpoint;
{
let settings = self.settings.lock().unwrap();
timeout = settings.timeout;
endpoint =
reqwest::Url::parse(settings.whep_endpoint.as_ref().unwrap().as_str()).unwrap();
drop(settings);
}
if let Err(e) = wait_async(&self.canceller, self.do_post(sess_desc), timeout).await {
if let Err(e) =
wait_async(&self.canceller, self.do_post(sess_desc, endpoint), timeout).await
{
self.handle_future_error(e);
}
}
#[async_recursion]
async fn do_post(&self, offer: WebRTCSessionDescription) {
async fn do_post(&self, offer: WebRTCSessionDescription, endpoint: reqwest::Url) {
let auth_token;
let endpoint;
let timeout;
{
let settings = self.settings.lock().unwrap();
endpoint =
reqwest::Url::parse(settings.whep_endpoint.as_ref().unwrap().as_str()).unwrap();
auth_token = settings.auth_token.clone();
timeout = settings.timeout;
drop(settings);

View file

@ -546,27 +546,30 @@ impl WhipSink {
);
let timeout;
let endpoint;
{
let settings = self.settings.lock().unwrap();
timeout = settings.timeout;
endpoint =
reqwest::Url::parse(settings.whip_endpoint.as_ref().unwrap().as_str()).unwrap();
drop(settings);
}
if let Err(e) = wait_async(&self.canceller, self.do_post(offer_sdp), timeout).await {
if let Err(e) =
wait_async(&self.canceller, self.do_post(offer_sdp, endpoint), timeout).await
{
self.handle_future_error(e);
}
}
#[async_recursion]
async fn do_post(&self, offer: gst_webrtc::WebRTCSessionDescription) {
async fn do_post(&self, offer: gst_webrtc::WebRTCSessionDescription, endpoint: reqwest::Url) {
let auth_token;
let endpoint;
let timeout;
{
let settings = self.settings.lock().unwrap();
endpoint =
reqwest::Url::parse(settings.whip_endpoint.as_ref().unwrap().as_str()).unwrap();
auth_token = settings.auth_token.clone();
timeout = settings.timeout;
drop(settings);
@ -794,11 +797,7 @@ impl WhipSink {
redirect_url.as_str()
);
if let Err(err) =
wait_async(&self.canceller, self.do_post(offer), timeout).await
{
self.handle_future_error(err);
}
self.do_post(offer, redirect_url).await
}
Err(e) => self.raise_error(gst::ResourceError::Failed, e.to_string()),
}