Much work

This commit is contained in:
Carl Lerche
2017-06-23 13:13:50 -07:00
parent a3950354aa
commit fa21970656
15 changed files with 531 additions and 77 deletions

View File

@@ -66,7 +66,7 @@ impl Head {
}
pub fn encode<T: BufMut>(&self, payload_len: usize, dst: &mut T) {
debug_assert_eq!(self.encode_len(), dst.remaining_mut());
debug_assert!(self.encode_len() <= dst.remaining_mut());
debug_assert!(self.stream_id & STREAM_ID_MASK == 0);
dst.put_uint::<BigEndian>(payload_len as u64, 3);

View File

@@ -34,7 +34,7 @@ pub struct Headers {
flags: HeadersFlag,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct HeadersFlag(u8);
#[derive(Debug)]
@@ -108,6 +108,16 @@ const ALL: u8 = END_STREAM
// ===== impl Headers =====
impl Headers {
pub fn new(stream_id: StreamId, pseudo: Pseudo, fields: HeaderMap<HeaderValue>) -> Self {
Headers {
stream_id: stream_id,
stream_dep: None,
fields: fields,
pseudo: pseudo,
flags: HeadersFlag::default(),
}
}
pub fn load(head: Head, src: &mut Cursor<Bytes>, decoder: &mut hpack::Decoder)
-> Result<Self, Error>
{
@@ -162,6 +172,10 @@ impl Headers {
})
}
pub fn is_end_headers(&self) -> bool {
self.flags.is_end_headers()
}
pub fn encode(self, encoder: &mut hpack::Encoder, dst: &mut BytesMut)
-> Option<Continuation>
{
@@ -210,6 +224,28 @@ impl From<Headers> for Frame {
}
}
// ===== impl Pseudo =====
impl Pseudo {
pub fn request(method: Method, path: ByteStr) -> Self {
Pseudo {
method: Some(method),
scheme: None,
authority: None,
path: Some(path),
status: None,
}
}
pub fn set_scheme(&mut self, scheme: ByteStr) {
self.scheme = Some(scheme);
}
pub fn set_authority(&mut self, authority: ByteStr) {
self.authority = Some(authority);
}
}
// ===== impl Iter =====
impl Iterator for Iter {
@@ -264,6 +300,10 @@ impl HeadersFlag {
self.0 & END_STREAM == END_STREAM
}
pub fn set_end_stream(&mut self) {
self.0 |= END_STREAM
}
pub fn is_end_headers(&self) -> bool {
self.0 & END_HEADERS == END_HEADERS
}
@@ -277,6 +317,13 @@ impl HeadersFlag {
}
}
impl Default for HeadersFlag {
/// Returns a `HeadersFlag` value with `END_HEADERS` set.
fn default() -> Self {
HeadersFlag(END_HEADERS)
}
}
impl From<HeadersFlag> for u8 {
fn from(src: HeadersFlag) -> u8 {
src.0

View File

@@ -34,7 +34,7 @@ mod util;
pub use self::data::Data;
pub use self::head::{Head, Kind, StreamId};
pub use self::headers::{Headers, PushPromise, Continuation};
pub use self::headers::{Headers, PushPromise, Continuation, Pseudo};
pub use self::settings::{Settings, SettingSet};
// Re-export some constants

View File

@@ -81,6 +81,7 @@ impl Settings {
// Ensure the payload length is correct, each setting is 6 bytes long.
if payload.len() % 6 != 0 {
debug!("invalid settings payload length; len={:?}", payload.len());
return Err(Error::InvalidPayloadAckSettings);
}