diff --git a/Cargo.toml b/Cargo.toml index 9fd0787..1e5efb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,10 +13,11 @@ serde_with = { version = "^3.8", default-features = false, features = ["base64", serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" -reqwest = { version = "^0.12", default-features = false, features = ["json", "cookies", "multipart"] } +reqwest = { version = "^0.12", default-features = false, features = ["json", "multipart"] } +reqwest-middleware = { version = "^0.4", features = ["json", "multipart"] } [features] -default = ["native-tls"] +default = ["reqwest/cookies"] native-tls = ["reqwest/native-tls"] rustls-tls = ["reqwest/rustls-tls"] diff --git a/examples/cookies_load.rs b/examples/cookies_load.rs index ad8dbcc..0dc9d5e 100644 --- a/examples/cookies_load.rs +++ b/examples/cookies_load.rs @@ -23,7 +23,8 @@ async fn main() { config.client = reqwest::Client::builder() .cookie_provider(jar) .build() - .unwrap(); + .unwrap() + .into(); let user = ::vrchatapi::apis::authentication_api::get_current_user(&config) .await diff --git a/examples/cookies_store.rs b/examples/cookies_store.rs index 0ee12e3..863077b 100644 --- a/examples/cookies_store.rs +++ b/examples/cookies_store.rs @@ -11,7 +11,8 @@ async fn main() { config.client = reqwest::Client::builder() .cookie_provider(cookie_store.clone()) .build() - .unwrap(); + .unwrap() + .into(); match ::vrchatapi::apis::authentication_api::get_current_user(&config) .await diff --git a/generate.sh b/generate.sh index 7aad33f..3d11ae4 100755 --- a/generate.sh +++ b/generate.sh @@ -12,7 +12,7 @@ rm src/apis src/models docs -rf ./node_modules/\@openapitools/openapi-generator-cli/main.js generate \ -g rust \ ---additional-properties=packageName=vrchatapi,supportAsync=true,avoidBoxedModels=true \ +--additional-properties=packageName=vrchatapi,supportAsync=true,avoidBoxedModels=true,library=reqwest,reqwestDefaultFeatures=reqwest/cookies,supportMiddleware=true \ --git-user-id=vrchatapi \ --git-repo-id=vrchatapi-rust \ -o . \ @@ -34,7 +34,7 @@ find src -type f -exec sed -i '/^\s*\/\/\/\s*$/d' {} \; # Cookie storage sed -i 's/Client::new()/Client::builder().cookie_store(true).build().unwrap()/g' src/apis/configuration.rs -sed -i 's/, features = \["json", "multipart"\]/, features = \["json", "cookies", "multipart"\]/g' Cargo.toml +#sed -i 's/, features = \["json", "multipart"\]/, features = \["json", "cookies", "multipart"\]/g' Cargo.toml #Fix example printf "\n[dev-dependencies]\ntokio = { version = '1', features = ['macros', 'rt-multi-thread'] }" >> Cargo.toml diff --git a/src/apis/configuration.rs b/src/apis/configuration.rs index f61fe1d..9470d57 100644 --- a/src/apis/configuration.rs +++ b/src/apis/configuration.rs @@ -10,7 +10,7 @@ pub struct Configuration { pub base_path: String, pub user_agent: Option, - pub client: reqwest::Client, + pub client: reqwest_middleware::ClientWithMiddleware, pub basic_auth: Option, pub oauth_access_token: Option, pub bearer_access_token: Option, @@ -36,10 +36,13 @@ impl Default for Configuration { Configuration { base_path: "https://api.vrchat.cloud/api/1".to_owned(), user_agent: Some("vrchatapi-rust".to_owned()), - client: reqwest::Client::builder() - .cookie_store(true) - .build() - .unwrap(), + client: reqwest_middleware::ClientBuilder::new( + reqwest::Client::builder() + .cookie_store(true) + .build() + .unwrap(), + ) + .build(), basic_auth: None, oauth_access_token: None, bearer_access_token: None, diff --git a/src/apis/mod.rs b/src/apis/mod.rs index 23faf1a..4b02c74 100644 --- a/src/apis/mod.rs +++ b/src/apis/mod.rs @@ -11,6 +11,7 @@ pub struct ResponseContent { #[derive(Debug)] pub enum Error { Reqwest(reqwest::Error), + ReqwestMiddleware(reqwest_middleware::Error), Serde(serde_json::Error), Io(std::io::Error), ResponseError(ResponseContent), @@ -20,6 +21,7 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let (module, e) = match self { Error::Reqwest(e) => ("reqwest", e.to_string()), + Error::ReqwestMiddleware(e) => ("reqwest-middleware", e.to_string()), Error::Serde(e) => ("serde", e.to_string()), Error::Io(e) => ("IO", e.to_string()), Error::ResponseError(e) => ("response", format!("status code {}", e.status)), @@ -32,6 +34,7 @@ impl error::Error for Error { fn source(&self) -> Option<&(dyn error::Error + 'static)> { Some(match self { Error::Reqwest(e) => e, + Error::ReqwestMiddleware(e) => e, Error::Serde(e) => e, Error::Io(e) => e, Error::ResponseError(_) => return None, @@ -45,6 +48,12 @@ impl From for Error { } } +impl From for Error { + fn from(e: reqwest_middleware::Error) -> Self { + Error::ReqwestMiddleware(e) + } +} + impl From for Error { fn from(e: serde_json::Error) -> Self { Error::Serde(e)