mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 16:02:59 +01:00
better actix mod re-exports
This commit is contained in:
parent
80965d7a9a
commit
154cd3c5de
@ -1,16 +1,12 @@
|
|||||||
extern crate actix;
|
|
||||||
|
|
||||||
use std::collections::{HashMap, VecDeque};
|
use std::collections::{HashMap, VecDeque};
|
||||||
use std::net::Shutdown;
|
use std::net::Shutdown;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use std::{fmt, io, mem, time};
|
use std::{fmt, io, mem, time};
|
||||||
|
|
||||||
use self::actix::actors::{Connect as ResolveConnect, Connector, ConnectorError};
|
use actix::resolver::{Connect as ResolveConnect, Connector, ConnectorError};
|
||||||
use self::actix::fut::WrapFuture;
|
use actix::{
|
||||||
use self::actix::registry::SystemService;
|
|
||||||
use self::actix::{
|
|
||||||
fut, Actor, ActorFuture, ActorResponse, AsyncContext, Context, ContextFutureSpawner,
|
fut, Actor, ActorFuture, ActorResponse, AsyncContext, Context, ContextFutureSpawner,
|
||||||
Handler, Message, Recipient, StreamHandler, Supervised,
|
Handler, Message, Recipient, StreamHandler, Supervised, SystemService, WrapFuture,
|
||||||
};
|
};
|
||||||
|
|
||||||
use futures::sync::{mpsc, oneshot};
|
use futures::sync::{mpsc, oneshot};
|
||||||
@ -287,7 +283,6 @@ impl ClientConnector {
|
|||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # #![cfg(feature="alpn")]
|
/// # #![cfg(feature="alpn")]
|
||||||
/// # extern crate actix;
|
|
||||||
/// # extern crate actix_web;
|
/// # extern crate actix_web;
|
||||||
/// # extern crate futures;
|
/// # extern crate futures;
|
||||||
/// # extern crate tokio;
|
/// # extern crate tokio;
|
||||||
@ -295,14 +290,12 @@ impl ClientConnector {
|
|||||||
/// # use std::io::Write;
|
/// # use std::io::Write;
|
||||||
/// # use std::process;
|
/// # use std::process;
|
||||||
/// extern crate openssl;
|
/// extern crate openssl;
|
||||||
/// use actix::prelude::*;
|
/// use actix_web::client::{ClientConnector, Connect};
|
||||||
/// use actix_web::client::{Connect, ClientConnector};
|
|
||||||
///
|
///
|
||||||
/// use openssl::ssl::{SslMethod, SslConnector};
|
/// use openssl::ssl::{SslConnector, SslMethod};
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// tokio::run(future::lazy(|| {
|
/// tokio::run(future::lazy(|| {
|
||||||
///
|
|
||||||
/// // Start `ClientConnector` with custom `SslConnector`
|
/// // Start `ClientConnector` with custom `SslConnector`
|
||||||
/// let ssl_conn = SslConnector::builder(SslMethod::tls()).unwrap().build();
|
/// let ssl_conn = SslConnector::builder(SslMethod::tls()).unwrap().build();
|
||||||
/// let conn = ClientConnector::with_connector(ssl_conn).start();
|
/// let conn = ClientConnector::with_connector(ssl_conn).start();
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
extern crate actix;
|
|
||||||
|
|
||||||
use bytes::{Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut};
|
||||||
use futures::sync::oneshot;
|
use futures::sync::oneshot;
|
||||||
use futures::{Async, Future, Poll};
|
use futures::{Async, Future, Poll};
|
||||||
@ -8,7 +6,7 @@ use std::time::{Duration, Instant};
|
|||||||
use std::{io, mem};
|
use std::{io, mem};
|
||||||
use tokio_timer::Delay;
|
use tokio_timer::Delay;
|
||||||
|
|
||||||
use self::actix::prelude::*;
|
use actix::{Addr, Request, SystemService};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
ClientBody, ClientBodyStream, ClientConnector, ClientConnectorError, ClientRequest,
|
ClientBody, ClientBodyStream, ClientConnector, ClientConnectorError, ClientRequest,
|
||||||
@ -56,7 +54,7 @@ impl From<ClientConnectorError> for SendRequestError {
|
|||||||
|
|
||||||
enum State {
|
enum State {
|
||||||
New,
|
New,
|
||||||
Connect(actix::dev::Request<ClientConnector, Connect>),
|
Connect(Request<ClientConnector, Connect>),
|
||||||
Connection(Connection),
|
Connection(Connection),
|
||||||
Send(Box<Pipeline>),
|
Send(Box<Pipeline>),
|
||||||
None,
|
None,
|
||||||
|
@ -118,10 +118,11 @@ pub trait HttpMessage {
|
|||||||
/// # extern crate actix_web;
|
/// # extern crate actix_web;
|
||||||
/// # extern crate futures;
|
/// # extern crate futures;
|
||||||
/// # #[macro_use] extern crate serde_derive;
|
/// # #[macro_use] extern crate serde_derive;
|
||||||
|
/// use actix_web::{
|
||||||
|
/// AsyncResponder, FutureResponse, HttpMessage, HttpRequest, HttpResponse,
|
||||||
|
/// };
|
||||||
/// use bytes::Bytes;
|
/// use bytes::Bytes;
|
||||||
/// use futures::future::Future;
|
/// use futures::future::Future;
|
||||||
/// use actix_web::{HttpMessage, HttpRequest, HttpResponse,
|
|
||||||
/// FutureResponse, AsyncResponder};
|
|
||||||
///
|
///
|
||||||
/// fn index(mut req: HttpRequest) -> FutureResponse<HttpResponse> {
|
/// fn index(mut req: HttpRequest) -> FutureResponse<HttpResponse> {
|
||||||
/// req.body() // <- get Body future
|
/// req.body() // <- get Body future
|
||||||
@ -158,7 +159,7 @@ pub trait HttpMessage {
|
|||||||
/// # extern crate futures;
|
/// # extern crate futures;
|
||||||
/// # use futures::Future;
|
/// # use futures::Future;
|
||||||
/// # use std::collections::HashMap;
|
/// # use std::collections::HashMap;
|
||||||
/// use actix_web::{HttpMessage, HttpRequest, HttpResponse, FutureResponse};
|
/// use actix_web::{FutureResponse, HttpMessage, HttpRequest, HttpResponse};
|
||||||
///
|
///
|
||||||
/// fn index(mut req: HttpRequest) -> FutureResponse<HttpResponse> {
|
/// fn index(mut req: HttpRequest) -> FutureResponse<HttpResponse> {
|
||||||
/// Box::new(
|
/// Box::new(
|
||||||
@ -167,7 +168,8 @@ pub trait HttpMessage {
|
|||||||
/// .and_then(|params| { // <- url encoded parameters
|
/// .and_then(|params| { // <- url encoded parameters
|
||||||
/// println!("==== BODY ==== {:?}", params);
|
/// println!("==== BODY ==== {:?}", params);
|
||||||
/// Ok(HttpResponse::Ok().into())
|
/// Ok(HttpResponse::Ok().into())
|
||||||
/// }))
|
/// }),
|
||||||
|
/// )
|
||||||
/// }
|
/// }
|
||||||
/// # fn main() {}
|
/// # fn main() {}
|
||||||
/// ```
|
/// ```
|
||||||
@ -193,14 +195,14 @@ pub trait HttpMessage {
|
|||||||
/// # extern crate futures;
|
/// # extern crate futures;
|
||||||
/// # #[macro_use] extern crate serde_derive;
|
/// # #[macro_use] extern crate serde_derive;
|
||||||
/// use actix_web::*;
|
/// use actix_web::*;
|
||||||
/// use futures::future::{Future, ok};
|
/// use futures::future::{ok, Future};
|
||||||
///
|
///
|
||||||
/// #[derive(Deserialize, Debug)]
|
/// #[derive(Deserialize, Debug)]
|
||||||
/// struct MyObj {
|
/// struct MyObj {
|
||||||
/// name: String,
|
/// name: String,
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
|
/// fn index(mut req: HttpRequest) -> Box<Future<Item = HttpResponse, Error = Error>> {
|
||||||
/// req.json() // <- get JsonBody future
|
/// req.json() // <- get JsonBody future
|
||||||
/// .from_err()
|
/// .from_err()
|
||||||
/// .and_then(|val: MyObj| { // <- deserialized value
|
/// .and_then(|val: MyObj| { // <- deserialized value
|
||||||
@ -224,16 +226,15 @@ pub trait HttpMessage {
|
|||||||
/// ## Server example
|
/// ## Server example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # extern crate actix;
|
|
||||||
/// # extern crate actix_web;
|
/// # extern crate actix_web;
|
||||||
/// # extern crate env_logger;
|
/// # extern crate env_logger;
|
||||||
/// # extern crate futures;
|
/// # extern crate futures;
|
||||||
/// # use std::str;
|
/// # use std::str;
|
||||||
/// # use actix_web::*;
|
/// # use actix_web::*;
|
||||||
/// # use actix::*;
|
/// # use actix_web::actix::*;
|
||||||
/// # use futures::{Future, Stream};
|
/// # use futures::{Future, Stream};
|
||||||
/// # use futures::future::{ok, result, Either};
|
/// # use futures::future::{ok, result, Either};
|
||||||
/// fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
|
/// fn index(mut req: HttpRequest) -> Box<Future<Item = HttpResponse, Error = Error>> {
|
||||||
/// req.multipart().from_err() // <- get multipart stream for current request
|
/// req.multipart().from_err() // <- get multipart stream for current request
|
||||||
/// .and_then(|item| match item { // <- iterate over multipart items
|
/// .and_then(|item| match item { // <- iterate over multipart items
|
||||||
/// multipart::MultipartItem::Field(field) => {
|
/// multipart::MultipartItem::Field(field) => {
|
||||||
|
22
src/lib.rs
22
src/lib.rs
@ -6,17 +6,17 @@
|
|||||||
//! # use std::thread;
|
//! # use std::thread;
|
||||||
//!
|
//!
|
||||||
//! fn index(info: Path<(String, u32)>) -> String {
|
//! fn index(info: Path<(String, u32)>) -> String {
|
||||||
//! format!("Hello {}! id:{}", info.0, info.1)
|
//! format!("Hello {}! id:{}", info.0, info.1)
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! fn main() {
|
//! fn main() {
|
||||||
//! # thread::spawn(|| {
|
//! //#### # thread::spawn(|| {
|
||||||
//! server::new(
|
//! server::new(|| {
|
||||||
//! || App::new()
|
//! App::new().resource("/{name}/{id}/index.html", |r| r.with(index))
|
||||||
//! .resource("/{name}/{id}/index.html", |r| r.with(index)))
|
//! }).bind("127.0.0.1:8080")
|
||||||
//! .bind("127.0.0.1:8080").unwrap()
|
//! .unwrap()
|
||||||
//! .run();
|
//! .run();
|
||||||
//! # });
|
//! //#### # });
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
@ -198,13 +198,13 @@ pub use scope::Scope;
|
|||||||
pub mod actix {
|
pub mod actix {
|
||||||
//! Re-exports [actix's](https://docs.rs/actix) prelude
|
//! Re-exports [actix's](https://docs.rs/actix) prelude
|
||||||
|
|
||||||
|
pub use actix_inner::actors::resolver;
|
||||||
|
pub use actix_inner::actors::signal;
|
||||||
|
pub use actix_inner::fut;
|
||||||
|
pub use actix_inner::msgs;
|
||||||
pub use actix_inner::prelude::*;
|
pub use actix_inner::prelude::*;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
#[deprecated(since = "0.6.2", note = "please use `use actix_web::ws::WsWriter`")]
|
|
||||||
pub use ws::WsWriter;
|
|
||||||
|
|
||||||
#[cfg(feature = "openssl")]
|
#[cfg(feature = "openssl")]
|
||||||
pub(crate) const HAS_OPENSSL: bool = true;
|
pub(crate) const HAS_OPENSSL: bool = true;
|
||||||
#[cfg(not(feature = "openssl"))]
|
#[cfg(not(feature = "openssl"))]
|
||||||
|
@ -32,8 +32,7 @@
|
|||||||
//! session data.
|
//! session data.
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! # extern crate actix;
|
//! //#### # extern crate actix_web;
|
||||||
//! # extern crate actix_web;
|
|
||||||
//! use actix_web::{server, App, HttpRequest, Result};
|
//! use actix_web::{server, App, HttpRequest, Result};
|
||||||
//! use actix_web::middleware::session::{RequestSession, SessionStorage, CookieSessionBackend};
|
//! use actix_web::middleware::session::{RequestSession, SessionStorage, CookieSessionBackend};
|
||||||
//!
|
//!
|
||||||
@ -59,7 +58,7 @@
|
|||||||
//! )))
|
//! )))
|
||||||
//! .bind("127.0.0.1:59880").unwrap()
|
//! .bind("127.0.0.1:59880").unwrap()
|
||||||
//! .start();
|
//! .start();
|
||||||
//! # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
|
//! //#### # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
|
||||||
//! });
|
//! });
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
@ -88,13 +87,13 @@ use middleware::{Middleware, Response, Started};
|
|||||||
/// The helper trait to obtain your session data from a request.
|
/// The helper trait to obtain your session data from a request.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use actix_web::*;
|
|
||||||
/// use actix_web::middleware::session::RequestSession;
|
/// use actix_web::middleware::session::RequestSession;
|
||||||
|
/// use actix_web::*;
|
||||||
///
|
///
|
||||||
/// fn index(mut req: HttpRequest) -> Result<&'static str> {
|
/// fn index(mut req: HttpRequest) -> Result<&'static str> {
|
||||||
/// // access session data
|
/// // access session data
|
||||||
/// if let Some(count) = req.session().get::<i32>("counter")? {
|
/// if let Some(count) = req.session().get::<i32>("counter")? {
|
||||||
/// req.session().set("counter", count+1)?;
|
/// req.session().set("counter", count + 1)?;
|
||||||
/// } else {
|
/// } else {
|
||||||
/// req.session().set("counter", 1)?;
|
/// req.session().set("counter", 1)?;
|
||||||
/// }
|
/// }
|
||||||
@ -123,13 +122,13 @@ impl<S> RequestSession for HttpRequest<S> {
|
|||||||
/// method. `RequestSession` trait is implemented for `HttpRequest`.
|
/// method. `RequestSession` trait is implemented for `HttpRequest`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use actix_web::*;
|
|
||||||
/// use actix_web::middleware::session::RequestSession;
|
/// use actix_web::middleware::session::RequestSession;
|
||||||
|
/// use actix_web::*;
|
||||||
///
|
///
|
||||||
/// fn index(mut req: HttpRequest) -> Result<&'static str> {
|
/// fn index(mut req: HttpRequest) -> Result<&'static str> {
|
||||||
/// // access session data
|
/// // access session data
|
||||||
/// if let Some(count) = req.session().get::<i32>("counter")? {
|
/// if let Some(count) = req.session().get::<i32>("counter")? {
|
||||||
/// req.session().set("counter", count+1)?;
|
/// req.session().set("counter", count + 1)?;
|
||||||
/// } else {
|
/// } else {
|
||||||
/// req.session().set("counter", 1)?;
|
/// req.session().set("counter", 1)?;
|
||||||
/// }
|
/// }
|
||||||
@ -200,7 +199,7 @@ impl Session {
|
|||||||
/// fn index(session: Session) -> Result<&'static str> {
|
/// fn index(session: Session) -> Result<&'static str> {
|
||||||
/// // access session data
|
/// // access session data
|
||||||
/// if let Some(count) = session.get::<i32>("counter")? {
|
/// if let Some(count) = session.get::<i32>("counter")? {
|
||||||
/// session.set("counter", count+1)?;
|
/// session.set("counter", count + 1)?;
|
||||||
/// } else {
|
/// } else {
|
||||||
/// session.set("counter", 1)?;
|
/// session.set("counter", 1)?;
|
||||||
/// }
|
/// }
|
||||||
@ -230,15 +229,15 @@ unsafe impl Sync for SessionImplCell {}
|
|||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # extern crate actix_web;
|
/// # extern crate actix_web;
|
||||||
|
/// use actix_web::middleware::session::{CookieSessionBackend, SessionStorage};
|
||||||
/// use actix_web::App;
|
/// use actix_web::App;
|
||||||
/// use actix_web::middleware::session::{SessionStorage, CookieSessionBackend};
|
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// let app = App::new().middleware(
|
/// let app = App::new().middleware(SessionStorage::new(
|
||||||
/// SessionStorage::new( // <- create session middleware
|
/// // <- create session middleware
|
||||||
/// CookieSessionBackend::signed(&[0; 32]) // <- create cookie session backend
|
/// CookieSessionBackend::signed(&[0; 32]) // <- create cookie session backend
|
||||||
/// .secure(false))
|
/// .secure(false),
|
||||||
/// );
|
/// ));
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub struct SessionStorage<T, S>(T, PhantomData<S>);
|
pub struct SessionStorage<T, S>(T, PhantomData<S>);
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
//! Http server
|
//! Http server
|
||||||
extern crate actix;
|
|
||||||
|
|
||||||
use std::net::Shutdown;
|
use std::net::Shutdown;
|
||||||
use std::{io, time};
|
use std::{io, time};
|
||||||
|
|
||||||
@ -29,6 +27,7 @@ pub use self::srv::HttpServer;
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use self::helpers::write_content_length;
|
pub use self::helpers::write_content_length;
|
||||||
|
|
||||||
|
use actix::Message;
|
||||||
use body::Binary;
|
use body::Binary;
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use header::ContentEncoding;
|
use header::ContentEncoding;
|
||||||
@ -43,9 +42,8 @@ pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536;
|
|||||||
/// This is shortcut for `server::HttpServer::new()` method.
|
/// This is shortcut for `server::HttpServer::new()` method.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # extern crate actix_web;
|
/// //#### # extern crate actix_web;
|
||||||
/// use actix_web::actix::*;
|
/// use actix_web::{actix, server, App, HttpResponse};
|
||||||
/// use actix_web::{server, App, HttpResponse};
|
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// actix::System::run(|| {
|
/// actix::System::run(|| {
|
||||||
@ -56,7 +54,7 @@ pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536;
|
|||||||
/// .bind("127.0.0.1:59090").unwrap()
|
/// .bind("127.0.0.1:59090").unwrap()
|
||||||
/// .start();
|
/// .start();
|
||||||
///
|
///
|
||||||
/// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
|
/// //#### # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
|
||||||
/// });
|
/// });
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
@ -116,7 +114,7 @@ pub struct StopServer {
|
|||||||
pub graceful: bool,
|
pub graceful: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl actix::Message for StopServer {
|
impl Message for StopServer {
|
||||||
type Result = Result<(), ()>;
|
type Result = Result<(), ()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
extern crate actix;
|
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::{mpsc as sync_mpsc, Arc};
|
use std::sync::{mpsc as sync_mpsc, Arc};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::{io, net, thread};
|
use std::{io, net, thread};
|
||||||
|
|
||||||
use self::actix::actors::signal;
|
use actix::{
|
||||||
use self::actix::prelude::*;
|
fut, msgs, signal, Actor, ActorFuture, Addr, Arbiter, AsyncContext, Context,
|
||||||
|
ContextFutureSpawner, Handler, Response, StreamHandler, System, WrapFuture,
|
||||||
|
};
|
||||||
|
|
||||||
use futures::sync::mpsc;
|
use futures::sync::mpsc;
|
||||||
use futures::{Future, Sink, Stream};
|
use futures::{Future, Sink, Stream};
|
||||||
use mio;
|
use mio;
|
||||||
@ -21,7 +22,7 @@ use native_tls::TlsAcceptor;
|
|||||||
#[cfg(feature = "alpn")]
|
#[cfg(feature = "alpn")]
|
||||||
use openssl::ssl::{AlpnError, SslAcceptorBuilder};
|
use openssl::ssl::{AlpnError, SslAcceptorBuilder};
|
||||||
|
|
||||||
use super::channel::{WrapperStream};
|
use super::channel::WrapperStream;
|
||||||
use super::settings::{ServerSettings, WorkerSettings};
|
use super::settings::{ServerSettings, WorkerSettings};
|
||||||
use super::worker::{Conn, SocketInfo, StopWorker, StreamHandlerType, Worker};
|
use super::worker::{Conn, SocketInfo, StopWorker, StreamHandlerType, Worker};
|
||||||
use super::{IntoHttpHandler, IoStream, KeepAlive};
|
use super::{IntoHttpHandler, IoStream, KeepAlive};
|
||||||
@ -408,20 +409,17 @@ impl<H: IntoHttpHandler> HttpServer<H> {
|
|||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// extern crate actix_web;
|
/// extern crate actix_web;
|
||||||
/// extern crate actix;
|
/// use actix_web::{actix, server, App, HttpResponse};
|
||||||
/// use actix_web::{server, App, HttpResponse};
|
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// // Run actix system, this method actually starts all async processes
|
/// // Run actix system, this method actually starts all async processes
|
||||||
/// actix::System::run(|| {
|
/// actix::System::run(|| {
|
||||||
///
|
/// server::new(|| App::new().resource("/", |r| r.h(|_| HttpResponse::Ok())))
|
||||||
/// server::new(
|
/// .bind("127.0.0.1:0")
|
||||||
/// || App::new()
|
/// .expect("Can not bind to 127.0.0.1:0")
|
||||||
/// .resource("/", |r| r.h(|_| HttpResponse::Ok())))
|
|
||||||
/// .bind("127.0.0.1:0").expect("Can not bind to 127.0.0.1:0")
|
|
||||||
/// .start();
|
/// .start();
|
||||||
/// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
|
/// //#### # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
|
||||||
/// });
|
/// });
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn start(mut self) -> Addr<Self> {
|
pub fn start(mut self) -> Addr<Self> {
|
||||||
@ -485,10 +483,9 @@ impl<H: IntoHttpHandler> HttpServer<H> {
|
|||||||
/// use actix_web::*;
|
/// use actix_web::*;
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// HttpServer::new(
|
/// HttpServer::new(|| App::new().resource("/", |r| r.h(|_| HttpResponse::Ok())))
|
||||||
/// || App::new()
|
/// .bind("127.0.0.1:0")
|
||||||
/// .resource("/", |r| r.h(|_| HttpResponse::Ok())))
|
/// .expect("Can not bind to 127.0.0.1:0")
|
||||||
/// .bind("127.0.0.1:0").expect("Can not bind to 127.0.0.1:0")
|
|
||||||
/// .run();
|
/// .run();
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
@ -723,7 +720,7 @@ impl<H: IntoHttpHandler> Handler<ResumeServer> for HttpServer<H> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<H: IntoHttpHandler> Handler<StopServer> for HttpServer<H> {
|
impl<H: IntoHttpHandler> Handler<StopServer> for HttpServer<H> {
|
||||||
type Result = actix::Response<(), ()>;
|
type Result = Response<(), ()>;
|
||||||
|
|
||||||
fn handle(&mut self, msg: StopServer, ctx: &mut Context<Self>) -> Self::Result {
|
fn handle(&mut self, msg: StopServer, ctx: &mut Context<Self>) -> Self::Result {
|
||||||
// stop accept threads
|
// stop accept threads
|
||||||
@ -754,11 +751,11 @@ impl<H: IntoHttpHandler> Handler<StopServer> for HttpServer<H> {
|
|||||||
// we need to stop system if server was spawned
|
// we need to stop system if server was spawned
|
||||||
if slf.exit {
|
if slf.exit {
|
||||||
ctx.run_later(Duration::from_millis(300), |_, _| {
|
ctx.run_later(Duration::from_millis(300), |_, _| {
|
||||||
Arbiter::system().do_send(actix::msgs::SystemExit(0))
|
Arbiter::system().do_send(msgs::SystemExit(0))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
actix::fut::ok(())
|
fut::ok(())
|
||||||
})
|
})
|
||||||
.spawn(ctx);
|
.spawn(ctx);
|
||||||
}
|
}
|
||||||
@ -769,7 +766,7 @@ impl<H: IntoHttpHandler> Handler<StopServer> for HttpServer<H> {
|
|||||||
// we need to stop system if server was spawned
|
// we need to stop system if server was spawned
|
||||||
if self.exit {
|
if self.exit {
|
||||||
ctx.run_later(Duration::from_millis(300), |_, _| {
|
ctx.run_later(Duration::from_millis(300), |_, _| {
|
||||||
Arbiter::system().do_send(actix::msgs::SystemExit(0))
|
Arbiter::system().do_send(msgs::SystemExit(0))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Response::reply(Ok(()))
|
Response::reply(Ok(()))
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
extern crate actix;
|
|
||||||
|
|
||||||
use futures::sync::oneshot;
|
use futures::sync::oneshot;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use net2::TcpStreamExt;
|
use net2::TcpStreamExt;
|
||||||
@ -23,8 +21,8 @@ use openssl::ssl::SslAcceptor;
|
|||||||
#[cfg(feature = "alpn")]
|
#[cfg(feature = "alpn")]
|
||||||
use tokio_openssl::SslAcceptorExt;
|
use tokio_openssl::SslAcceptorExt;
|
||||||
|
|
||||||
use self::actix::msgs::StopArbiter;
|
use actix::msgs::StopArbiter;
|
||||||
use self::actix::*;
|
use actix::{Actor, Arbiter, AsyncContext, Context, Handler, Message, Response};
|
||||||
|
|
||||||
use server::channel::HttpChannel;
|
use server::channel::HttpChannel;
|
||||||
use server::settings::WorkerSettings;
|
use server::settings::WorkerSettings;
|
||||||
|
12
src/test.rs
12
src/test.rs
@ -1,13 +1,11 @@
|
|||||||
//! Various helpers for Actix applications to use during testing.
|
//! Various helpers for Actix applications to use during testing.
|
||||||
|
|
||||||
extern crate actix;
|
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use std::{net, thread};
|
use std::{net, thread};
|
||||||
|
|
||||||
use self::actix::{msgs, Actor, Addr, Arbiter, System};
|
use actix_inner::{msgs, Actor, Addr, Arbiter, System};
|
||||||
|
|
||||||
use cookie::Cookie;
|
use cookie::Cookie;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use http::header::HeaderName;
|
use http::header::HeaderName;
|
||||||
@ -409,11 +407,11 @@ impl<S: 'static> Iterator for TestApp<S> {
|
|||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// let resp = TestRequest::with_header("content-type", "text/plain")
|
/// let resp = TestRequest::with_header("content-type", "text/plain")
|
||||||
/// .run(index).unwrap();
|
/// .run(index)
|
||||||
|
/// .unwrap();
|
||||||
/// assert_eq!(resp.status(), StatusCode::OK);
|
/// assert_eq!(resp.status(), StatusCode::OK);
|
||||||
///
|
///
|
||||||
/// let resp = TestRequest::default()
|
/// let resp = TestRequest::default().run(index).unwrap();
|
||||||
/// .run(index).unwrap();
|
|
||||||
/// assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
/// assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
//! Http client request
|
//! Http client request
|
||||||
extern crate actix;
|
|
||||||
|
|
||||||
use std::cell::UnsafeCell;
|
use std::cell::UnsafeCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@ -16,7 +14,7 @@ use http::{Error as HttpError, HttpTryFrom, StatusCode};
|
|||||||
use rand;
|
use rand;
|
||||||
use sha1::Sha1;
|
use sha1::Sha1;
|
||||||
|
|
||||||
use self::actix::prelude::*;
|
use actix::{Addr, SystemService};
|
||||||
|
|
||||||
use body::Binary;
|
use body::Binary;
|
||||||
use error::{Error, UrlParseError};
|
use error::{Error, UrlParseError};
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
//!
|
//!
|
||||||
//! // Handler for ws::Message messages
|
//! // Handler for ws::Message messages
|
||||||
//! impl StreamHandler<ws::Message, ws::ProtocolError> for Ws {
|
//! impl StreamHandler<ws::Message, ws::ProtocolError> for Ws {
|
||||||
//!
|
|
||||||
//! fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) {
|
//! fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) {
|
||||||
//! match msg {
|
//! match msg {
|
||||||
//! ws::Message::Ping(msg) => ctx.pong(&msg),
|
//! ws::Message::Ping(msg) => ctx.pong(&msg),
|
||||||
@ -42,13 +41,11 @@
|
|||||||
//! # .finish();
|
//! # .finish();
|
||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
extern crate actix;
|
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::{Async, Poll, Stream};
|
use futures::{Async, Poll, Stream};
|
||||||
use http::{header, Method, StatusCode};
|
use http::{header, Method, StatusCode};
|
||||||
|
|
||||||
use self::actix::{Actor, AsyncContext, StreamHandler};
|
use super::actix::{Actor, AsyncContext, StreamHandler};
|
||||||
|
|
||||||
use body::Binary;
|
use body::Binary;
|
||||||
use error::{Error, PayloadError, ResponseError};
|
use error::{Error, PayloadError, ResponseError};
|
||||||
|
Loading…
Reference in New Issue
Block a user