mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 09:42:57 +01:00
stop claiming actor support
This commit is contained in:
parent
ceace26ed4
commit
871ca5e4ae
@ -32,7 +32,6 @@
|
||||
* SSL support using OpenSSL or Rustls
|
||||
* Middlewares ([Logger, Session, CORS, etc](https://actix.rs/docs/middleware/))
|
||||
* Includes an async [HTTP client](https://actix.rs/actix-web/actix_web/client/index.html)
|
||||
* Supports [Actix actor framework](https://github.com/actix/actix)
|
||||
* Runs on stable Rust 1.46+
|
||||
|
||||
## Documentation
|
||||
|
@ -356,6 +356,7 @@ where
|
||||
this.state.set(State::ServiceCall(task));
|
||||
};
|
||||
}
|
||||
|
||||
// handle error message.
|
||||
Some(DispatcherMessage::Error(res)) => {
|
||||
// send_response would update InnerDispatcher state to SendPayload or
|
||||
@ -364,10 +365,12 @@ where
|
||||
self.as_mut()
|
||||
.send_response(res, ResponseBody::Other(Body::Empty))?;
|
||||
}
|
||||
|
||||
// return with upgrade request and poll it exclusively.
|
||||
Some(DispatcherMessage::Upgrade(req)) => {
|
||||
return Ok(PollResponse::Upgrade(req));
|
||||
}
|
||||
|
||||
// all messages are dealt with.
|
||||
None => return Ok(PollResponse::DoNothing),
|
||||
},
|
||||
@ -377,12 +380,14 @@ where
|
||||
let (res, body) = res.into().replace_body(());
|
||||
self.as_mut().send_response(res, body)?;
|
||||
}
|
||||
|
||||
// send service call error as response
|
||||
Poll::Ready(Err(e)) => {
|
||||
let res: Response = e.into().into();
|
||||
let (res, body) = res.replace_body(());
|
||||
self.as_mut().send_response(res, body.into_body())?;
|
||||
}
|
||||
|
||||
// service call pending and could be waiting for more chunk messages.
|
||||
// (pipeline message limit and/or payload can_read limit)
|
||||
Poll::Pending => {
|
||||
@ -394,6 +399,7 @@ where
|
||||
// otherwise keep loop.
|
||||
}
|
||||
},
|
||||
|
||||
StateProj::SendPayload(mut stream) => {
|
||||
// keep populate writer buffer until buffer size limit hit,
|
||||
// get blocked or finished.
|
||||
@ -405,6 +411,7 @@ where
|
||||
&mut this.write_buf,
|
||||
)?;
|
||||
}
|
||||
|
||||
Poll::Ready(None) => {
|
||||
this.codec
|
||||
.encode(Message::Chunk(None), &mut this.write_buf)?;
|
||||
@ -413,9 +420,11 @@ where
|
||||
this.state.set(State::None);
|
||||
continue 'res;
|
||||
}
|
||||
|
||||
Poll::Ready(Some(Err(e))) => {
|
||||
return Err(DispatchError::Service(e))
|
||||
}
|
||||
|
||||
Poll::Pending => return Ok(PollResponse::DoNothing),
|
||||
}
|
||||
}
|
||||
@ -423,6 +432,7 @@ where
|
||||
// return and try to write the whole buffer to io stream.
|
||||
return Ok(PollResponse::DrainWriteBuf);
|
||||
}
|
||||
|
||||
StateProj::ExpectCall(fut) => match fut.poll(cx) {
|
||||
// expect resolved. write continue to buffer and set InnerDispatcher state
|
||||
// to service call.
|
||||
|
27
src/lib.rs
27
src/lib.rs
@ -56,7 +56,6 @@
|
||||
//! * SSL support using OpenSSL or Rustls
|
||||
//! * Middlewares ([Logger, Session, CORS, etc](https://actix.rs/docs/middleware/))
|
||||
//! * Includes an async [HTTP client](https://actix.rs/actix-web/actix_web/client/index.html)
|
||||
//! * Supports [Actix actor framework](https://github.com/actix/actix)
|
||||
//! * Runs on stable Rust 1.46+
|
||||
//!
|
||||
//! ## Crate Features
|
||||
@ -203,29 +202,3 @@ pub mod dev {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod client {
|
||||
//! Actix Web async HTTP client.
|
||||
//!
|
||||
//! ```rust
|
||||
//! use actix_web::client::Client;
|
||||
//!
|
||||
//! #[actix_web::main]
|
||||
//! async fn main() {
|
||||
//! let mut client = Client::default();
|
||||
//!
|
||||
//! // Create request builder and send request
|
||||
//! let response = client.get("http://www.rust-lang.org")
|
||||
//! .insert_header(("User-Agent", "actix-web/3.0"))
|
||||
//! .send() // <- Send request
|
||||
//! .await; // <- Wait for response
|
||||
//!
|
||||
//! println!("Response: {:?}", response);
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
pub use awc::error::*;
|
||||
pub use awc::{
|
||||
test, Client, ClientBuilder, ClientRequest, ClientResponse, Connector,
|
||||
};
|
||||
}
|
||||
|
53
src/test.rs
53
src/test.rs
@ -1246,57 +1246,4 @@ mod tests {
|
||||
let res = app.call(req).await.unwrap();
|
||||
assert!(res.status().is_success());
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_actor() {
|
||||
use crate::Error;
|
||||
use actix::prelude::*;
|
||||
|
||||
struct MyActor;
|
||||
|
||||
impl Actor for MyActor {
|
||||
type Context = Context<Self>;
|
||||
}
|
||||
|
||||
struct Num(usize);
|
||||
|
||||
impl Message for Num {
|
||||
type Result = usize;
|
||||
}
|
||||
|
||||
impl Handler<Num> for MyActor {
|
||||
type Result = usize;
|
||||
|
||||
fn handle(&mut self, msg: Num, _: &mut Self::Context) -> Self::Result {
|
||||
msg.0
|
||||
}
|
||||
}
|
||||
|
||||
let addr = MyActor.start();
|
||||
|
||||
async fn actor_handler(
|
||||
addr: Data<Addr<MyActor>>,
|
||||
) -> Result<impl Responder, Error> {
|
||||
let res = addr
|
||||
.send(Num(1))
|
||||
.await
|
||||
.map_err(crate::error::ErrorInternalServerError)?;
|
||||
|
||||
if res == 1 {
|
||||
Ok(HttpResponse::Ok())
|
||||
} else {
|
||||
Ok(HttpResponse::BadRequest())
|
||||
}
|
||||
}
|
||||
|
||||
let srv = App::new()
|
||||
.data(addr.clone())
|
||||
.service(web::resource("/").to(actor_handler));
|
||||
|
||||
let app = init_service(srv).await;
|
||||
|
||||
let req = TestRequest::post().uri("/").to_request();
|
||||
let res = app.call(req).await.unwrap();
|
||||
assert!(res.status().is_success());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user