Track HTTP crate

This commit is contained in:
Carl Lerche
2017-09-05 10:21:31 -07:00
parent b4fa5134f9
commit c2e6eb35d8
15 changed files with 50 additions and 48 deletions

View File

@@ -18,7 +18,7 @@ futures = "0.1"
tokio-io = "0.1.3" tokio-io = "0.1.3"
tokio-timer = "0.1" tokio-timer = "0.1"
bytes = "0.4" bytes = "0.4"
http = { git = "https://github.com/carllerche/http", rev = "2dd15d9" } http = { git = "https://github.com/carllerche/http" }
byteorder = "1.0" byteorder = "1.0"
log = "0.3.8" log = "0.3.8"
fnv = "1.0.5" fnv = "1.0.5"

View File

@@ -10,7 +10,7 @@ extern crate env_logger;
use h2::client::Client; use h2::client::Client;
use http::{method, Request}; use http::{Request, Method};
use futures::*; use futures::*;
use tokio_core::reactor; use tokio_core::reactor;
@@ -65,7 +65,7 @@ pub fn main() {
let mut h2 = res.unwrap(); let mut h2 = res.unwrap();
let request = Request::builder() let request = Request::builder()
.method(method::GET) .method(Method::GET)
.uri("https://http2.akamai.com/") .uri("https://http2.akamai.com/")
.body(()).unwrap(); .body(()).unwrap();

View File

@@ -38,7 +38,7 @@ pub fn main() {
println!("GOT request: {:?}", request); println!("GOT request: {:?}", request);
let response = Response::builder() let response = Response::builder()
.status(status::OK) .status(StatusCode::OK)
.body(()).unwrap(); .body(()).unwrap();
if let Err(e) = stream.send_response(response, false) { if let Err(e) = stream.send_response(response, false) {

View File

@@ -38,7 +38,7 @@ pub fn main() {
println!("GOT request: {:?}", request); println!("GOT request: {:?}", request);
let response = Response::builder() let response = Response::builder()
.status(status::OK) .status(StatusCode::OK)
.body(()).unwrap(); .body(()).unwrap();
if let Err(e) = stream.send_response(response, false) { if let Err(e) = stream.send_response(response, false) {

View File

@@ -1,7 +1,9 @@
use super::{huffman, Header}; use super::{huffman, Header};
use frame; use frame;
use http::{method, header, status}; use http::{header};
use http::method::{self, Method};
use http::status::{self, StatusCode};
use bytes::{Buf, Bytes, BytesMut}; use bytes::{Buf, Bytes, BytesMut};
use string::String; use string::String;
@@ -544,24 +546,24 @@ impl From<DecoderError> for frame::Error {
/// Get an entry from the static table /// Get an entry from the static table
pub fn get_static(idx: usize) -> Header { pub fn get_static(idx: usize) -> Header {
use http::{status, method, header}; use http::header;
use http::header::HeaderValue; use http::header::HeaderValue;
match idx { match idx {
1 => Header::Authority(from_static("")), 1 => Header::Authority(from_static("")),
2 => Header::Method(method::GET), 2 => Header::Method(Method::GET),
3 => Header::Method(method::POST), 3 => Header::Method(Method::POST),
4 => Header::Path(from_static("/")), 4 => Header::Path(from_static("/")),
5 => Header::Path(from_static("/index.html")), 5 => Header::Path(from_static("/index.html")),
6 => Header::Scheme(from_static("http")), 6 => Header::Scheme(from_static("http")),
7 => Header::Scheme(from_static("https")), 7 => Header::Scheme(from_static("https")),
8 => Header::Status(status::OK), 8 => Header::Status(StatusCode::OK),
9 => Header::Status(status::NO_CONTENT), 9 => Header::Status(StatusCode::NO_CONTENT),
10 => Header::Status(status::PARTIAL_CONTENT), 10 => Header::Status(StatusCode::PARTIAL_CONTENT),
11 => Header::Status(status::NOT_MODIFIED), 11 => Header::Status(StatusCode::NOT_MODIFIED),
12 => Header::Status(status::BAD_REQUEST), 12 => Header::Status(StatusCode::BAD_REQUEST),
13 => Header::Status(status::NOT_FOUND), 13 => Header::Status(StatusCode::NOT_FOUND),
14 => Header::Status(status::INTERNAL_SERVER_ERROR), 14 => Header::Status(StatusCode::INTERNAL_SERVER_ERROR),
15 => Header::Field { 15 => Header::Field {
name: header::ACCEPT_CHARSET, name: header::ACCEPT_CHARSET,
value: HeaderValue::from_static(""), value: HeaderValue::from_static(""),

View File

@@ -1,7 +1,8 @@
use super::Header; use super::Header;
use fnv::FnvHasher; use fnv::FnvHasher;
use http::{method, header}; use http::header;
use http::method::Method;
use std::{cmp, mem, usize}; use std::{cmp, mem, usize};
use std::collections::VecDeque; use std::collections::VecDeque;
@@ -721,8 +722,8 @@ fn index_static(header: &Header) -> Option<(usize, bool)> {
Header::Authority(_) => Some((1, false)), Header::Authority(_) => Some((1, false)),
Header::Method(ref v) => { Header::Method(ref v) => {
match *v { match *v {
method::GET => Some((2, true)), Method::GET => Some((2, true)),
method::POST => Some((3, true)), Method::POST => Some((3, true)),
_ => Some((2, false)), _ => Some((2, false)),
} }
} }

View File

@@ -176,8 +176,7 @@ impl Arbitrary for FuzzHpack {
} }
fn gen_header(g: &mut StdRng) -> Header<Option<HeaderName>> { fn gen_header(g: &mut StdRng) -> Header<Option<HeaderName>> {
use http::StatusCode; use http::{Method, StatusCode};
use http::method::{self, Method};
if g.gen_weighted_bool(10) { if g.gen_weighted_bool(10) {
match g.next_u32() % 5 { match g.next_u32() % 5 {
@@ -187,11 +186,11 @@ fn gen_header(g: &mut StdRng) -> Header<Option<HeaderName>> {
} }
1 => { 1 => {
let method = match g.next_u32() % 6 { let method = match g.next_u32() % 6 {
0 => method::GET, 0 => Method::GET,
1 => method::POST, 1 => Method::POST,
2 => method::PUT, 2 => Method::PUT,
3 => method::PATCH, 3 => Method::PATCH,
4 => method::DELETE, 4 => Method::DELETE,
5 => { 5 => {
let n: usize = g.gen_range(3, 7); let n: usize = g.gen_range(3, 7);
let bytes: Vec<u8> = (0..n).map(|_| { let bytes: Vec<u8> = (0..n).map(|_| {

View File

@@ -299,7 +299,7 @@ impl<B, P> Streams<B, P>
pub fn send_request(&mut self, request: Request<()>, end_of_stream: bool) pub fn send_request(&mut self, request: Request<()>, end_of_stream: bool)
-> Result<StreamRef<B, P>, SendError> -> Result<StreamRef<B, P>, SendError>
{ {
use http::method; use http::Method;
use super::stream::ContentLength; use super::stream::ContentLength;
// TODO: There is a hazard with assigning a stream ID before the // TODO: There is a hazard with assigning a stream ID before the
@@ -319,7 +319,7 @@ impl<B, P> Streams<B, P>
me.actions.send.init_window_sz(), me.actions.send.init_window_sz(),
me.actions.recv.init_window_sz()); me.actions.recv.init_window_sz());
if *request.method() == method::HEAD { if *request.method() == Method::HEAD {
stream.content_length = ContentLength::Head; stream.content_length = ContentLength::Head;
} }

View File

@@ -418,7 +418,7 @@ impl proto::Peer for Peer {
fn convert_poll_message(headers: frame::Headers) fn convert_poll_message(headers: frame::Headers)
-> Result<Self::Poll, RecvError> -> Result<Self::Poll, RecvError>
{ {
use http::{version, uri}; use http::{Version, uri};
let mut b = Request::builder(); let mut b = Request::builder();
@@ -434,7 +434,7 @@ impl proto::Peer for Peer {
} }
}; };
b.version(version::HTTP_2); b.version(Version::HTTP_2);
if let Some(method) = pseudo.method { if let Some(method) = pseudo.method {
b.method(method); b.method(method);

View File

@@ -30,7 +30,7 @@ fn send_data_without_requesting_capacity() {
.wait().unwrap(); .wait().unwrap();
let request = Request::builder() let request = Request::builder()
.method(method::POST) .method(Method::POST)
.uri("https://http2.akamai.com/") .uri("https://http2.akamai.com/")
.body(()).unwrap(); .body(()).unwrap();
@@ -44,7 +44,7 @@ fn send_data_without_requesting_capacity() {
// Get the response // Get the response
let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap(); let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap();
assert_eq!(resp.status(), status::NO_CONTENT); assert_eq!(resp.status(), StatusCode::NO_CONTENT);
h2.wait().unwrap(); h2.wait().unwrap();
} }

View File

@@ -28,7 +28,7 @@ fn single_stream_send_large_body() {
.wait().unwrap(); .wait().unwrap();
let request = Request::builder() let request = Request::builder()
.method(method::POST) .method(Method::POST)
.uri("https://http2.akamai.com/") .uri("https://http2.akamai.com/")
.body(()).unwrap(); .body(()).unwrap();
@@ -45,7 +45,7 @@ fn single_stream_send_large_body() {
// Get the response // Get the response
let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap(); let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap();
assert_eq!(resp.status(), status::NO_CONTENT); assert_eq!(resp.status(), StatusCode::NO_CONTENT);
h2.wait().unwrap(); h2.wait().unwrap();
} }
@@ -82,7 +82,7 @@ fn single_stream_send_extra_large_body_multi_frames_one_buffer() {
.wait().unwrap(); .wait().unwrap();
let request = Request::builder() let request = Request::builder()
.method(method::POST) .method(Method::POST)
.uri("https://http2.akamai.com/") .uri("https://http2.akamai.com/")
.body(()).unwrap(); .body(()).unwrap();
@@ -98,7 +98,7 @@ fn single_stream_send_extra_large_body_multi_frames_one_buffer() {
// Get the response // Get the response
let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap(); let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap();
assert_eq!(resp.status(), status::NO_CONTENT); assert_eq!(resp.status(), StatusCode::NO_CONTENT);
h2.wait().unwrap(); h2.wait().unwrap();
} }
@@ -147,7 +147,7 @@ fn single_stream_send_extra_large_body_multi_frames_multi_buffer() {
.wait().unwrap(); .wait().unwrap();
let request = Request::builder() let request = Request::builder()
.method(method::POST) .method(Method::POST)
.uri("https://http2.akamai.com/") .uri("https://http2.akamai.com/")
.body(()).unwrap(); .body(()).unwrap();
@@ -164,7 +164,7 @@ fn single_stream_send_extra_large_body_multi_frames_multi_buffer() {
// Get the response // Get the response
let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap(); let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap();
assert_eq!(resp.status(), status::NO_CONTENT); assert_eq!(resp.status(), StatusCode::NO_CONTENT);
h2.wait().unwrap(); h2.wait().unwrap();
} }

View File

@@ -32,7 +32,7 @@ fn send_recv_headers_only() {
let mut stream = h2.request(request, true).unwrap(); let mut stream = h2.request(request, true).unwrap();
let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap(); let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap();
assert_eq!(resp.status(), status::NO_CONTENT); assert_eq!(resp.status(), StatusCode::NO_CONTENT);
h2.wait().unwrap(); h2.wait().unwrap();
} }
@@ -66,7 +66,7 @@ fn send_recv_data() {
.wait().unwrap(); .wait().unwrap();
let request = Request::builder() let request = Request::builder()
.method(method::POST) .method(Method::POST)
.uri("https://http2.akamai.com/") .uri("https://http2.akamai.com/")
.body(()).unwrap(); .body(()).unwrap();
@@ -83,7 +83,7 @@ fn send_recv_data() {
// Get the response // Get the response
let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap(); let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap();
assert_eq!(resp.status(), status::OK); assert_eq!(resp.status(), StatusCode::OK);
// Take the body // Take the body
let (_, body) = resp.into_parts(); let (_, body) = resp.into_parts();
@@ -131,7 +131,7 @@ fn send_headers_recv_data_single_frame() {
let mut stream = h2.request(request, true).unwrap(); let mut stream = h2.request(request, true).unwrap();
let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap(); let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap();
assert_eq!(resp.status(), status::OK); assert_eq!(resp.status(), StatusCode::OK);
// Take the body // Take the body
let (_, body) = resp.into_parts(); let (_, body) = resp.into_parts();
@@ -169,7 +169,7 @@ fn send_data_after_headers_eos() {
// Send the request // Send the request
let mut request = request::Head::default(); let mut request = request::Head::default();
request.method = method::POST; request.method = Method::POST;
request.uri = "https://http2.akamai.com/".parse().unwrap(); request.uri = "https://http2.akamai.com/".parse().unwrap();
let id = 1.into(); let id = 1.into();

View File

@@ -7,7 +7,7 @@ authors = ["Carl Lerche <me@carllerche.com>"]
futures = "0.1" futures = "0.1"
tokio-io = "0.1" tokio-io = "0.1"
bytes = "0.4" bytes = "0.4"
http = { git = "https://github.com/carllerche/http", rev = "2dd15d9" } http = { git = "https://github.com/carllerche/http" }
env_logger = "0.4" env_logger = "0.4"
mock-io = { git = "https://github.com/carllerche/mock-io", branch = "experiments" } mock-io = { git = "https://github.com/carllerche/mock-io", branch = "experiments" }

View File

@@ -21,11 +21,11 @@ pub use self::futures::future::poll_fn;
pub use self::http::{ pub use self::http::{
request, request,
response, response,
method,
status,
Request, Request,
Response, Response,
Method,
HeaderMap, HeaderMap,
StatusCode,
}; };
pub use self::h2::*; pub use self::h2::*;

View File

@@ -35,7 +35,7 @@ fn recv_trailers_only() {
let mut stream = h2.request(request, true).unwrap(); let mut stream = h2.request(request, true).unwrap();
let response = h2.run(poll_fn(|| stream.poll_response())).unwrap(); let response = h2.run(poll_fn(|| stream.poll_response())).unwrap();
assert_eq!(response.status(), status::OK); assert_eq!(response.status(), StatusCode::OK);
let (_, mut body) = response.into_parts(); let (_, mut body) = response.into_parts();
@@ -88,7 +88,7 @@ fn send_trailers_immediately() {
stream.send_trailers(trailers).unwrap(); stream.send_trailers(trailers).unwrap();
let response = h2.run(poll_fn(|| stream.poll_response())).unwrap(); let response = h2.run(poll_fn(|| stream.poll_response())).unwrap();
assert_eq!(response.status(), status::OK); assert_eq!(response.status(), StatusCode::OK);
let (_, mut body) = response.into_parts(); let (_, mut body) = response.into_parts();