Skip to content

Commit 62e47e3

Browse files
committed
improve RequestMessage, pass uri to RedirectPolicy
1 parent c5c2985 commit 62e47e3

File tree

9 files changed

+120
-101
lines changed

9 files changed

+120
-101
lines changed

Cargo.lock

Lines changed: 11 additions & 11 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.12.0"
3+
version = "0.13.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: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
# http_req
2-
> [!CAUTION]
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.
42

53
[![Rust](https://github.com/jayjamesjay/http_req/actions/workflows/rust.yml/badge.svg)](https://github.com/jayjamesjay/http_req/actions/workflows/rust.yml)
64
[![Crates.io](https://img.shields.io/badge/crates.io-v0.12.0-orange.svg?longCache=true)](https://crates.io/crates/http_req)
75
[![Docs.rs](https://docs.rs/http_req/badge.svg)](https://docs.rs/http_req/0.12.0/http_req/)
86

97
Simple and lightweight HTTP client with built-in HTTPS support.
8+
109
- 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)
10+
- Small binary size (0.7 MB for basic GET request in default configuration)
1211
- Minimal amount of dependencies
1312

1413
## Requirements
14+
1515
http_req by default uses [rust-native-tls](https://github.com/sfackler/rust-native-tls),
1616
which relies on TLS framework provided by OS on Windows and macOS, and OpenSSL
1717
on all other platforms. But it also supports [rus-tls](https://crates.io/crates/rustls).
1818

1919
## Example
20+
2021
Basic HTTP GET request
22+
2123
```rust
2224
use http_req::request;
2325

@@ -31,12 +33,26 @@ fn main() {
3133

3234
Take a look at [more examples](https://github.com/jayjamesjay/http_req/tree/master/examples)
3335

34-
## How to use with `rustls`:
36+
## Usage
37+
38+
### Default configuration
39+
40+
In order to use `http_req` with default configuration, add the following lines to `Cargo.toml`:
41+
42+
```toml
43+
[dependencies]
44+
http_req = "^0.13"
45+
```
46+
47+
### Rustls
48+
3549
In order to use `http_req` with `rustls` in your project, add the following lines to `Cargo.toml`:
50+
3651
```toml
3752
[dependencies]
38-
http_req = {version="^0.12", default-features = false, features = ["rust-tls"]}
53+
http_req = { version="^0.13", default-features = false, features = ["rust-tls"] }
3954
```
4055

4156
## License
57+
4258
Licensed under [MIT](https://github.com/jayjamesjay/http_req/blob/master/LICENSE).

benches/bench.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,30 @@
22
extern crate http_req;
33
extern crate test;
44

5-
use http_req::{request::Request, response::Response, uri::Uri};
5+
use http_req::{request::RequestMessage, response::Response, uri::Uri};
66
use std::{convert::TryFrom, fs::File, io::Read};
77
use test::Bencher;
88

9+
const URI: &str = "https://www.rust-lang.org/";
10+
const BODY: [u8; 14] = [78, 97, 109, 101, 61, 74, 97, 109, 101, 115, 43, 74, 97, 121];
11+
12+
#[bench]
13+
fn parse_uri(b: &mut Bencher) {
14+
b.iter(|| Uri::try_from(URI));
15+
}
16+
17+
#[bench]
18+
fn parse_request(b: &mut Bencher) {
19+
let uri = Uri::try_from(URI).unwrap();
20+
21+
b.iter(|| {
22+
RequestMessage::new(&uri)
23+
.header("Accept", "*/*")
24+
.body(&BODY)
25+
.parse();
26+
});
27+
}
28+
929
#[bench]
1030
fn parse_response(b: &mut Bencher) {
1131
let mut content = Vec::new();
@@ -17,22 +37,3 @@ fn parse_response(b: &mut Bencher) {
1737
Response::try_from(&content, &mut body)
1838
});
1939
}
20-
21-
const URI: &str = "https://www.rust-lang.org/";
22-
23-
#[bench]
24-
fn request_send(b: &mut Bencher) {
25-
b.iter(|| {
26-
let uri = Uri::try_from(URI).unwrap();
27-
let mut writer = Vec::new();
28-
29-
let res = Request::new(&uri).send(&mut writer).unwrap();
30-
31-
res
32-
});
33-
}
34-
35-
#[bench]
36-
fn parse_uri(b: &mut Bencher) {
37-
b.iter(|| Uri::try_from(URI));
38-
}

0 commit comments

Comments
 (0)