Skip to content

feat(http): add Expect 100-continue support #1040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/http/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl<I: Io, T: Http1Transaction, K: KeepAlive> Conn<I, T, K> {
}
};
self.state.busy();
let wants_continue = head.expecting_continue();
let wants_keep_alive = head.should_keep_alive();
self.state.keep_alive &= wants_keep_alive;
let (body, reading) = if decoder.is_eof() {
Expand All @@ -124,6 +125,10 @@ impl<I: Io, T: Http1Transaction, K: KeepAlive> Conn<I, T, K> {
(true, Reading::Body(decoder))
};
self.state.reading = reading;
if wants_continue {
self.state.reading = Reading::Init;
}

return Ok(Async::Ready(Some(Frame::Message { message: head, body: body })));
},
_ => {
Expand Down
16 changes: 15 additions & 1 deletion src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::borrow::Cow;
use std::fmt;

use header::{Connection, ConnectionOption};
use header::{Connection, ConnectionOption, Expect};
use header::Headers;
use method::Method;
use status::StatusCode;
Expand Down Expand Up @@ -68,6 +68,10 @@ impl<S> MessageHead<S> {
pub fn should_keep_alive(&self) -> bool {
should_keep_alive(self.version, &self.headers)
}

pub fn expecting_continue(&self) -> bool {
expecting_continue(self.version, &self.headers)
}
}

/// The raw status code and reason-phrase.
Expand Down Expand Up @@ -115,6 +119,16 @@ pub fn should_keep_alive(version: HttpVersion, headers: &Headers) -> bool {
ret
}

#[inline]
pub fn expecting_continue(version: HttpVersion, headers: &Headers) -> bool {
let ret = match (version, headers.get::<Expect>()) {
(Http11, Some(expect)) if expect == &Expect::Continue => true,
_ => false
};
trace!("expecting_continue(version={:?}, header={:?}) = {:?}", version, headers.get::<Expect>(), ret);
ret
}

#[derive(Debug)]
pub enum ServerTransaction {}

Expand Down