From abbe0ccb50718ec52699c75035ede1b48c04a655 Mon Sep 17 00:00:00 2001 From: Tobias Mucke Date: Fri, 25 Oct 2019 23:38:05 +0200 Subject: [PATCH] Adopt and update to reqwest 0.9.x mainly to support actual OpenSSL versions. --- .gitignore | 5 ++++- Cargo.toml | 52 ++++++++++++++++++++++++------------------------- src/client.rs | 31 +++++++++++++++-------------- src/database.rs | 20 +++++++++---------- 4 files changed, 56 insertions(+), 52 deletions(-) diff --git a/.gitignore b/.gitignore index 058002c..a553249 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,7 @@ Cargo.lock **/*.rs.bk -# End of https://www.gitignore.io/api/rust \ No newline at end of file +# End of https://www.gitignore.io/api/rust + +# Exclude Intellij IDEA project config +/.idea/ diff --git a/Cargo.toml b/Cargo.toml index 82a20fa..967b56f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,26 +1,26 @@ -[package] -name = "sofa" -version = "0.6.0" -authors = ["Mathieu Amiot "] -license = "MIT/Apache-2.0" -description = "Sofa - CouchDB for Rust" -readme = "README.md" -documentation = "https://docs.rs/sofa" -homepage = "https://github.com/YellowInnovation/sofa" -repository = "https://github.com/YellowInnovation/sofa" -keywords = ["couchdb", "orm", "database", "nosql"] -categories = ["database"] -include = [ - "**/*.rs", - "Cargo.toml" -] - -[dependencies] -failure = "0.1" -serde = "1.0" -serde_derive = "1.0" -serde_json = "1.0" -reqwest = "0.8" - -[dev-dependencies] -pretty_assertions = "0.5" +[package] +name = "sofa" +version = "0.6.1" +authors = ["Mathieu Amiot "] +license = "MIT/Apache-2.0" +description = "Sofa - CouchDB for Rust" +readme = "README.md" +documentation = "https://docs.rs/sofa" +homepage = "https://github.com/YellowInnovation/sofa" +repository = "https://github.com/YellowInnovation/sofa" +keywords = ["couchdb", "orm", "database", "nosql"] +categories = ["database"] +include = [ + "**/*.rs", + "Cargo.toml" +] + +[dependencies] +failure = "0.1" +serde = "1.0" +serde_derive = "1.0" +serde_json = "1.0" +reqwest = "^0.9" + +[dev-dependencies] +pretty_assertions = "0.5" diff --git a/src/client.rs b/src/client.rs index 7c21680..88a9dd4 100644 --- a/src/client.rs +++ b/src/client.rs @@ -4,6 +4,7 @@ use failure::Error; use serde_json::from_reader; use reqwest::{self, Url, Method, RequestBuilder, StatusCode}; +use reqwest::header::{HeaderMap, HeaderValue, CONTENT_TYPE, REFERER}; use ::database::*; use ::types::*; @@ -94,11 +95,11 @@ impl Client { let path = self.create_path(name, None)?; let head_response = self._client.head(&path) - .header(reqwest::header::ContentType::json()) + .header(CONTENT_TYPE, HeaderValue::from_static("application/json")) .send()?; match head_response.status() { - StatusCode::Ok => Ok(db), + StatusCode::OK => Ok(db), _ => self.make_db(dbname), } } @@ -111,7 +112,7 @@ impl Client { let path = self.create_path(name, None)?; let put_response = self._client.put(&path) - .header(reqwest::header::ContentType::json()) + .header(CONTENT_TYPE, HeaderValue::from_static("application/json")) .send()?; let s: CouchResponse = from_reader(put_response)?; @@ -128,7 +129,7 @@ impl Client { pub fn destroy_db(&self, dbname: &'static str) -> Result { let path = self.create_path(self.build_dbname(dbname), None)?; let response = self._client.delete(&path) - .header(reqwest::header::ContentType::json()) + .header(CONTENT_TYPE, HeaderValue::from_static("application/json")) .send()?; let s: CouchResponse = from_reader(response)?; @@ -138,7 +139,7 @@ impl Client { pub fn check_status(&self) -> Result { let response = self._client.get(&self.uri) - .header(reqwest::header::ContentType::json()) + .header(CONTENT_TYPE, HeaderValue::from_static("application/json")) .send()?; let status = from_reader(response)?; @@ -168,34 +169,34 @@ impl Client { opts: Option> ) -> Result { let uri = self.create_path(path, opts)?; - let mut req = self._client.request(method, &uri); - req.header(reqwest::header::Referer::new(uri.clone())); - req.header(reqwest::header::ContentType::json()); + let mut headers = HeaderMap::new(); + headers.insert(REFERER, HeaderValue::from_str(uri.as_str())?); + headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json")); + + let req = self._client.request(method, &uri).headers(headers); Ok(req) } pub fn get(&self, path: String, args: Option>) -> Result { - Ok(self.req(Method::Get, path, args)?) + Ok(self.req(Method::GET, path, args)?) } pub fn post(&self, path: String, body: String) -> Result { - let mut req = self.req(Method::Post, path, None)?; - req.body(body); + let req = self.req(Method::POST, path, None)?.body(body); Ok(req) } pub fn put(&self, path: String, body: String) -> Result { - let mut req = self.req(Method::Put, path, None)?; - req.body(body); + let req = self.req(Method::PUT, path, None)?.body(body); Ok(req) } pub fn head(&self, path: String, args: Option>) -> Result { - Ok(self.req(Method::Head, path, args)?) + Ok(self.req(Method::HEAD, path, args)?) } pub fn delete(&self, path: String, args: Option>) -> Result { - Ok(self.req(Method::Delete, path, args)?) + Ok(self.req(Method::DELETE, path, args)?) } } diff --git a/src/database.rs b/src/database.rs index bb482b0..60b5e2a 100644 --- a/src/database.rs +++ b/src/database.rs @@ -57,9 +57,9 @@ impl Database { let request = self._client.post(path, "".into()); request - .and_then(|mut req| { + .and_then(|req| { Ok(req.send() - .and_then(|res| Ok(res.status() == StatusCode::Accepted)) + .and_then(|res| Ok(res.status() == StatusCode::ACCEPTED)) .unwrap_or(false)) }) .unwrap_or(false) @@ -73,9 +73,9 @@ impl Database { let request = self._client.post(path, "".into()); request - .and_then(|mut req| { + .and_then(|req| { Ok(req.send() - .and_then(|res| Ok(res.status() == StatusCode::Accepted)) + .and_then(|res| Ok(res.status() == StatusCode::ACCEPTED)) .unwrap_or(false)) }) .unwrap_or(false) @@ -86,9 +86,9 @@ impl Database { let request = self._client.post(self.create_compact_path(index), "".into()); request - .and_then(|mut req| { + .and_then(|req| { Ok(req.send() - .and_then(|res| Ok(res.status() == StatusCode::Accepted)) + .and_then(|res| Ok(res.status() == StatusCode::ACCEPTED)) .unwrap_or(false)) }) .unwrap_or(false) @@ -99,11 +99,11 @@ impl Database { let request = self._client.head(self.create_document_path(id), None); request - .and_then(|mut req| { + .and_then(|req| { Ok(req.send() .and_then(|res| { Ok(match res.status() { - StatusCode::Ok | StatusCode::NotModified => true, + StatusCode::OK | StatusCode::NOT_MODIFIED => true, _ => false, }) }) @@ -266,11 +266,11 @@ impl Database { ); request - .and_then(|mut req| { + .and_then(|req| { Ok(req.send() .and_then(|res| { Ok(match res.status() { - StatusCode::Ok | StatusCode::Accepted => true, + StatusCode::OK | StatusCode::ACCEPTED => true, _ => false, }) })