mirror of
https://github.com/actix/actix-extras.git
synced 2025-06-27 10:39:03 +02:00
upgrade to tokio 0.2
This commit is contained in:
@ -24,9 +24,10 @@
|
||||
//! );
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
#![allow(non_snake_case)]
|
||||
use actix_http::http::{self, header, uri::Uri, HttpTryFrom};
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use actix_http::http::{self, header, uri::Uri};
|
||||
use actix_http::RequestHead;
|
||||
|
||||
/// Trait defines resource guards. Guards are used for route selection.
|
||||
|
@ -76,7 +76,7 @@ impl ConnectionInfo {
|
||||
}
|
||||
}
|
||||
if scheme.is_none() {
|
||||
scheme = req.uri.scheme_part().map(|a| a.as_str());
|
||||
scheme = req.uri.scheme().map(|a| a.as_str());
|
||||
if scheme.is_none() && cfg.secure() {
|
||||
scheme = Some("https")
|
||||
}
|
||||
@ -98,7 +98,7 @@ impl ConnectionInfo {
|
||||
host = h.to_str().ok();
|
||||
}
|
||||
if host.is_none() {
|
||||
host = req.uri.authority_part().map(|a| a.as_str());
|
||||
host = req.uri.authority().map(|a| a.as_str());
|
||||
if host.is_none() {
|
||||
host = Some(cfg.host());
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
//! Middleware for setting default response headers
|
||||
use std::convert::TryFrom;
|
||||
use std::rc::Rc;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
@ -6,7 +7,7 @@ use actix_service::{Service, Transform};
|
||||
use futures::future::{ok, FutureExt, LocalBoxFuture, Ready};
|
||||
|
||||
use crate::http::header::{HeaderName, HeaderValue, CONTENT_TYPE};
|
||||
use crate::http::{HeaderMap, HttpTryFrom};
|
||||
use crate::http::{Error as HttpError, HeaderMap};
|
||||
use crate::service::{ServiceRequest, ServiceResponse};
|
||||
use crate::Error;
|
||||
|
||||
@ -58,8 +59,10 @@ impl DefaultHeaders {
|
||||
#[inline]
|
||||
pub fn header<K, V>(mut self, key: K, value: V) -> Self
|
||||
where
|
||||
HeaderName: HttpTryFrom<K>,
|
||||
HeaderValue: HttpTryFrom<V>,
|
||||
HeaderName: TryFrom<K>,
|
||||
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
|
||||
HeaderValue: TryFrom<V>,
|
||||
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
|
||||
{
|
||||
#[allow(clippy::match_wild_err_arm)]
|
||||
match HeaderName::try_from(key) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
//! Request logging middleware
|
||||
use std::collections::HashSet;
|
||||
use std::convert::TryFrom;
|
||||
use std::env;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::future::Future;
|
||||
@ -17,7 +18,7 @@ use time;
|
||||
|
||||
use crate::dev::{BodySize, MessageBody, ResponseBody};
|
||||
use crate::error::{Error, Result};
|
||||
use crate::http::{HeaderName, HttpTryFrom, StatusCode};
|
||||
use crate::http::{HeaderName, StatusCode};
|
||||
use crate::service::{ServiceRequest, ServiceResponse};
|
||||
use crate::HttpResponse;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! `Middleware` to normalize request's URI
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
use actix_http::http::{HttpTryFrom, PathAndQuery, Uri};
|
||||
use actix_http::http::{PathAndQuery, Uri};
|
||||
use actix_service::{Service, Transform};
|
||||
use bytes::Bytes;
|
||||
use futures::future::{ok, Ready};
|
||||
@ -74,7 +74,6 @@ where
|
||||
|
||||
fn call(&mut self, mut req: ServiceRequest) -> Self::Future {
|
||||
let head = req.head_mut();
|
||||
|
||||
let path = head.uri.path();
|
||||
let original_len = path.len();
|
||||
let path = self.merge_slash.replace_all(path, "/");
|
||||
@ -86,9 +85,10 @@ where
|
||||
let path = if let Some(q) = pq.query() {
|
||||
Bytes::from(format!("{}?{}", path, q))
|
||||
} else {
|
||||
Bytes::from(path.as_ref())
|
||||
Bytes::copy_from_slice(path.as_bytes())
|
||||
};
|
||||
parts.path_and_query = Some(PathAndQuery::try_from(path).unwrap());
|
||||
parts.path_and_query = Some(PathAndQuery::from_maybe_shared(path).unwrap());
|
||||
drop(head);
|
||||
|
||||
let uri = Uri::from_parts(parts).unwrap();
|
||||
req.match_info_mut().get_mut().update(&uri);
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::future::Future;
|
||||
use std::marker::PhantomData;
|
||||
use std::pin::Pin;
|
||||
@ -5,8 +6,7 @@ use std::task::{Context, Poll};
|
||||
|
||||
use actix_http::error::InternalError;
|
||||
use actix_http::http::{
|
||||
header::IntoHeaderValue, Error as HttpError, HeaderMap, HeaderName, HttpTryFrom,
|
||||
StatusCode,
|
||||
header::IntoHeaderValue, Error as HttpError, HeaderMap, HeaderName, StatusCode,
|
||||
};
|
||||
use actix_http::{Error, Response, ResponseBuilder};
|
||||
use bytes::{Bytes, BytesMut};
|
||||
@ -68,7 +68,8 @@ pub trait Responder {
|
||||
fn with_header<K, V>(self, key: K, value: V) -> CustomResponder<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
HeaderName: HttpTryFrom<K>,
|
||||
HeaderName: TryFrom<K>,
|
||||
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
|
||||
V: IntoHeaderValue,
|
||||
{
|
||||
CustomResponder::new(self).with_header(key, value)
|
||||
@ -267,7 +268,8 @@ impl<T: Responder> CustomResponder<T> {
|
||||
/// ```
|
||||
pub fn with_header<K, V>(mut self, key: K, value: V) -> Self
|
||||
where
|
||||
HeaderName: HttpTryFrom<K>,
|
||||
HeaderName: TryFrom<K>,
|
||||
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
|
||||
V: IntoHeaderValue,
|
||||
{
|
||||
if self.headers.is_none() {
|
||||
|
@ -14,9 +14,9 @@ use parking_lot::Mutex;
|
||||
use net2::TcpBuilder;
|
||||
|
||||
#[cfg(feature = "openssl")]
|
||||
use open_ssl::ssl::{SslAcceptor, SslAcceptorBuilder};
|
||||
use actix_tls::openssl::{SslAcceptor, SslAcceptorBuilder};
|
||||
#[cfg(feature = "rustls")]
|
||||
use rust_tls::ServerConfig as RustlsServerConfig;
|
||||
use actix_tls::rustls::ServerConfig as RustlsServerConfig;
|
||||
|
||||
struct Socket {
|
||||
scheme: &'static str,
|
||||
@ -315,15 +315,8 @@ where
|
||||
fn listen_rustls_inner(
|
||||
mut self,
|
||||
lst: net::TcpListener,
|
||||
mut config: RustlsServerConfig,
|
||||
config: RustlsServerConfig,
|
||||
) -> io::Result<Self> {
|
||||
use actix_server::ssl::{RustlsAcceptor, SslError};
|
||||
use actix_service::pipeline_factory;
|
||||
|
||||
let protos = vec!["h2".to_string().into(), "http/1.1".to_string().into()];
|
||||
config.set_protocols(&protos);
|
||||
|
||||
let acceptor = RustlsAcceptor::new(config);
|
||||
let factory = self.factory.clone();
|
||||
let cfg = self.config.clone();
|
||||
let addr = lst.local_addr().unwrap();
|
||||
@ -337,15 +330,12 @@ where
|
||||
lst,
|
||||
move || {
|
||||
let c = cfg.lock();
|
||||
pipeline_factory(acceptor.clone().map_err(SslError::Ssl)).and_then(
|
||||
HttpService::build()
|
||||
.keep_alive(c.keep_alive)
|
||||
.client_timeout(c.client_timeout)
|
||||
.client_disconnect(c.client_shutdown)
|
||||
.finish(factory())
|
||||
.map_err(SslError::Service)
|
||||
.map_init_err(|_| ()),
|
||||
)
|
||||
HttpService::build()
|
||||
.keep_alive(c.keep_alive)
|
||||
.client_timeout(c.client_timeout)
|
||||
.client_disconnect(c.client_shutdown)
|
||||
.finish(factory())
|
||||
.rustls(config.clone())
|
||||
},
|
||||
)?;
|
||||
Ok(self)
|
||||
@ -530,14 +520,13 @@ where
|
||||
/// use std::io;
|
||||
/// use actix_web::{web, App, HttpResponse, HttpServer};
|
||||
///
|
||||
/// fn main() -> io::Result<()> {
|
||||
/// let sys = actix_rt::System::new("example"); // <- create Actix system
|
||||
///
|
||||
/// #[actix_rt::main]
|
||||
/// async fn main() -> io::Result<()> {
|
||||
/// # actix_rt::System::current().stop();
|
||||
/// HttpServer::new(|| App::new().service(web::resource("/").to(|| HttpResponse::Ok())))
|
||||
/// .bind("127.0.0.1:0")?
|
||||
/// .start();
|
||||
/// # actix_rt::System::current().stop();
|
||||
/// sys.run() // <- Run actix system, this method starts all async processes
|
||||
/// .start()
|
||||
/// .await
|
||||
/// }
|
||||
/// ```
|
||||
pub fn start(self) -> Server {
|
||||
|
@ -1,8 +1,9 @@
|
||||
//! Various helpers for Actix applications to use during testing.
|
||||
use std::convert::TryFrom;
|
||||
use std::rc::Rc;
|
||||
|
||||
use actix_http::http::header::{ContentType, Header, HeaderName, IntoHeaderValue};
|
||||
use actix_http::http::{HttpTryFrom, Method, StatusCode, Uri, Version};
|
||||
use actix_http::http::{Error as HttpError, Method, StatusCode, Uri, Version};
|
||||
use actix_http::test::TestRequest as HttpTestRequest;
|
||||
use actix_http::{cookie::Cookie, Extensions, Request};
|
||||
use actix_router::{Path, ResourceDef, Url};
|
||||
@ -319,7 +320,8 @@ impl TestRequest {
|
||||
/// Create TestRequest and set header
|
||||
pub fn with_header<K, V>(key: K, value: V) -> TestRequest
|
||||
where
|
||||
HeaderName: HttpTryFrom<K>,
|
||||
HeaderName: TryFrom<K>,
|
||||
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
|
||||
V: IntoHeaderValue,
|
||||
{
|
||||
TestRequest::default().header(key, value)
|
||||
@ -377,7 +379,8 @@ impl TestRequest {
|
||||
/// Set a header
|
||||
pub fn header<K, V>(mut self, key: K, value: V) -> Self
|
||||
where
|
||||
HeaderName: HttpTryFrom<K>,
|
||||
HeaderName: TryFrom<K>,
|
||||
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
|
||||
V: IntoHeaderValue,
|
||||
{
|
||||
self.req.header(key, value);
|
||||
|
Reference in New Issue
Block a user