From c4e51d3e8c1b4dfacf92e65a7afc44af5f696ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 2 Oct 2019 08:59:25 +0300 Subject: [PATCH] reqwesthttpsrc: Implement keep-alive property --- gst-plugin-reqwest/src/reqwesthttpsrc.rs | 29 ++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/gst-plugin-reqwest/src/reqwesthttpsrc.rs b/gst-plugin-reqwest/src/reqwesthttpsrc.rs index 408843b6..7716d7a8 100644 --- a/gst-plugin-reqwest/src/reqwesthttpsrc.rs +++ b/gst-plugin-reqwest/src/reqwesthttpsrc.rs @@ -40,6 +40,7 @@ const DEFAULT_IS_LIVE: bool = false; const DEFAULT_TIMEOUT: u32 = 15; const DEFAULT_COMPRESS: bool = false; const DEFAULT_IRADIO_MODE: bool = true; +const DEFAULT_KEEP_ALIVE: bool = true; #[derive(Debug, Clone)] struct Settings { @@ -52,6 +53,7 @@ struct Settings { extra_headers: Option, cookies: Vec, iradio_mode: bool, + keep_alive: bool, } impl Default for Settings { @@ -66,11 +68,12 @@ impl Default for Settings { extra_headers: None, cookies: Vec::new(), iradio_mode: DEFAULT_IRADIO_MODE, + keep_alive: DEFAULT_KEEP_ALIVE, } } } -static PROPERTIES: [subclass::Property; 10] = [ +static PROPERTIES: [subclass::Property; 11] = [ subclass::Property("location", |name| { glib::ParamSpec::string( name, @@ -163,6 +166,15 @@ static PROPERTIES: [subclass::Property; 10] = [ glib::ParamFlags::READWRITE, ) }), + subclass::Property("keep-alive", |name| { + glib::ParamSpec::boolean( + name, + "Keep Alive", + "Use HTTP persistent connections", + DEFAULT_KEEP_ALIVE, + glib::ParamFlags::READWRITE, + ) + }), ]; const REQWEST_CLIENT_CONTEXT: &str = "gst.request.client"; @@ -349,7 +361,11 @@ impl ReqwestHttpSrc { let mut headers = Headers::new(); - headers.set(Connection::keep_alive()); + if settings.keep_alive { + headers.set(Connection::keep_alive()); + } else { + headers.set(Connection::close()); + } match (start != 0, stop) { (false, None) => (), @@ -710,6 +726,11 @@ impl ObjectImpl for ReqwestHttpSrc { let iradio_mode = value.get_some().expect("type checked upstream"); settings.iradio_mode = iradio_mode; } + subclass::Property("keep-alive", ..) => { + let mut settings = self.settings.lock().unwrap(); + let keep_alive = value.get_some().expect("type checked upstream"); + settings.keep_alive = keep_alive; + } _ => unimplemented!(), }; } @@ -759,6 +780,10 @@ impl ObjectImpl for ReqwestHttpSrc { let settings = self.settings.lock().unwrap(); Ok(settings.iradio_mode.to_value()) } + subclass::Property("keep-alive", ..) => { + let settings = self.settings.lock().unwrap(); + Ok(settings.keep_alive.to_value()) + } _ => unimplemented!(), } }