Add function to set hydrus user agent

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/3/head
trivernis 3 years ago
parent 5d25aceab5
commit cd5de8ee1c
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -13,7 +13,8 @@ use crate::api_core::adding_urls::{
}; };
use crate::api_core::common::{FileIdentifier, FileMetadataInfo, FileRecord, OptionalStringNumber}; use crate::api_core::common::{FileIdentifier, FileMetadataInfo, FileRecord, OptionalStringNumber};
use crate::api_core::managing_cookies_and_http_headers::{ use crate::api_core::managing_cookies_and_http_headers::{
GetCookies, GetCookiesResponse, SetCookies, SetCookiesRequest, GetCookies, GetCookiesResponse, SetCookies, SetCookiesRequest, SetUserAgent,
SetUserAgentRequest,
}; };
use crate::api_core::managing_pages::{ use crate::api_core::managing_pages::{
FocusPage, FocusPageRequest, GetPageInfo, GetPageInfoResponse, GetPages, GetPagesResponse, FocusPage, FocusPageRequest, GetPageInfo, GetPageInfoResponse, GetPages, GetPagesResponse,
@ -350,4 +351,14 @@ impl Client {
Ok(()) Ok(())
} }
/// Sets the user agent that is being used for every request hydrus starts
pub async fn set_user_agent<S: ToString>(&self, user_agent: S) -> Result<()> {
self.post::<SetUserAgent>(SetUserAgentRequest {
user_agent: user_agent.to_string(),
})
.await?;
Ok(())
}
} }

@ -83,3 +83,20 @@ impl CookieBuilder {
[self.name, self.value, self.domain, self.path, self.expires] [self.name, self.value, self.domain, self.path, self.expires]
} }
} }
#[derive(Clone, Debug, Serialize)]
pub struct SetUserAgentRequest {
#[serde(rename = "user-agent")]
pub user_agent: String,
}
pub struct SetUserAgent;
impl Endpoint for SetUserAgent {
type Request = SetUserAgentRequest;
type Response = ();
fn path() -> String {
String::from("manage_headers/set_user_agent")
}
}

@ -18,3 +18,12 @@ async fn it_sets_cookies_for_a_domain() {
.build(); .build();
client.set_cookies(vec![cookie]).await.unwrap(); client.set_cookies(vec![cookie]).await.unwrap();
} }
#[tokio::test]
async fn it_sets_the_user_agent() {
let client = common::get_client();
client
.set_user_agent("Mozilla/5.0 (compatible; Hydrus Client)")
.await
.unwrap();
}

Loading…
Cancel
Save