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

feat: set user agent in webdav requests #2284

Merged
merged 14 commits into from
Dec 3, 2024
12 changes: 11 additions & 1 deletion src/cache/webdav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

use crate::errors::*;
use opendal::layers::LoggingLayer;
use opendal::raw::HttpClient;
use opendal::services::Webdav;
use opendal::Operator;
use reqwest::ClientBuilder;

/// A cache that stores entries in a Webdav.
pub struct WebdavCache;
Expand All @@ -32,11 +34,19 @@ impl WebdavCache {
.root(key_prefix)
.username(username.unwrap_or_default())
.password(password.unwrap_or_default())
.token(token.unwrap_or_default());
.token(token.unwrap_or_default())
.http_client(set_user_agent());

let op = Operator::new(builder)?
.layer(LoggingLayer::default())
.finish();
Ok(op)
}
}

/// Set the user agent (helps with monitoring on the server side)
fn set_user_agent() -> HttpClient {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall that we already have similar code that builds an HTTP client. Would you like to check the codebase again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! I've removed the copied code and referenced set_user_agent from src/cache/s3.rs.

let user_agent = format!("{}/{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
let client_builder = ClientBuilder::new().user_agent(user_agent);
HttpClient::build(client_builder).unwrap()
}
Loading