Process response
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use frame::{util, Head, Error, StreamId, Kind};
|
||||
use frame::{util, Frame, Head, Error, StreamId, Kind};
|
||||
use bytes::{BufMut, Bytes};
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -35,10 +35,18 @@ impl Data {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn stream_id(&self) -> StreamId {
|
||||
self.stream_id
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.data.len()
|
||||
}
|
||||
|
||||
pub fn is_end_stream(&self) -> bool {
|
||||
self.flags.is_end_stream()
|
||||
}
|
||||
|
||||
pub fn encode<T: BufMut>(&self, dst: &mut T) {
|
||||
self.head().encode(self.len(), dst);
|
||||
dst.put(&self.data);
|
||||
@@ -53,6 +61,13 @@ impl Data {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Data> for Frame {
|
||||
fn from(src: Data) -> Frame {
|
||||
Frame::Data(src)
|
||||
}
|
||||
}
|
||||
|
||||
// ===== impl DataFlag =====
|
||||
|
||||
impl DataFlag {
|
||||
pub fn load(bits: u8) -> DataFlag {
|
||||
|
||||
@@ -4,7 +4,7 @@ use error::Reason;
|
||||
use frame::{self, Frame, Head, Kind, Error};
|
||||
use util::byte_str::ByteStr;
|
||||
|
||||
use http::{Method, StatusCode};
|
||||
use http::{request, response, Method, StatusCode};
|
||||
use http::header::{self, HeaderMap, HeaderName, HeaderValue};
|
||||
|
||||
use bytes::{BytesMut, Bytes};
|
||||
@@ -172,14 +172,35 @@ impl Headers {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn stream_id(&self) -> StreamId {
|
||||
self.stream_id
|
||||
}
|
||||
|
||||
pub fn is_end_headers(&self) -> bool {
|
||||
self.flags.is_end_headers()
|
||||
}
|
||||
|
||||
pub fn is_end_stream(&self) -> bool {
|
||||
self.flags.is_end_stream()
|
||||
}
|
||||
|
||||
pub fn set_end_stream(&mut self) {
|
||||
self.flags.set_end_stream()
|
||||
}
|
||||
|
||||
pub fn into_response(self) -> response::Head {
|
||||
let mut response = response::Head::default();
|
||||
|
||||
if let Some(status) = self.pseudo.status {
|
||||
response.status = status;
|
||||
} else {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
response.headers = self.fields;
|
||||
response
|
||||
}
|
||||
|
||||
pub fn encode(self, encoder: &mut hpack::Encoder, dst: &mut BytesMut)
|
||||
-> Option<Continuation>
|
||||
{
|
||||
|
||||
@@ -31,6 +31,7 @@ mod data;
|
||||
mod go_away;
|
||||
mod head;
|
||||
mod headers;
|
||||
mod reset;
|
||||
mod settings;
|
||||
mod util;
|
||||
|
||||
@@ -38,6 +39,7 @@ 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::reset::Reset;
|
||||
pub use self::settings::{Settings, SettingSet};
|
||||
|
||||
// Re-export some constants
|
||||
|
||||
25
src/frame/reset.rs
Normal file
25
src/frame/reset.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use frame::{Head, Error};
|
||||
use super::{head, StreamId};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Reset {
|
||||
stream_id: StreamId,
|
||||
error_code: u32,
|
||||
}
|
||||
|
||||
impl Reset {
|
||||
pub fn load(head: Head, payload: &[u8]) -> Result<Reset, Error> {
|
||||
if payload.len() != 4 {
|
||||
// Invalid payload len
|
||||
// TODO: Handle error
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
let error_code = unpack_octets_4!(payload, 0, u32);
|
||||
|
||||
Ok(Reset {
|
||||
stream_id: head.stream_id(),
|
||||
error_code: error_code,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user