Skip to content

Commit 1370a6f

Browse files
committed
fix(server): use provided executor if fallback to HTTP2
1 parent 8f91747 commit 1370a6f

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/server/conn.rs

+27-6
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,23 @@ where
110110
S::ResBody,
111111
>,
112112
>>,
113-
fallback: bool,
113+
fallback: Fallback,
114114
}
115115

116+
#[derive(Clone, Debug)]
117+
enum Fallback {
118+
ToHttp2(Exec),
119+
Http1Only,
120+
}
116121

122+
impl Fallback {
123+
fn to_h2(&self) -> bool {
124+
match *self {
125+
Fallback::ToHttp2(_) => true,
126+
Fallback::Http1Only => false,
127+
}
128+
}
129+
}
117130

118131
/// Deconstructed parts of a `Connection`.
119132
///
@@ -305,7 +318,11 @@ impl Http {
305318

306319
Connection {
307320
conn: Some(either),
308-
fallback: self.mode == ConnectionMode::Fallback,
321+
fallback: if self.mode == ConnectionMode::Fallback {
322+
Fallback::ToHttp2(self.exec.clone())
323+
} else {
324+
Fallback::Http1Only
325+
},
309326
}
310327
}
311328

@@ -442,7 +459,7 @@ where
442459
Err(e) => {
443460
debug!("error polling connection protocol without shutdown: {}", e);
444461
match *e.kind() {
445-
Kind::Parse(Parse::VersionH2) if self.fallback => {
462+
Kind::Parse(Parse::VersionH2) if self.fallback.to_h2() => {
446463
self.upgrade_h2();
447464
continue;
448465
}
@@ -467,7 +484,11 @@ where
467484
};
468485
let mut rewind_io = Rewind::new(io);
469486
rewind_io.rewind(read_buf);
470-
let h2 = proto::h2::Server::new(rewind_io, dispatch.into_service(), Exec::Default);
487+
let exec = match self.fallback {
488+
Fallback::ToHttp2(ref exec) => exec.clone(),
489+
Fallback::Http1Only => unreachable!("upgrade_h2 with Fallback::Http1Only"),
490+
};
491+
let h2 = proto::h2::Server::new(rewind_io, dispatch.into_service(), exec);
471492

472493
debug_assert!(self.conn.is_none());
473494
self.conn = Some(Either::B(h2));
@@ -512,7 +533,7 @@ where
512533
Err(e) => {
513534
debug!("error polling connection protocol: {}", e);
514535
match *e.kind() {
515-
Kind::Parse(Parse::VersionH2) if self.fallback => {
536+
Kind::Parse(Parse::VersionH2) if self.fallback.to_h2() => {
516537
self.upgrade_h2();
517538
continue;
518539
}
@@ -717,7 +738,7 @@ mod upgrades {
717738
Err(e) => {
718739
debug!("error polling connection protocol: {}", e);
719740
match *e.kind() {
720-
Kind::Parse(Parse::VersionH2) if self.inner.fallback => {
741+
Kind::Parse(Parse::VersionH2) if self.inner.fallback.to_h2() => {
721742
self.inner.upgrade_h2();
722743
continue;
723744
}

0 commit comments

Comments
 (0)