Get a server working

This commit is contained in:
Carl Lerche
2017-07-06 14:55:35 -07:00
parent cb5130e3c6
commit 5982113c7a
5 changed files with 80 additions and 9 deletions

View File

@@ -1,10 +1,11 @@
use {frame, Frame, ConnectionError, Peer, StreamId};
use client::Client;
use server::Server;
use proto::{self, ReadySink, State};
use tokio_io::{AsyncRead, AsyncWrite};
use http::{request};
use http::{request, response};
use futures::*;
@@ -52,6 +53,23 @@ impl<T> Connection<T, Client>
}
}
impl<T> Connection<T, Server>
where T: AsyncRead + AsyncWrite,
{
pub fn send_response(self,
id: StreamId, // TODO: Generate one internally?
response: response::Head,
end_of_stream: bool)
-> sink::Send<Self>
{
self.send(Frame::Headers {
id: id,
headers: response,
end_of_stream: end_of_stream,
})
}
}
impl<T, P> Stream for Connection<T, P>
where T: AsyncRead + AsyncWrite,
P: Peer,
@@ -126,7 +144,9 @@ impl<T, P> Sink for Connection<T, P>
match item {
Frame::Headers { id, headers, end_of_stream } => {
// Ensure ID is valid
try!(P::check_initiating_id(id));
// TODO: This check should only be done **if** this is a new
// stream ID
// try!(P::check_initiating_id(id));
// TODO: Ensure available capacity for a new stream
// This won't be as simple as self.streams.len() as closed