Moved WriteStatus, Fresh, and Streaming in to the net module.
This commit is contained in:
committed by
Sean McArthur
parent
d5c6f33c34
commit
4115c0e219
@@ -8,9 +8,9 @@ use std::io::net::ip::Ipv4Addr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use hyper::{Get, Post};
|
||||
use hyper::server::{Server, Handler, Incoming, Request, Response, Fresh};
|
||||
use hyper::server::{Server, Handler, Incoming, Request, Response};
|
||||
use hyper::header::common::ContentLength;
|
||||
use hyper::net::{HttpStream, HttpAcceptor};
|
||||
use hyper::net::{HttpStream, HttpAcceptor, Fresh};
|
||||
|
||||
trait ConcurrentHandler: Send + Sync {
|
||||
fn handle(&self, req: Request, res: Response<Fresh>);
|
||||
|
||||
@@ -6,28 +6,11 @@ use url::Url;
|
||||
use method::{mod, Get, Post, Delete, Put, Patch, Head, Options};
|
||||
use header::Headers;
|
||||
use header::common::Host;
|
||||
use net::{NetworkStream, HttpStream};
|
||||
use net::{NetworkStream, HttpStream, WriteStatus, Fresh, Streaming};
|
||||
use http::LINE_ENDING;
|
||||
use version;
|
||||
use {HttpResult, HttpUriError};
|
||||
use super::Response;
|
||||
|
||||
/// The write-status of a Request that has not had its headers written.
|
||||
pub struct Fresh;
|
||||
|
||||
/// The write-status of a Request that has had its headers written.
|
||||
pub struct Streaming;
|
||||
|
||||
/// The write-status of a Request
|
||||
pub trait WriteStatus: Private {}
|
||||
impl WriteStatus for Fresh {}
|
||||
impl WriteStatus for Streaming {}
|
||||
|
||||
// Only Fresh and Streaming can be WriteStatus
|
||||
#[doc(hidden)]
|
||||
trait Private {}
|
||||
impl Private for Fresh {}
|
||||
impl Private for Streaming {}
|
||||
use client::Response;
|
||||
|
||||
/// A client request to a remote server.
|
||||
pub struct Request<W: WriteStatus> {
|
||||
|
||||
17
src/net.rs
17
src/net.rs
@@ -3,6 +3,23 @@ use std::io::{IoResult, Stream, Listener, Acceptor};
|
||||
use std::io::net::ip::{SocketAddr, Port};
|
||||
use std::io::net::tcp::{TcpStream, TcpListener, TcpAcceptor};
|
||||
|
||||
/// The write-status indicating headers have not been written.
|
||||
pub struct Fresh;
|
||||
|
||||
/// The write-status indicating headers have been written.
|
||||
pub struct Streaming;
|
||||
|
||||
/// The write-status of a Request
|
||||
pub trait WriteStatus: Private {}
|
||||
impl WriteStatus for Fresh {}
|
||||
impl WriteStatus for Streaming {}
|
||||
|
||||
// Only Fresh and Streaming can be WriteStatus
|
||||
#[doc(hidden)]
|
||||
trait Private {}
|
||||
impl Private for Fresh {}
|
||||
impl Private for Streaming {}
|
||||
|
||||
/// An abstraction to listen for connections on a certain port.
|
||||
pub trait NetworkListener<S: NetworkStream, A: NetworkAcceptor<S>>: Listener<S, A> {
|
||||
/// Bind to a socket.
|
||||
|
||||
@@ -6,11 +6,12 @@ use intertwine::{Intertwine, Intertwined};
|
||||
use macceptor::MoveAcceptor;
|
||||
|
||||
pub use self::request::Request;
|
||||
pub use self::response::{Response, Fresh, Streaming};
|
||||
|
||||
use net::{NetworkListener, NetworkAcceptor, NetworkStream, HttpAcceptor, HttpListener, HttpStream};
|
||||
pub use self::response::Response;
|
||||
|
||||
use {HttpResult};
|
||||
use net::{NetworkListener, NetworkAcceptor, NetworkStream,
|
||||
HttpAcceptor, HttpListener, HttpStream,
|
||||
Fresh};
|
||||
|
||||
pub mod request;
|
||||
pub mod response;
|
||||
|
||||
@@ -10,21 +10,9 @@ use header;
|
||||
use header::common;
|
||||
use http::{CR, LF, LINE_ENDING};
|
||||
use status;
|
||||
use net::NetworkStream;
|
||||
use net::{NetworkStream, WriteStatus, Fresh, Streaming};
|
||||
use version;
|
||||
|
||||
/// Phantom type indicating Headers and StatusCode have not been written.
|
||||
pub struct Fresh;
|
||||
|
||||
/// Phantom type indicating Headers and StatusCode have been written.
|
||||
pub struct Streaming;
|
||||
|
||||
/// The status of a Response, indicating if the headers and status have been written.
|
||||
pub trait WriteStatus {}
|
||||
|
||||
impl WriteStatus for Streaming {}
|
||||
impl WriteStatus for Fresh {}
|
||||
|
||||
/// The outgoing half for a Tcp connection, created by a `Server` and given to a `Handler`.
|
||||
pub struct Response<W: WriteStatus> {
|
||||
/// The HTTP version of this response.
|
||||
|
||||
Reference in New Issue
Block a user