-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow disabling default features for HTTP clients
By doing this, `pretend` users can specify the features they want.
- Loading branch information
1 parent
6d4be15
commit e4c9d2c
Showing
8 changed files
with
95 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,15 @@ description = "awc based client for pretend." | |
authors = ["Lucien XU <[email protected]>"] | ||
license = "MIT" | ||
homepage = "https://github.com/SfietKonstantin/pretend" | ||
documentation = "https://docs.rs/pretend-isahc/latest/pretend_awc/" | ||
documentation = "https://docs.rs/pretend-awc/latest/pretend_awc/" | ||
repository = "https://github.com/SfietKonstantin/pretend" | ||
keywords = ["http", "client", "web", "async", "declarative"] | ||
categories = ["web-programming::http-client"] | ||
readme = "README.md" | ||
|
||
[dependencies] | ||
pretend = { path = "../pretend", version = "0.2.0", features = ["local-error"] } | ||
awc = "2.0" | ||
awc = { version = "2", default-features = false } | ||
|
||
[features] | ||
default = ["awc/default"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,15 @@ description = "ureq based client for pretend." | |
authors = ["Lucien XU <[email protected]>"] | ||
license = "MIT" | ||
homepage = "https://github.com/SfietKonstantin/pretend" | ||
documentation = "https://docs.rs/pretend-reqwest/latest/pretend_ureq/" | ||
documentation = "https://docs.rs/pretend-ureq/latest/pretend_ureq/" | ||
repository = "https://github.com/SfietKonstantin/pretend" | ||
keywords = ["http", "client", "web", "async", "declarative"] | ||
keywords = ["http", "client", "web", "declarative"] | ||
categories = ["web-programming::http-client"] | ||
readme = "README.md" | ||
|
||
[dependencies] | ||
pretend = { path = "../pretend", version = "0.2.0" } | ||
ureq = "2.1" | ||
ureq = { version = "2", default-features = false } | ||
|
||
[features] | ||
default = ["ureq/default"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use pretend::{pretend, request, Pretend, Result, Url}; | ||
|
||
#[pretend] | ||
trait HttpBin { | ||
#[request(method = "GET", path = "/get")] | ||
async fn get(&self) -> Result<()>; | ||
} | ||
|
||
#[pretend] | ||
trait HttpBinSync { | ||
#[request(method = "GET", path = "/get")] | ||
fn get(&self) -> Result<()>; | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_reqwest_no_https_feature() { | ||
// With default-features = false | ||
// reqwest will not use any TLS crate, | ||
// and thus, cannot handle https calls | ||
|
||
let url = Url::parse("https://httpbin.org").unwrap(); | ||
let pretend = Pretend::for_client(pretend_reqwest::Client::default()).with_url(url); | ||
let result = pretend.get().await; | ||
|
||
let error = anyhow::Error::from(result.unwrap_err()); | ||
assert!(format!("{:?}", error).contains("scheme is not http")); | ||
} | ||
|
||
#[test] | ||
fn test_ureq_no_https_feature() { | ||
// With default-features = false | ||
// ureq will not use any TLS crate, | ||
// and thus, cannot handle https calls | ||
|
||
let url = Url::parse("https://httpbin.org").unwrap(); | ||
let pretend = | ||
Pretend::for_client(pretend_ureq::Client::new(pretend_ureq::ureq::agent())).with_url(url); | ||
let result = pretend.get(); | ||
|
||
let error = anyhow::Error::from(result.unwrap_err()); | ||
assert!(format!("{:?}", error).contains("ureq was build without HTTP support")); | ||
} |