Skip to content

Commit c5c2985

Browse files
authored
Merge pull request #67 from jayjamesjay/v0.12
V0.12
2 parents 6c91c2e + e706672 commit c5c2985

File tree

12 files changed

+497
-195
lines changed

12 files changed

+497
-195
lines changed

Cargo.lock

Lines changed: 40 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "http_req"
3-
version = "0.11.1"
3+
version = "0.12.0"
44
license = "MIT"
55
description = "simple and lightweight HTTP client with built-in HTTPS support"
66
repository = "https://github.com/jayjamesjay/http_req"

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# http_req
22
> [!CAUTION]
3-
> v0.11.0 introduces major changes to design of `RequestBuilder` and `Request`. Please review [documentation](https://docs.rs/http_req/0.11.0/http_req/) before migrating from previous versions.
3+
> v0.12.0 replaces `RequestBuilder` with `RequestMessage`. Please review [documentation](https://docs.rs/http_req/0.12.0/http_req/) before migrating from previous versions.
44
55
[![Rust](https://github.com/jayjamesjay/http_req/actions/workflows/rust.yml/badge.svg)](https://github.com/jayjamesjay/http_req/actions/workflows/rust.yml)
6-
[![Crates.io](https://img.shields.io/badge/crates.io-v0.11.1-orange.svg?longCache=true)](https://crates.io/crates/http_req)
7-
[![Docs.rs](https://docs.rs/http_req/badge.svg)](https://docs.rs/http_req/0.11.1/http_req/)
6+
[![Crates.io](https://img.shields.io/badge/crates.io-v0.12.0-orange.svg?longCache=true)](https://crates.io/crates/http_req)
7+
[![Docs.rs](https://docs.rs/http_req/badge.svg)](https://docs.rs/http_req/0.12.0/http_req/)
88

99
Simple and lightweight HTTP client with built-in HTTPS support.
10+
- HTTP and HTTPS via [rust-native-tls](https://github.com/sfackler/rust-native-tls) (or optionally [rus-tls](https://crates.io/crates/rustls))
11+
- Small binary size (less than 0.7 MB for basic GET request)
12+
- Minimal amount of dependencies
1013

1114
## Requirements
1215
http_req by default uses [rust-native-tls](https://github.com/sfackler/rust-native-tls),
@@ -32,7 +35,7 @@ Take a look at [more examples](https://github.com/jayjamesjay/http_req/tree/mast
3235
In order to use `http_req` with `rustls` in your project, add the following lines to `Cargo.toml`:
3336
```toml
3437
[dependencies]
35-
http_req = {version="^0.11", default-features = false, features = ["rust-tls"]}
38+
http_req = {version="^0.12", default-features = false, features = ["rust-tls"]}
3639
```
3740

3841
## License
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use http_req::{
2-
request::RequestBuilder,
2+
request::RequestMessage,
33
response::Response,
44
stream::{self, Stream},
55
uri::Uri,
@@ -19,12 +19,12 @@ fn main() {
1919
let mut body = Vec::new();
2020

2121
// Prepares a request message.
22-
let request_msg = RequestBuilder::new(&addr)
22+
let request_msg = RequestMessage::new(&addr)
2323
.header("Connection", "Close")
2424
.parse();
2525

2626
// Connects to a server. Uses information from `addr`.
27-
let mut stream = Stream::new(&addr, Some(Duration::from_secs(60))).unwrap();
27+
let mut stream = Stream::connect(&addr, Some(Duration::from_secs(60))).unwrap();
2828
stream = Stream::try_to_https(stream, &addr, None).unwrap();
2929

3030
// Makes a request to server. Sends the prepared message.

src/chunked.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fn is_ascii_space(b: u8) -> bool {
175175
}
176176
}
177177

178-
fn parse_hex_uint(data: Vec<u8>) -> Result<usize, &'static str> {
178+
fn parse_hex_uint<'a>(data: Vec<u8>) -> Result<usize, &'a str> {
179179
let mut n = 0usize;
180180
for (i, v) in data.iter().enumerate() {
181181
if i == 16 {

src/error.rs

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ impl fmt::Display for ParseErr {
2929
use self::ParseErr::*;
3030

3131
let err = match self {
32-
Utf8(_) => "invalid character",
33-
Int(_) => "cannot parse number",
34-
Invalid => "invalid value",
35-
Empty => "nothing to parse",
36-
StatusErr => "status line contains invalid values",
37-
HeadersErr => "headers contain invalid values",
38-
UriErr => "uri contains invalid characters",
32+
Utf8(_) => "Invalid character",
33+
Int(_) => "Cannot parse number",
34+
Invalid => "Invalid value",
35+
Empty => "Nothing to parse",
36+
StatusErr => "Status line contains invalid values",
37+
HeadersErr => "Headers contain invalid values",
38+
UriErr => "URI contains invalid characters",
3939
};
4040
write!(f, "ParseErr: {}", err)
4141
}
@@ -57,8 +57,9 @@ impl From<str::Utf8Error> for ParseErr {
5757
pub enum Error {
5858
IO(io::Error),
5959
Parse(ParseErr),
60-
Timeout(mpsc::RecvTimeoutError),
60+
Timeout,
6161
Tls,
62+
Thread,
6263
}
6364

6465
impl error::Error for Error {
@@ -68,8 +69,7 @@ impl error::Error for Error {
6869
match self {
6970
IO(e) => Some(e),
7071
Parse(e) => Some(e),
71-
Timeout(e) => Some(e),
72-
Tls => None,
72+
Timeout | Tls | Thread => None,
7373
}
7474
}
7575
}
@@ -81,27 +81,14 @@ impl fmt::Display for Error {
8181
let err = match self {
8282
IO(_) => "IO error",
8383
Parse(err) => return err.fmt(f),
84-
Timeout(_) => "Timeout error",
84+
Timeout => "Timeout error",
8585
Tls => "TLS error",
86+
Thread => "Thread communication error",
8687
};
8788
write!(f, "Error: {}", err)
8889
}
8990
}
9091

91-
#[cfg(feature = "native-tls")]
92-
impl From<native_tls::Error> for Error {
93-
fn from(_e: native_tls::Error) -> Self {
94-
Error::Tls
95-
}
96-
}
97-
98-
#[cfg(feature = "native-tls")]
99-
impl<T> From<native_tls::HandshakeError<T>> for Error {
100-
fn from(_e: native_tls::HandshakeError<T>) -> Self {
101-
Error::Tls
102-
}
103-
}
104-
10592
impl From<io::Error> for Error {
10693
fn from(e: io::Error) -> Self {
10794
Error::IO(e)
@@ -121,8 +108,8 @@ impl From<str::Utf8Error> for Error {
121108
}
122109

123110
impl From<mpsc::RecvTimeoutError> for Error {
124-
fn from(e: mpsc::RecvTimeoutError) -> Self {
125-
Error::Timeout(e)
111+
fn from(_e: mpsc::RecvTimeoutError) -> Self {
112+
Error::Timeout
126113
}
127114
}
128115

@@ -132,3 +119,23 @@ impl From<rustls::Error> for Error {
132119
Error::Tls
133120
}
134121
}
122+
123+
#[cfg(feature = "native-tls")]
124+
impl From<native_tls::Error> for Error {
125+
fn from(_e: native_tls::Error) -> Self {
126+
Error::Tls
127+
}
128+
}
129+
130+
#[cfg(feature = "native-tls")]
131+
impl<T> From<native_tls::HandshakeError<T>> for Error {
132+
fn from(_e: native_tls::HandshakeError<T>) -> Self {
133+
Error::Tls
134+
}
135+
}
136+
137+
impl<T> From<mpsc::SendError<T>> for Error {
138+
fn from(_e: mpsc::SendError<T>) -> Self {
139+
Error::Thread
140+
}
141+
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Simple HTTP client with built-in HTTPS support.
2-
//!
2+
//!
33
//! By default uses [rust-native-tls](https://github.com/sfackler/rust-native-tls),
44
//! which relies on TLS framework provided by OS on Windows and macOS, and OpenSSL
55
//! on all other platforms. But it also supports [rus-tls](https://crates.io/crates/rustls).

0 commit comments

Comments
 (0)