mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-26 06:57:43 +02:00
apply standard formatting
This commit is contained in:
@ -12,19 +12,18 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use actix_http::{HttpService, StatusCode};
|
||||
use actix_http_test::test_server;
|
||||
use actix_service::{fn_service, map_config, ServiceFactoryExt as _};
|
||||
use actix_utils::future::ok;
|
||||
use actix_web::{dev::AppConfig, http::header, web, App, Error, HttpRequest, HttpResponse};
|
||||
use awc::error::{JsonPayloadError, PayloadError, SendRequestError};
|
||||
use base64::prelude::*;
|
||||
use bytes::Bytes;
|
||||
use cookie::Cookie;
|
||||
use futures_util::stream;
|
||||
use rand::Rng;
|
||||
|
||||
use actix_http::{HttpService, StatusCode};
|
||||
use actix_http_test::test_server;
|
||||
use actix_service::{fn_service, map_config, ServiceFactoryExt as _};
|
||||
use actix_web::{dev::AppConfig, http::header, web, App, Error, HttpRequest, HttpResponse};
|
||||
use awc::error::{JsonPayloadError, PayloadError, SendRequestError};
|
||||
|
||||
mod utils;
|
||||
|
||||
const S: &str = "Hello World ";
|
||||
@ -33,9 +32,8 @@ const STR: &str = const_str::repeat!(S, 100);
|
||||
#[actix_rt::test]
|
||||
async fn simple() {
|
||||
let srv = actix_test::start(|| {
|
||||
App::new().service(
|
||||
web::resource("/").route(web::to(|| async { HttpResponse::Ok().body(STR) })),
|
||||
)
|
||||
App::new()
|
||||
.service(web::resource("/").route(web::to(|| async { HttpResponse::Ok().body(STR) })))
|
||||
});
|
||||
|
||||
let request = srv.get("/").insert_header(("x-test", "111")).send();
|
||||
@ -61,9 +59,8 @@ async fn simple() {
|
||||
#[actix_rt::test]
|
||||
async fn json() {
|
||||
let srv = actix_test::start(|| {
|
||||
App::new().service(
|
||||
web::resource("/").route(web::to(|_: web::Json<String>| HttpResponse::Ok())),
|
||||
)
|
||||
App::new()
|
||||
.service(web::resource("/").route(web::to(|_: web::Json<String>| HttpResponse::Ok())))
|
||||
});
|
||||
|
||||
let request = srv
|
||||
@ -340,8 +337,7 @@ async fn connection_wait_queue() {
|
||||
.and_then(
|
||||
HttpService::new(map_config(
|
||||
App::new().service(
|
||||
web::resource("/")
|
||||
.route(web::to(|| async { HttpResponse::Ok().body(STR) })),
|
||||
web::resource("/").route(web::to(|| async { HttpResponse::Ok().body(STR) })),
|
||||
),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
@ -449,9 +445,7 @@ async fn no_decompress() {
|
||||
let srv = actix_test::start(|| {
|
||||
App::new()
|
||||
.wrap(actix_web::middleware::Compress::default())
|
||||
.service(
|
||||
web::resource("/").route(web::to(|| async { HttpResponse::Ok().body(STR) })),
|
||||
)
|
||||
.service(web::resource("/").route(web::to(|| async { HttpResponse::Ok().body(STR) })))
|
||||
});
|
||||
|
||||
let mut res = awc::Client::new()
|
||||
@ -833,12 +827,12 @@ async fn local_address() {
|
||||
let ip = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
|
||||
|
||||
let srv = actix_test::start(move || {
|
||||
App::new().service(web::resource("/").route(web::to(
|
||||
move |req: HttpRequest| async move {
|
||||
App::new().service(
|
||||
web::resource("/").route(web::to(move |req: HttpRequest| async move {
|
||||
assert_eq!(req.peer_addr().unwrap().ip(), ip);
|
||||
Ok::<_, Error>(HttpResponse::Ok())
|
||||
},
|
||||
)))
|
||||
})),
|
||||
)
|
||||
});
|
||||
let client = awc::Client::builder().local_address(ip).finish();
|
||||
|
||||
|
@ -5,8 +5,7 @@ extern crate tls_openssl as openssl;
|
||||
use actix_http::HttpService;
|
||||
use actix_http_test::test_server;
|
||||
use actix_service::{map_config, ServiceFactoryExt};
|
||||
use actix_web::http::Version;
|
||||
use actix_web::{dev::AppConfig, web, App, HttpResponse};
|
||||
use actix_web::{dev::AppConfig, http::Version, web, App, HttpResponse};
|
||||
use openssl::{
|
||||
pkey::PKey,
|
||||
ssl::{SslAcceptor, SslConnector, SslMethod, SslVerifyMode},
|
||||
|
@ -2,15 +2,16 @@
|
||||
|
||||
extern crate tls_openssl as openssl;
|
||||
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::sync::{
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
Arc,
|
||||
};
|
||||
|
||||
use actix_http::HttpService;
|
||||
use actix_http_test::test_server;
|
||||
use actix_service::{fn_service, map_config, ServiceFactoryExt};
|
||||
use actix_utils::future::ok;
|
||||
use actix_web::http::Version;
|
||||
use actix_web::{dev::AppConfig, web, App, HttpResponse};
|
||||
use actix_web::{dev::AppConfig, http::Version, web, App, HttpResponse};
|
||||
use openssl::{
|
||||
pkey::PKey,
|
||||
ssl::{SslAcceptor, SslConnector, SslMethod, SslVerifyMode},
|
||||
|
@ -4,9 +4,10 @@
|
||||
use std::io::{Read as _, Write as _};
|
||||
|
||||
pub mod gzip {
|
||||
use super::*;
|
||||
use flate2::{read::GzDecoder, write::GzEncoder, Compression};
|
||||
|
||||
use super::*;
|
||||
|
||||
pub fn encode(bytes: impl AsRef<[u8]>) -> Vec<u8> {
|
||||
let mut encoder = GzEncoder::new(Vec::new(), Compression::fast());
|
||||
encoder.write_all(bytes.as_ref()).unwrap();
|
||||
@ -22,9 +23,10 @@ pub mod gzip {
|
||||
}
|
||||
|
||||
pub mod deflate {
|
||||
use super::*;
|
||||
use flate2::{read::ZlibDecoder, write::ZlibEncoder, Compression};
|
||||
|
||||
use super::*;
|
||||
|
||||
pub fn encode(bytes: impl AsRef<[u8]>) -> Vec<u8> {
|
||||
let mut encoder = ZlibEncoder::new(Vec::new(), Compression::fast());
|
||||
encoder.write_all(bytes.as_ref()).unwrap();
|
||||
@ -40,9 +42,10 @@ pub mod deflate {
|
||||
}
|
||||
|
||||
pub mod brotli {
|
||||
use super::*;
|
||||
use ::brotli::{reader::Decompressor as BrotliDecoder, CompressorWriter as BrotliEncoder};
|
||||
|
||||
use super::*;
|
||||
|
||||
pub fn encode(bytes: impl AsRef<[u8]>) -> Vec<u8> {
|
||||
let mut encoder = BrotliEncoder::new(
|
||||
Vec::new(),
|
||||
@ -64,9 +67,10 @@ pub mod brotli {
|
||||
}
|
||||
|
||||
pub mod zstd {
|
||||
use super::*;
|
||||
use ::zstd::stream::{read::Decoder, write::Encoder};
|
||||
|
||||
use super::*;
|
||||
|
||||
pub fn encode(bytes: impl AsRef<[u8]>) -> Vec<u8> {
|
||||
let mut encoder = Encoder::new(Vec::new(), 3).unwrap();
|
||||
encoder.write_all(bytes.as_ref()).unwrap();
|
||||
|
Reference in New Issue
Block a user