-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sending headers through request
- Loading branch information
Showing
9 changed files
with
161 additions
and
57 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
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#[allow(clippy::module_inception)] | ||
pub mod collection; | ||
pub mod header_map; | ||
pub mod types; | ||
pub use types::Collection; | ||
mod errors; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod request_client; | ||
pub mod request_manager; | ||
pub mod request_strategies; | ||
pub mod response_decoders; | ||
|
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,61 @@ | ||
use crate::collection::types::Request; | ||
|
||
#[derive(Debug)] | ||
pub struct RequestClient { | ||
client: reqwest::Client, | ||
} | ||
|
||
impl RequestClient { | ||
pub fn new() -> Self { | ||
RequestClient { | ||
client: reqwest::Client::new(), | ||
} | ||
} | ||
|
||
pub fn get(&self, request: &Request) -> reqwest::RequestBuilder { | ||
let request_builder = self.client.get(&request.uri); | ||
self.append_headers(request, request_builder) | ||
} | ||
|
||
pub fn post(&self, request: &Request) -> reqwest::RequestBuilder { | ||
let request_builder = self.client.post(&request.uri); | ||
self.append_headers(request, request_builder) | ||
} | ||
|
||
pub fn put(&self, request: &Request) -> reqwest::RequestBuilder { | ||
let request_builder = self.client.put(&request.uri); | ||
self.append_headers(request, request_builder) | ||
} | ||
|
||
pub fn patch(&self, request: &Request) -> reqwest::RequestBuilder { | ||
let request_builder = self.client.patch(&request.uri); | ||
self.append_headers(request, request_builder) | ||
} | ||
|
||
pub fn delete(&self, request: &Request) -> reqwest::RequestBuilder { | ||
let request_builder = self.client.delete(&request.uri); | ||
self.append_headers(request, request_builder) | ||
} | ||
|
||
fn append_headers( | ||
&self, | ||
request: &Request, | ||
mut request_builder: reqwest::RequestBuilder, | ||
) -> reqwest::RequestBuilder { | ||
if let Some(ref headers) = request.headers { | ||
for header in headers.iter().filter(|header| header.enabled) { | ||
let header_name = header.pair.0.clone(); | ||
let header_value = header.pair.1.clone(); | ||
request_builder = request_builder.header(header_name, header_value); | ||
} | ||
} | ||
|
||
request_builder | ||
} | ||
} | ||
|
||
impl Default for RequestClient { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} |
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