Handle client-disabled server push (#486)

This commit is contained in:
eggyal
2020-09-18 01:25:31 +01:00
committed by GitHub
parent a19323727b
commit 2b19acf132
6 changed files with 70 additions and 3 deletions

View File

@@ -63,6 +63,9 @@ pub enum UserError {
/// Tries to update local SETTINGS while ACK has not been received.
SendSettingsWhilePending,
/// Tries to send push promise to peer who has disabled server push
PeerDisabledServerPush,
}
// ===== impl RecvError =====
@@ -136,6 +139,7 @@ impl fmt::Display for UserError {
PollResetAfterSendResponse => "poll_reset after send_response is illegal",
SendPingWhilePending => "send_ping before received previous pong",
SendSettingsWhilePending => "sending SETTINGS before received previous ACK",
PeerDisabledServerPush => "sending PUSH_PROMISE to peer who disabled server push",
})
}
}

View File

@@ -99,8 +99,8 @@ impl Settings {
self.max_header_list_size = size;
}
pub fn is_push_enabled(&self) -> bool {
self.enable_push.unwrap_or(1) != 0
pub fn is_push_enabled(&self) -> Option<bool> {
self.enable_push.map(|val| val != 0)
}
pub fn set_enable_push(&mut self, enable: bool) {

View File

@@ -86,7 +86,7 @@ where
.unwrap_or(DEFAULT_INITIAL_WINDOW_SIZE),
initial_max_send_streams: config.initial_max_send_streams,
local_next_stream_id: config.next_stream_id,
local_push_enabled: config.settings.is_push_enabled(),
local_push_enabled: config.settings.is_push_enabled().unwrap_or(true),
local_reset_duration: config.reset_stream_duration,
local_reset_max: config.reset_stream_max,
remote_init_window_sz: DEFAULT_INITIAL_WINDOW_SIZE,

View File

@@ -32,6 +32,8 @@ pub(super) struct Send {
/// Prioritization layer
prioritize: Prioritize,
is_push_enabled: bool,
}
/// A value to detect which public API has called `poll_reset`.
@@ -49,6 +51,7 @@ impl Send {
max_stream_id: StreamId::MAX,
next_stream_id: Ok(config.local_next_stream_id),
prioritize: Prioritize::new(config),
is_push_enabled: true,
}
}
@@ -95,6 +98,10 @@ impl Send {
stream: &mut store::Ptr,
task: &mut Option<Waker>,
) -> Result<(), UserError> {
if !self.is_push_enabled {
return Err(UserError::PeerDisabledServerPush);
}
tracing::trace!(
"send_push_promise; frame={:?}; init_window={:?}",
frame,
@@ -496,6 +503,10 @@ impl Send {
}
}
if let Some(val) = settings.is_push_enabled() {
self.is_push_enabled = val
}
Ok(())
}