Skip to content

Commit c2938fb

Browse files
committed
feat(header): add Connection::close() and ::keep_alive() constructors
1 parent a6dd9c8 commit c2938fb

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ use std::io::Read;
5656

5757
use hyper::Client;
5858
use hyper::header::Connection;
59-
use hyper::header::ConnectionOption;
6059

6160
fn main() {
6261
// Create a client.
@@ -65,7 +64,7 @@ fn main() {
6564
// Creating an outgoing request.
6665
let mut res = client.get("http://www.gooogle.com/")
6766
// set a header
68-
.header(Connection(vec![ConnectionOption::Close]))
67+
.header(Connection::close())
6968
// let 'er go!
7069
.send().unwrap();
7170

examples/client.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::io;
88

99
use hyper::Client;
1010
use hyper::header::Connection;
11-
use hyper::header::ConnectionOption::Close;
1211

1312
fn main() {
1413
env_logger::init().unwrap();
@@ -24,7 +23,7 @@ fn main() {
2423
let mut client = Client::new();
2524

2625
let mut res = client.get(&*url)
27-
.header(Connection(vec![Close]))
26+
.header(Connection::close())
2827
.send().unwrap();
2928

3029
println!("Response: {}", res.status);

src/header/common/connection.rs

+12
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ header! {
7171
}
7272
}
7373

74+
impl Connection {
75+
/// A constructor to easily create a `Connection: close` header.
76+
pub fn close() -> Connection {
77+
Connection(vec![ConnectionOption::Close])
78+
}
79+
80+
/// A constructor to easily create a `Connection: keep-alive` header.
81+
pub fn keep_alive() -> Connection {
82+
Connection(vec![ConnectionOption::KeepAlive])
83+
}
84+
}
85+
7486
bench_header!(close, Connection, { vec![b"close".to_vec()] });
7587
bench_header!(keep_alive, Connection, { vec![b"keep-alive".to_vec()] });
7688
bench_header!(header, Connection, { vec![b"authorization".to_vec()] });

0 commit comments

Comments
 (0)