Get a request sent
This commit is contained in:
26
src/frame/go_away.rs
Normal file
26
src/frame/go_away.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use frame::Error;
|
||||
use super::{head, StreamId};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GoAway {
|
||||
last_stream_id: StreamId,
|
||||
error_code: u32,
|
||||
}
|
||||
|
||||
impl GoAway {
|
||||
pub fn load(payload: &[u8]) -> Result<GoAway, Error> {
|
||||
if payload.len() < 8 {
|
||||
// Invalid payload len
|
||||
// TODO: Handle error
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
let last_stream_id = head::parse_stream_id(&payload[..4]);
|
||||
let error_code = unpack_octets_4!(payload, 4, u32);
|
||||
|
||||
Ok(GoAway {
|
||||
last_stream_id: last_stream_id,
|
||||
error_code: error_code,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,8 @@ impl Head {
|
||||
/// octet is ignored and the rest interpreted as a network-endian 31-bit
|
||||
/// integer.
|
||||
#[inline]
|
||||
fn parse_stream_id(buf: &[u8]) -> StreamId {
|
||||
pub fn parse_stream_id(buf: &[u8]) -> StreamId {
|
||||
/// TODO: Move this onto the StreamId type?
|
||||
let unpacked = unpack_octets_4!(buf, 0, u32);
|
||||
// Now clear the most significant bit, as that is reserved and MUST be ignored when received.
|
||||
unpacked & !STREAM_ID_MASK
|
||||
|
||||
@@ -176,6 +176,10 @@ impl Headers {
|
||||
self.flags.is_end_headers()
|
||||
}
|
||||
|
||||
pub fn set_end_stream(&mut self) {
|
||||
self.flags.set_end_stream()
|
||||
}
|
||||
|
||||
pub fn encode(self, encoder: &mut hpack::Encoder, dst: &mut BytesMut)
|
||||
-> Option<Continuation>
|
||||
{
|
||||
@@ -208,13 +212,13 @@ impl Headers {
|
||||
let len = (dst.len() - pos) - frame::HEADER_LEN;
|
||||
|
||||
// Write the frame length
|
||||
BigEndian::write_u32(&mut dst[pos..pos+3], len as u32);
|
||||
BigEndian::write_uint(&mut dst[pos..pos+3], len as u64, 3);
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
fn head(&self) -> Head {
|
||||
Head::new(Kind::Data, self.flags.into(), self.stream_id)
|
||||
Head::new(Kind::Headers, self.flags.into(), self.stream_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ use std::io;
|
||||
/// ```
|
||||
#[macro_escape]
|
||||
macro_rules! unpack_octets_4 {
|
||||
// TODO: Get rid of this macro
|
||||
($buf:expr, $offset:expr, $tip:ty) => (
|
||||
(($buf[$offset + 0] as $tip) << 24) |
|
||||
(($buf[$offset + 1] as $tip) << 16) |
|
||||
@@ -27,12 +28,14 @@ macro_rules! unpack_octets_4 {
|
||||
}
|
||||
|
||||
mod data;
|
||||
mod go_away;
|
||||
mod head;
|
||||
mod headers;
|
||||
mod settings;
|
||||
mod util;
|
||||
|
||||
pub use self::data::Data;
|
||||
pub use self::go_away::GoAway;
|
||||
pub use self::head::{Head, Kind, StreamId};
|
||||
pub use self::headers::{Headers, PushPromise, Continuation, Pseudo};
|
||||
pub use self::settings::{Settings, SettingSet};
|
||||
|
||||
@@ -22,6 +22,7 @@ pub struct SettingSet {
|
||||
/// frame.
|
||||
///
|
||||
/// Each setting has a value that is a 32 bit unsigned integer (6.5.1.).
|
||||
#[derive(Debug)]
|
||||
pub enum Setting {
|
||||
HeaderTableSize(u32),
|
||||
EnablePush(u32),
|
||||
@@ -134,10 +135,15 @@ impl Settings {
|
||||
let head = Head::new(Kind::Settings, self.flags.into(), 0);
|
||||
let payload_len = self.payload_len();
|
||||
|
||||
trace!("encoding SETTINGS; len={}", payload_len);
|
||||
|
||||
head.encode(payload_len, dst);
|
||||
|
||||
// Encode the settings
|
||||
self.for_each(|setting| setting.encode(dst));
|
||||
self.for_each(|setting| {
|
||||
trace!("encoding setting; val={:?}", setting);
|
||||
setting.encode(dst)
|
||||
});
|
||||
}
|
||||
|
||||
fn for_each<F: FnMut(Setting)>(&self, mut f: F) {
|
||||
|
||||
Reference in New Issue
Block a user