mirror of
https://github.com/actix/actix-web.git
synced 2024-12-28 19:10:36 +00:00
allow to pass extra information from acceptor to application level
This commit is contained in:
parent
f3f1e04853
commit
e34b5c08ba
4 changed files with 28 additions and 2 deletions
|
@ -368,6 +368,10 @@ where
|
|||
self.payload = Some(PayloadType::new(&msg.inner.headers, ps));
|
||||
}
|
||||
|
||||
// stream extensions
|
||||
msg.inner_mut().stream_extensions =
|
||||
self.stream.get_mut().extensions();
|
||||
|
||||
// set remote addr
|
||||
msg.inner_mut().addr = self.addr;
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ use tokio_io::{AsyncRead, AsyncWrite};
|
|||
use tokio_timer::Delay;
|
||||
|
||||
use error::{Error, PayloadError};
|
||||
use extensions::Extensions;
|
||||
use http::{StatusCode, Version};
|
||||
use payload::{Payload, PayloadStatus, PayloadWriter};
|
||||
use uri::Url;
|
||||
|
@ -22,7 +23,7 @@ use super::error::ServerError;
|
|||
use super::h2writer::H2Writer;
|
||||
use super::input::PayloadType;
|
||||
use super::settings::WorkerSettings;
|
||||
use super::{HttpHandler, HttpHandlerTask, Writer};
|
||||
use super::{HttpHandler, HttpHandlerTask, IoStream, Writer};
|
||||
|
||||
bitflags! {
|
||||
struct Flags: u8 {
|
||||
|
@ -42,6 +43,7 @@ where
|
|||
state: State<IoWrapper<T>>,
|
||||
tasks: VecDeque<Entry<H>>,
|
||||
keepalive_timer: Option<Delay>,
|
||||
extensions: Option<Rc<Extensions>>,
|
||||
}
|
||||
|
||||
enum State<T: AsyncRead + AsyncWrite> {
|
||||
|
@ -52,12 +54,13 @@ enum State<T: AsyncRead + AsyncWrite> {
|
|||
|
||||
impl<T, H> Http2<T, H>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite + 'static,
|
||||
T: IoStream + 'static,
|
||||
H: HttpHandler + 'static,
|
||||
{
|
||||
pub fn new(
|
||||
settings: Rc<WorkerSettings<H>>, io: T, addr: Option<SocketAddr>, buf: Bytes,
|
||||
) -> Self {
|
||||
let extensions = io.extensions();
|
||||
Http2 {
|
||||
flags: Flags::empty(),
|
||||
tasks: VecDeque::new(),
|
||||
|
@ -68,6 +71,7 @@ where
|
|||
keepalive_timer: None,
|
||||
addr,
|
||||
settings,
|
||||
extensions,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,6 +210,7 @@ where
|
|||
resp,
|
||||
self.addr,
|
||||
&self.settings,
|
||||
self.extensions.clone(),
|
||||
));
|
||||
}
|
||||
Ok(Async::NotReady) => {
|
||||
|
@ -324,6 +329,7 @@ impl<H: HttpHandler + 'static> Entry<H> {
|
|||
fn new(
|
||||
parts: Parts, recv: RecvStream, resp: SendResponse<Bytes>,
|
||||
addr: Option<SocketAddr>, settings: &Rc<WorkerSettings<H>>,
|
||||
extensions: Option<Rc<Extensions>>,
|
||||
) -> Entry<H>
|
||||
where
|
||||
H: HttpHandler + 'static,
|
||||
|
@ -338,6 +344,7 @@ impl<H: HttpHandler + 'static> Entry<H> {
|
|||
inner.method = parts.method;
|
||||
inner.version = parts.version;
|
||||
inner.headers = parts.headers;
|
||||
inner.stream_extensions = extensions;
|
||||
*inner.payload.borrow_mut() = Some(payload);
|
||||
inner.addr = addr;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ pub(crate) struct InnerRequest {
|
|||
pub(crate) info: RefCell<ConnectionInfo>,
|
||||
pub(crate) payload: RefCell<Option<Payload>>,
|
||||
pub(crate) settings: ServerSettings,
|
||||
pub(crate) stream_extensions: Option<Rc<Extensions>>,
|
||||
pool: &'static RequestPool,
|
||||
}
|
||||
|
||||
|
@ -82,6 +83,7 @@ impl Request {
|
|||
info: RefCell::new(ConnectionInfo::default()),
|
||||
payload: RefCell::new(None),
|
||||
extensions: RefCell::new(Extensions::new()),
|
||||
stream_extensions: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -189,6 +191,12 @@ impl Request {
|
|||
}
|
||||
}
|
||||
|
||||
/// Io stream extensions
|
||||
#[inline]
|
||||
pub fn stream_extensions(&self) -> Option<&Extensions> {
|
||||
self.inner().stream_extensions.as_ref().map(|e| e.as_ref())
|
||||
}
|
||||
|
||||
/// Server settings
|
||||
#[inline]
|
||||
pub fn server_settings(&self) -> &ServerSettings {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
//! Http server
|
||||
use std::net::Shutdown;
|
||||
use std::rc::Rc;
|
||||
use std::{io, net, time};
|
||||
|
||||
use bytes::{BufMut, BytesMut};
|
||||
|
@ -36,6 +37,7 @@ pub use self::helpers::write_content_length;
|
|||
use actix::Message;
|
||||
use body::Binary;
|
||||
use error::Error;
|
||||
use extensions::Extensions;
|
||||
use header::ContentEncoding;
|
||||
use httpresponse::HttpResponse;
|
||||
|
||||
|
@ -287,6 +289,11 @@ pub trait IoStream: AsyncRead + AsyncWrite + 'static {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Extra io stream extensions
|
||||
fn extensions(&self) -> Option<Rc<Extensions>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl IoStream for TcpStream {
|
||||
|
|
Loading…
Reference in a new issue