mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 00:21:08 +01:00
Run rustfmt
This commit is contained in:
parent
fe89ba7027
commit
6dd78d9355
@ -474,13 +474,15 @@ where
|
||||
mod tests {
|
||||
use actix_service::Service;
|
||||
use bytes::Bytes;
|
||||
use futures_util::future::{ok, err};
|
||||
use futures_util::future::{err, ok};
|
||||
|
||||
use super::*;
|
||||
use crate::http::{header, HeaderValue, Method, StatusCode};
|
||||
use crate::middleware::DefaultHeaders;
|
||||
use crate::service::ServiceRequest;
|
||||
use crate::test::{call_service, init_service, try_init_service, read_body, TestRequest};
|
||||
use crate::test::{
|
||||
call_service, init_service, read_body, try_init_service, TestRequest,
|
||||
};
|
||||
use crate::{web, HttpRequest, HttpResponse};
|
||||
|
||||
#[actix_rt::test]
|
||||
@ -556,7 +558,7 @@ mod tests {
|
||||
web::resource("/").to(|_: web::Data<usize>| HttpResponse::Ok()),
|
||||
))
|
||||
.await;
|
||||
|
||||
|
||||
assert!(srv.is_err());
|
||||
}
|
||||
|
||||
|
@ -273,13 +273,15 @@ impl<B> PinnedDrop for StreamLog<B> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<B: MessageBody> MessageBody for StreamLog<B> {
|
||||
fn size(&self) -> BodySize {
|
||||
self.body.size()
|
||||
}
|
||||
|
||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Result<Bytes, Error>>> {
|
||||
fn poll_next(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<Option<Result<Bytes, Error>>> {
|
||||
let this = self.project();
|
||||
match this.body.poll_next(cx) {
|
||||
Poll::Ready(Some(Ok(chunk))) => {
|
||||
@ -324,11 +326,13 @@ impl Format {
|
||||
|
||||
if let Some(key) = cap.get(2) {
|
||||
results.push(match cap.get(3).unwrap().as_str() {
|
||||
"a" => if key.as_str() == "r" {
|
||||
FormatText::RealIPRemoteAddr
|
||||
} else {
|
||||
unreachable!()
|
||||
},
|
||||
"a" => {
|
||||
if key.as_str() == "r" {
|
||||
FormatText::RealIPRemoteAddr
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
"i" => FormatText::RequestHeader(
|
||||
HeaderName::try_from(key.as_str()).unwrap(),
|
||||
),
|
||||
@ -481,7 +485,8 @@ impl FormatText {
|
||||
*self = s;
|
||||
}
|
||||
FormatText::RealIPRemoteAddr => {
|
||||
let s = if let Some(remote) = req.connection_info().realip_remote_addr() {
|
||||
let s = if let Some(remote) = req.connection_info().realip_remote_addr()
|
||||
{
|
||||
FormatText::Str(remote.to_string())
|
||||
} else {
|
||||
FormatText::Str("-".to_string())
|
||||
@ -630,7 +635,9 @@ mod tests {
|
||||
|
||||
let req = TestRequest::with_header(
|
||||
header::FORWARDED,
|
||||
header::HeaderValue::from_static("for=192.0.2.60;proto=http;by=203.0.113.43"),
|
||||
header::HeaderValue::from_static(
|
||||
"for=192.0.2.60;proto=http;by=203.0.113.43",
|
||||
),
|
||||
)
|
||||
.to_srv_request();
|
||||
|
||||
|
@ -74,7 +74,7 @@ where
|
||||
|
||||
fn call(&mut self, mut req: ServiceRequest) -> Self::Future {
|
||||
let head = req.head_mut();
|
||||
|
||||
|
||||
// always add trailing slash, might be an extra one
|
||||
let path = head.uri.path().to_string() + "/";
|
||||
let original_len = path.len();
|
||||
@ -177,7 +177,7 @@ mod tests {
|
||||
assert!(res.status().is_success());
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
#[actix_rt::test]
|
||||
async fn should_normalize_nothing_notrail() {
|
||||
const URI: &str = "/v1/something";
|
||||
|
||||
|
34
src/route.rs
34
src/route.rs
@ -362,31 +362,23 @@ mod tests {
|
||||
.service(
|
||||
web::resource("/test")
|
||||
.route(web::get().to(|| HttpResponse::Ok()))
|
||||
.route(web::put().to(|| {
|
||||
async {
|
||||
Err::<HttpResponse, _>(error::ErrorBadRequest("err"))
|
||||
}
|
||||
.route(web::put().to(|| async {
|
||||
Err::<HttpResponse, _>(error::ErrorBadRequest("err"))
|
||||
}))
|
||||
.route(web::post().to(|| {
|
||||
async {
|
||||
delay_for(Duration::from_millis(100)).await;
|
||||
HttpResponse::Created()
|
||||
}
|
||||
.route(web::post().to(|| async {
|
||||
delay_for(Duration::from_millis(100)).await;
|
||||
HttpResponse::Created()
|
||||
}))
|
||||
.route(web::delete().to(|| {
|
||||
async {
|
||||
delay_for(Duration::from_millis(100)).await;
|
||||
Err::<HttpResponse, _>(error::ErrorBadRequest("err"))
|
||||
}
|
||||
.route(web::delete().to(|| async {
|
||||
delay_for(Duration::from_millis(100)).await;
|
||||
Err::<HttpResponse, _>(error::ErrorBadRequest("err"))
|
||||
})),
|
||||
)
|
||||
.service(web::resource("/json").route(web::get().to(|| {
|
||||
async {
|
||||
delay_for(Duration::from_millis(25)).await;
|
||||
web::Json(MyObject {
|
||||
name: "test".to_string(),
|
||||
})
|
||||
}
|
||||
.service(web::resource("/json").route(web::get().to(|| async {
|
||||
delay_for(Duration::from_millis(25)).await;
|
||||
web::Json(MyObject {
|
||||
name: "test".to_string(),
|
||||
})
|
||||
}))),
|
||||
)
|
||||
.await;
|
||||
|
@ -89,7 +89,9 @@ where
|
||||
>,
|
||||
S::InitError: std::fmt::Debug,
|
||||
{
|
||||
try_init_service(app).await.expect("service initilization failed")
|
||||
try_init_service(app)
|
||||
.await
|
||||
.expect("service initilization failed")
|
||||
}
|
||||
|
||||
/// Fallible version of init_service that allows testing data factory errors.
|
||||
@ -913,7 +915,8 @@ impl TestServerConfig {
|
||||
/// Get first available unused address
|
||||
pub fn unused_addr() -> net::SocketAddr {
|
||||
let addr: net::SocketAddr = "127.0.0.1:0".parse().unwrap();
|
||||
let socket = Socket::new(Domain::ipv4(), Type::stream(), Some(Protocol::tcp())).unwrap();
|
||||
let socket =
|
||||
Socket::new(Domain::ipv4(), Type::stream(), Some(Protocol::tcp())).unwrap();
|
||||
socket.bind(&addr.into()).unwrap();
|
||||
socket.set_reuse_address(true).unwrap();
|
||||
let tcp = socket.into_tcp_listener();
|
||||
|
@ -349,9 +349,10 @@ async fn test_body_br_streaming() {
|
||||
#[actix_rt::test]
|
||||
async fn test_head_binary() {
|
||||
let srv = test::start_with(test::config().h1(), || {
|
||||
App::new().service(web::resource("/").route(
|
||||
web::head().to(move || HttpResponse::Ok().body(STR)),
|
||||
))
|
||||
App::new().service(
|
||||
web::resource("/")
|
||||
.route(web::head().to(move || HttpResponse::Ok().body(STR))),
|
||||
)
|
||||
});
|
||||
|
||||
let mut response = srv.head("/").send().await.unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user