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