feat(header): add Connection::close() and ::keep_alive() constructors
This commit is contained in:
@@ -56,7 +56,6 @@ use std::io::Read;
|
||||
|
||||
use hyper::Client;
|
||||
use hyper::header::Connection;
|
||||
use hyper::header::ConnectionOption;
|
||||
|
||||
fn main() {
|
||||
// Create a client.
|
||||
@@ -65,7 +64,7 @@ fn main() {
|
||||
// Creating an outgoing request.
|
||||
let mut res = client.get("http://www.gooogle.com/")
|
||||
// set a header
|
||||
.header(Connection(vec![ConnectionOption::Close]))
|
||||
.header(Connection::close())
|
||||
// let 'er go!
|
||||
.send().unwrap();
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ use std::io;
|
||||
|
||||
use hyper::Client;
|
||||
use hyper::header::Connection;
|
||||
use hyper::header::ConnectionOption::Close;
|
||||
|
||||
fn main() {
|
||||
env_logger::init().unwrap();
|
||||
@@ -24,7 +23,7 @@ fn main() {
|
||||
let mut client = Client::new();
|
||||
|
||||
let mut res = client.get(&*url)
|
||||
.header(Connection(vec![Close]))
|
||||
.header(Connection::close())
|
||||
.send().unwrap();
|
||||
|
||||
println!("Response: {}", res.status);
|
||||
|
||||
@@ -71,6 +71,18 @@ header! {
|
||||
}
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
/// A constructor to easily create a `Connection: close` header.
|
||||
pub fn close() -> Connection {
|
||||
Connection(vec![ConnectionOption::Close])
|
||||
}
|
||||
|
||||
/// A constructor to easily create a `Connection: keep-alive` header.
|
||||
pub fn keep_alive() -> Connection {
|
||||
Connection(vec![ConnectionOption::KeepAlive])
|
||||
}
|
||||
}
|
||||
|
||||
bench_header!(close, Connection, { vec![b"close".to_vec()] });
|
||||
bench_header!(keep_alive, Connection, { vec![b"keep-alive".to_vec()] });
|
||||
bench_header!(header, Connection, { vec![b"authorization".to_vec()] });
|
||||
|
||||
Reference in New Issue
Block a user