mirror of
https://github.com/fafhrd91/actix-web
synced 2025-09-02 17:46:38 +02:00
simplify middleware api; fix examples
This commit is contained in:
@@ -29,6 +29,7 @@ pub struct HttpContext<A> where A: Actor<Context=HttpContext<A>> + Route,
|
||||
address: ActorAddressCell<A>,
|
||||
stream: VecDeque<Frame>,
|
||||
wait: ActorWaitCell<A>,
|
||||
app_state: Rc<<A as Route>::State>,
|
||||
disconnected: bool,
|
||||
}
|
||||
|
||||
@@ -101,9 +102,10 @@ impl<A> AsyncContextApi<A> for HttpContext<A> where A: Actor<Context=Self> + Rou
|
||||
}
|
||||
}
|
||||
|
||||
impl<A> Default for HttpContext<A> where A: Actor<Context=Self> + Route {
|
||||
impl<A> HttpContext<A> where A: Actor<Context=Self> + Route {
|
||||
|
||||
fn default() -> HttpContext<A> {
|
||||
pub fn new(state: Rc<<A as Route>::State>) -> HttpContext<A>
|
||||
{
|
||||
HttpContext {
|
||||
act: None,
|
||||
state: ActorState::Started,
|
||||
@@ -112,12 +114,10 @@ impl<A> Default for HttpContext<A> where A: Actor<Context=Self> + Route {
|
||||
address: ActorAddressCell::default(),
|
||||
wait: ActorWaitCell::default(),
|
||||
stream: VecDeque::new(),
|
||||
app_state: state,
|
||||
disconnected: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<A> HttpContext<A> where A: Actor<Context=Self> + Route {
|
||||
|
||||
pub(crate) fn set_actor(&mut self, act: A) {
|
||||
self.act = Some(act)
|
||||
@@ -126,6 +126,11 @@ impl<A> HttpContext<A> where A: Actor<Context=Self> + Route {
|
||||
|
||||
impl<A> HttpContext<A> where A: Actor<Context=Self> + Route {
|
||||
|
||||
/// Shared application state
|
||||
pub fn state(&self) -> &<A as Route>::State {
|
||||
&self.app_state
|
||||
}
|
||||
|
||||
/// Start response processing
|
||||
pub fn start<R: Into<HttpResponse>>(&mut self, response: R) {
|
||||
self.stream.push_back(Frame::Message(response.into()))
|
||||
|
Reference in New Issue
Block a user