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/1335>
This commit is contained in:
Sean DuBois 2023-09-26 19:17:29 +00:00
parent ed4181617a
commit 90e06dc37b
2 changed files with 24 additions and 14 deletions

View file

@ -748,7 +748,7 @@ impl WhepSrc {
redirect_url.as_str() redirect_url.as_str()
); );
self.do_post(sess_desc).await self.do_post(sess_desc, redirect_url).await
} }
Err(e) => self.raise_error(gst::ResourceError::Failed, e.to_string()), Err(e) => self.raise_error(gst::ResourceError::Failed, e.to_string()),
} }
@ -918,26 +918,29 @@ impl WhepSrc {
let sess_desc = WebRTCSessionDescription::new(WebRTCSDPType::Offer, offer_sdp.sdp()); let sess_desc = WebRTCSessionDescription::new(WebRTCSDPType::Offer, offer_sdp.sdp());
let timeout; let timeout;
let endpoint;
{ {
let settings = self.settings.lock().unwrap(); let settings = self.settings.lock().unwrap();
timeout = settings.timeout; timeout = settings.timeout;
endpoint =
reqwest::Url::parse(settings.whep_endpoint.as_ref().unwrap().as_str()).unwrap();
drop(settings); 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); self.handle_future_error(e);
} }
} }
#[async_recursion] #[async_recursion]
async fn do_post(&self, offer: WebRTCSessionDescription) { async fn do_post(&self, offer: WebRTCSessionDescription, endpoint: reqwest::Url) {
let auth_token; let auth_token;
let endpoint;
{ {
let settings = self.settings.lock().unwrap(); 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(); auth_token = settings.auth_token.clone();
drop(settings); drop(settings);
} }

View file

@ -343,8 +343,12 @@ impl ObjectImpl for WhipSink {
obj.set_suppressed_flags(gst::ElementFlags::SINK | gst::ElementFlags::SOURCE); obj.set_suppressed_flags(gst::ElementFlags::SINK | gst::ElementFlags::SOURCE);
obj.set_element_flags(gst::ElementFlags::SINK); obj.set_element_flags(gst::ElementFlags::SINK);
gst::warning!(CAT, imp: self, "whipsink will be deprecated in the future, \ gst::warning!(
it is recommended that whipclientsink be used instead"); CAT,
imp: self,
"whipsink will be deprecated in the future, \
it is recommended that whipclientsink be used instead"
);
// The spec requires all m= lines to be bundled (section 4.2) // The spec requires all m= lines to be bundled (section 4.2)
self.webrtcbin self.webrtcbin
@ -553,26 +557,29 @@ impl WhipSink {
); );
let timeout; let timeout;
let endpoint;
{ {
let settings = self.settings.lock().unwrap(); let settings = self.settings.lock().unwrap();
timeout = settings.timeout; timeout = settings.timeout;
endpoint =
reqwest::Url::parse(settings.whip_endpoint.as_ref().unwrap().as_str()).unwrap();
drop(settings); 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); self.handle_future_error(e);
} }
} }
#[async_recursion] #[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 auth_token;
let endpoint;
{ {
let settings = self.settings.lock().unwrap(); 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(); auth_token = settings.auth_token.clone();
drop(settings); drop(settings);
} }
@ -777,7 +784,7 @@ impl WhipSink {
redirect_url.as_str() redirect_url.as_str()
); );
self.do_post(offer).await self.do_post(offer, redirect_url).await
} }
Err(e) => self.raise_error(gst::ResourceError::Failed, e.to_string()), Err(e) => self.raise_error(gst::ResourceError::Failed, e.to_string()),
} }