Skip to content

Commit ad856fb

Browse files
committed
test response to dummy request
some small bug fixes added as well as logging
1 parent 2479a59 commit ad856fb

16 files changed

+35
-3
lines changed

scripts/header_only.py

+4
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@
1212
my_socket = socket.socket()
1313
my_socket.connect(("127.0.0.1", 8080))
1414
my_socket.send(frame)
15+
16+
response = my_socket.recv(1024)
17+
18+
print(response)

src/http2/core/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ impl<'a, 'b> Connection<'a, 'b> {
157157

158158
// Fetch any send frames which have been generated on the stream.
159159
self.send_frames.extend(stream.fetch_send_frames());
160+
trace!("Finished processing headers on stream [{}]. Frames ready for send [{:?}]", frame.header.stream_id, self.send_frames);
160161
},
161162
_ => {
162163
panic!("can't handle that frame type yet");

src/http2/frame/continuation.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use super::FrameType;
2424

2525
const FLAG_END_HEADERS: u8 = 0x4;
2626

27+
#[derive(Debug)]
2728
pub struct ContinuationFrameCompressModel {
2829
flags: u8,
2930
header_block_fragment: Vec<u8>

src/http2/frame/data.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use super::FrameType;
2525
const FLAG_END_STREAM: u8 = 0x1;
2626
const FLAG_PADDED: u8 = 0x8;
2727

28+
#[derive(Debug)]
2829
pub struct DataFrameCompressModel {
2930
flags: u8,
3031
pad_length: u8,

src/http2/frame/go_away.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use super::FrameType;
2525

2626
const LAST_STREAM_IDENTIFIER_BIT_MASK: u8 = 0x80;
2727

28+
#[derive(Debug)]
2829
pub struct GoAwayFrameCompressModel {
2930
last_stream_identifier: u32,
3031
error_code: error::ErrorCode,

src/http2/frame/headers.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const FLAG_PRIORITY: u8 = 0x20;
2929

3030
const STREAM_DEPENDENCY_EXCLUSIVE_BIT_MASK: u8 = 0x80;
3131

32+
#[derive(Debug)]
3233
pub struct HeadersFrameCompressModel {
3334
flags: u8,
3435
pad_length: u8,

src/http2/frame/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ pub const FRAME_HEADER_SIZE: usize = 9;
3131
// Denoted 'R' in http2 Section 4.1
3232
const STREAM_IDENTIFIER_RESERVED_BIT_MASK: u8 = !0x80;
3333

34+
// std
35+
use std::fmt;
36+
3437
// osmium
3538
pub use self::data::DataFrame;
3639

37-
pub trait CompressibleHttpFrame {
40+
pub trait CompressibleHttpFrame: fmt::Debug {
3841
fn get_length(&self) -> i32;
3942

4043
fn get_frame_type(&self) -> FrameType;

src/http2/frame/ping.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const FLAG_ACK: u8 = 0x1;
2828
// the spec says '8 octets of opaque data', which can be anything? or should it be random
2929
const DEFAULT_PING_PAYLOAD: [u8; 8] = [0x9, 0x2, 0xa, 0x3, 0x2, 0xe, 0x1, 0xf];
3030

31+
#[derive(Debug)]
3132
pub struct PingFrameCompressModel {
3233
flags: u8,
3334
payload: [u8; 8]

src/http2/frame/priority.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use super::FrameType;
2424

2525
const STREAM_DEPENDENCY_EXCLUSIVE_BIT_MASK: u8 = 0x80;
2626

27+
#[derive(Debug)]
2728
pub struct PriorityFrameCompressModel {
2829
stream_dependency: u32,
2930
stream_dependency_exclusive: bool,

src/http2/frame/push_promise.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const FLAG_PADDED: u8 = 0x8;
2727

2828
const PROMISED_STREAM_IDENTIFIER_RESERVED_BIT_MASK: u8 = 0x80;
2929

30+
#[derive(Debug)]
3031
pub struct PushPromiseFrameCompressModel {
3132
flags: u8,
3233
pad_length: u8,

src/http2/frame/reset_stream.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use std::vec::IntoIter;
2222
use super::CompressibleHttpFrame;
2323
use super::FrameType;
2424

25+
#[derive(Debug)]
2526
pub struct ResetStreamFrameCompressModel {
2627
error_code: u32
2728
}

src/http2/frame/settings.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ use super::FrameType;
2525

2626
const FLAG_ACK: u8 = 0x1;
2727

28+
#[derive(Debug)]
2829
pub struct SettingsParameter {
2930
name: settings::SettingName,
3031
value: u32
3132
}
3233

34+
#[derive(Debug)]
3335
pub struct SettingsFrameCompressModel {
3436
flags: u8,
3537
parameters: Vec<SettingsParameter>

src/http2/frame/window_update.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use super::FrameType;
2424

2525
const WINDOW_SIZE_INCREMENT_BIT_MASK: u8 = 0x80;
2626

27+
#[derive(Debug)]
2728
pub struct WindowUpdateFrameCompressModel {
2829
window_size_increment: u32
2930
}

src/http2/net/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,12 @@ mod tests {
216216

217217
fn process(&self, request: Self::Request) -> Self::Response {
218218
println!("Got request {:?}", request);
219+
220+
let mut headers = header::Headers::new();
221+
headers.push(header::HeaderName::ContentLength, header::HeaderValue::Num(0));
222+
219223
HttpResponse {
220-
headers: header::Headers::new(),
224+
headers: headers,
221225
body: None
222226
}
223227
}

src/http2/settings.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with Osmium. If not, see <http://www.gnu.org/licenses/>.
1717

18+
#[derive(Debug)]
1819
pub enum SettingName {
1920
SettingsHeaderTableSize,
2021
SettingsEnablePush,

src/http2/stream/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ impl StreamRequest {
7777
impl StreamResponse {
7878
pub fn to_frames(self, hpack_context: &mut hpack_context::Context) -> Vec<Box<framing::CompressibleHttpFrame>>
7979
{
80+
trace!("Starting to convert stream response to frames [{:?}]", self);
81+
8082
let mut frames: Vec<Box<framing::CompressibleHttpFrame>> = Vec::new();
8183

8284
for informational_header in &self.informational_headers {
@@ -102,6 +104,8 @@ impl StreamResponse {
102104
frames.extend(trailer_headers_frame);
103105
}
104106

107+
trace!("Converted to frames [{:?}]", frames);
108+
105109
frames
106110
}
107111

@@ -722,10 +726,12 @@ impl Stream {
722726
}
723727

724728
self.send_frames.extend(temp_send_frames);
729+
730+
trace!("Finished sending frames on stream [{:?}]", self.send_frames);
725731
}
726732

727733
pub fn fetch_send_frames(&mut self) -> Vec<Vec<u8>> {
728-
self.send_frames.drain(1..).collect()
734+
self.send_frames.drain(0..).collect()
729735
}
730736

731737
fn should_headers_frame_end_stream(&self) -> bool {
@@ -755,8 +761,10 @@ impl Stream {
755761
let mut new_request = StreamRequest::new();
756762
mem::swap(&mut self.request, &mut new_request);
757763

764+
trace!("Passing request to the application [{:?}]", new_request);
758765
// TODO should the application be allowed to error?
759766
let response: StreamResponse = app.process(new_request.into()).into();
767+
trace!("Got response from the application [{:?}]", response);
760768

761769
self.send(response.to_frames(hpack_send_context));
762770
},

0 commit comments

Comments
 (0)