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

Adopt and update to reqwest 0.9.x mainly to support latest OpenSSL versions #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ Cargo.lock
**/*.rs.bk


# End of https://www.gitignore.io/api/rust
# End of https://www.gitignore.io/api/rust

# Exclude Intellij IDEA project config
/.idea/
52 changes: 26 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
[package]
name = "sofa"
version = "0.6.0"
authors = ["Mathieu Amiot <[email protected]>"]
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 <[email protected]>"]
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"
31 changes: 16 additions & 15 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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),
}
}
Expand All @@ -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)?;
Expand All @@ -128,7 +129,7 @@ impl Client {
pub fn destroy_db(&self, dbname: &'static str) -> Result<bool, Error> {
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)?;
Expand All @@ -138,7 +139,7 @@ impl Client {

pub fn check_status(&self) -> Result<CouchStatus, Error> {
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)?;
Expand Down Expand Up @@ -168,34 +169,34 @@ impl Client {
opts: Option<HashMap<String, String>>
) -> Result<RequestBuilder, Error> {
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<HashMap<String, String>>) -> Result<RequestBuilder, Error> {
Ok(self.req(Method::Get, path, args)?)
Ok(self.req(Method::GET, path, args)?)
}

pub fn post(&self, path: String, body: String) -> Result<RequestBuilder, Error> {
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<RequestBuilder, Error> {
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<HashMap<String, String>>) -> Result<RequestBuilder, Error> {
Ok(self.req(Method::Head, path, args)?)
Ok(self.req(Method::HEAD, path, args)?)
}

pub fn delete(&self, path: String, args: Option<HashMap<String, String>>) -> Result<RequestBuilder, Error> {
Ok(self.req(Method::Delete, path, args)?)
Ok(self.req(Method::DELETE, path, args)?)
}
}
20 changes: 10 additions & 10 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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,
})
})
Expand Down Expand Up @@ -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,
})
})
Expand Down