Skip to content

Commit

Permalink
fix(server): use provided executor if fallback to HTTP2
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Sep 18, 2018
1 parent 8f91747 commit 1370a6f
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/server/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,23 @@ where
S::ResBody,
>,
>>,
fallback: bool,
fallback: Fallback,
}

#[derive(Clone, Debug)]
enum Fallback {
ToHttp2(Exec),
Http1Only,
}

impl Fallback {
fn to_h2(&self) -> bool {
match *self {
Fallback::ToHttp2(_) => true,
Fallback::Http1Only => false,
}
}
}

/// Deconstructed parts of a `Connection`.
///
Expand Down Expand Up @@ -305,7 +318,11 @@ impl Http {

Connection {
conn: Some(either),
fallback: self.mode == ConnectionMode::Fallback,
fallback: if self.mode == ConnectionMode::Fallback {
Fallback::ToHttp2(self.exec.clone())
} else {
Fallback::Http1Only
},
}
}

Expand Down Expand Up @@ -442,7 +459,7 @@ where
Err(e) => {
debug!("error polling connection protocol without shutdown: {}", e);
match *e.kind() {
Kind::Parse(Parse::VersionH2) if self.fallback => {
Kind::Parse(Parse::VersionH2) if self.fallback.to_h2() => {
self.upgrade_h2();
continue;
}
Expand All @@ -467,7 +484,11 @@ where
};
let mut rewind_io = Rewind::new(io);
rewind_io.rewind(read_buf);
let h2 = proto::h2::Server::new(rewind_io, dispatch.into_service(), Exec::Default);
let exec = match self.fallback {
Fallback::ToHttp2(ref exec) => exec.clone(),
Fallback::Http1Only => unreachable!("upgrade_h2 with Fallback::Http1Only"),
};
let h2 = proto::h2::Server::new(rewind_io, dispatch.into_service(), exec);

debug_assert!(self.conn.is_none());
self.conn = Some(Either::B(h2));
Expand Down Expand Up @@ -512,7 +533,7 @@ where
Err(e) => {
debug!("error polling connection protocol: {}", e);
match *e.kind() {
Kind::Parse(Parse::VersionH2) if self.fallback => {
Kind::Parse(Parse::VersionH2) if self.fallback.to_h2() => {
self.upgrade_h2();
continue;
}
Expand Down Expand Up @@ -717,7 +738,7 @@ mod upgrades {
Err(e) => {
debug!("error polling connection protocol: {}", e);
match *e.kind() {
Kind::Parse(Parse::VersionH2) if self.inner.fallback => {
Kind::Parse(Parse::VersionH2) if self.inner.fallback.to_h2() => {
self.inner.upgrade_h2();
continue;
}
Expand Down

0 comments on commit 1370a6f

Please sign in to comment.