-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from sleeyax/develop
- Loading branch information
Showing
31 changed files
with
527 additions
and
125 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use cronet_rs::client::{Body, Client}; | ||
|
||
fn main() { | ||
let client = Client::new(); | ||
|
||
println!("sending GET request..."); | ||
let request = http::Request::builder() | ||
.method("GET") | ||
.uri("https://httpbin.org/anything") | ||
.body(Body::default()) | ||
.unwrap(); | ||
let result = client.send(request); | ||
print_result(result); | ||
|
||
println!("sending POST request..."); | ||
let request = http::Request::builder() | ||
.method("POST") | ||
.uri("https://httpbin.org/anything") | ||
.header("content-type", "application/x-www-form-urlencoded") | ||
.body(Body::from("Hello, world")) | ||
.unwrap(); | ||
let result = client.send(request); | ||
print_result(result); | ||
} | ||
|
||
fn print_result(result: Result<http::Response<Body>, cronet_rs::client::ClientError>) { | ||
match result { | ||
Ok(response) => { | ||
println!("Status: {}", response.status()); | ||
println!("Headers: {:#?}", response.headers()); | ||
let body = response.body().as_bytes().unwrap(); | ||
println!("Body: {}", String::from_utf8_lossy(body)); | ||
} | ||
Err(error) => println!("Error: {}", error), | ||
} | ||
} |
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
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,38 @@ | ||
use core::fmt; | ||
|
||
use crate::{CronetError, EngineResult}; | ||
|
||
pub enum ClientError { | ||
/// Internal cronet error. | ||
CronetError(CronetError), | ||
/// The request was cancelled. | ||
CancellationError, | ||
/// Unexpected cronet engine result. | ||
EngineError(EngineResult), | ||
} | ||
|
||
impl From<CronetError> for ClientError { | ||
fn from(error: CronetError) -> Self { | ||
Self::CronetError(error) | ||
} | ||
} | ||
|
||
impl fmt::Display for ClientError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::CronetError(error) => write!(f, "{}", error), | ||
Self::CancellationError => write!(f, "Request was cancelled"), | ||
Self::EngineError(error) => write!(f, "Unexpected engine result: {:?}", error), | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Debug for ClientError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::CronetError(error) => write!(f, "{}", error), | ||
Self::CancellationError => write!(f, "Request was cancelled"), | ||
Self::EngineError(error) => write!(f, "Unexpected engine result: {:?}", error), | ||
} | ||
} | ||
} |
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,7 +1,12 @@ | ||
mod body; | ||
mod body_upload_provider; | ||
#[allow(clippy::module_inception)] | ||
mod client; | ||
mod error; | ||
mod response_handler; | ||
|
||
pub use body::*; | ||
pub use body_upload_provider::*; | ||
pub use client::*; | ||
pub use error::*; | ||
pub use response_handler::*; |
Oops, something went wrong.