mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-23 16:21:06 +01:00
Check format and tweak CI config (#1619)
This commit is contained in:
parent
701bdacfa2
commit
92b5bcd13f
1
.github/PULL_REQUEST_TEMPLATE.md
vendored
1
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -15,6 +15,7 @@ Check your PR fulfills the following:
|
||||
- [ ] Tests for the changes have been added / updated.
|
||||
- [ ] Documentation comments have been added / updated.
|
||||
- [ ] A changelog entry has been made for the appropriate packages.
|
||||
- [ ] Format code with the latest stable rustfmt
|
||||
|
||||
|
||||
## Overview
|
||||
|
7
.github/workflows/bench.yml
vendored
7
.github/workflows/bench.yml
vendored
@ -1,6 +1,11 @@
|
||||
name: Benchmark (Linux)
|
||||
|
||||
on: [push, pull_request]
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
check_benchmark:
|
||||
|
32
.github/workflows/clippy-fmt.yml
vendored
Normal file
32
.github/workflows/clippy-fmt.yml
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
name: Clippy and rustfmt Check
|
||||
jobs:
|
||||
clippy_check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
components: rustfmt
|
||||
override: true
|
||||
- name: Check with rustfmt
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: fmt
|
||||
args: --all -- --check
|
||||
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: nightly
|
||||
components: clippy
|
||||
override: true
|
||||
- name: Check with Clippy
|
||||
uses: actions-rs/clippy-check@v1
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
args: --all-features --all --tests
|
7
.github/workflows/linux.yml
vendored
7
.github/workflows/linux.yml
vendored
@ -1,6 +1,11 @@
|
||||
name: CI (Linux)
|
||||
|
||||
on: [push, pull_request]
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build_and_test:
|
||||
|
7
.github/workflows/macos.yml
vendored
7
.github/workflows/macos.yml
vendored
@ -1,6 +1,11 @@
|
||||
name: CI (macOS)
|
||||
|
||||
on: [push, pull_request]
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build_and_test:
|
||||
|
7
.github/workflows/windows.yml
vendored
7
.github/workflows/windows.yml
vendored
@ -1,6 +1,11 @@
|
||||
name: CI (Windows)
|
||||
|
||||
on: [push, pull_request]
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
env:
|
||||
VCPKGRS_DYNAMIC: 1
|
||||
|
@ -26,7 +26,6 @@ use actix_web::{web, FromRequest, HttpRequest, HttpResponse};
|
||||
use bytes::Bytes;
|
||||
use futures_core::Stream;
|
||||
use futures_util::future::{ok, ready, Either, FutureExt, LocalBoxFuture, Ready};
|
||||
use mime;
|
||||
use mime_guess::from_ext;
|
||||
use percent_encoding::{utf8_percent_encode, CONTROLS};
|
||||
use v_htmlescape::escape as escape_html_entity;
|
||||
@ -250,6 +249,8 @@ pub struct Files {
|
||||
renderer: Rc<DirectoryRenderer>,
|
||||
mime_override: Option<Rc<MimeOverride>>,
|
||||
file_flags: named::Flags,
|
||||
// FIXME: Should re-visit later.
|
||||
#[allow(clippy::redundant_allocation)]
|
||||
guards: Option<Rc<Box<dyn Guard>>>,
|
||||
}
|
||||
|
||||
@ -462,6 +463,8 @@ pub struct FilesService {
|
||||
renderer: Rc<DirectoryRenderer>,
|
||||
mime_override: Option<Rc<MimeOverride>>,
|
||||
file_flags: named::Flags,
|
||||
// FIXME: Should re-visit later.
|
||||
#[allow(clippy::redundant_allocation)]
|
||||
guards: Option<Rc<Box<dyn Guard>>>,
|
||||
}
|
||||
|
||||
@ -501,11 +504,8 @@ impl Service for FilesService {
|
||||
// execute user defined guards
|
||||
(**guard).check(req.head())
|
||||
} else {
|
||||
// default behaviour
|
||||
match *req.method() {
|
||||
Method::HEAD | Method::GET => true,
|
||||
_ => false,
|
||||
}
|
||||
// default behavior
|
||||
matches!(*req.method(), Method::HEAD | Method::GET)
|
||||
};
|
||||
|
||||
if !is_method_valid {
|
||||
@ -952,9 +952,7 @@ mod tests {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_named_file_content_range_headers() {
|
||||
let srv = test::start(|| {
|
||||
App::new().service(Files::new("/", "."))
|
||||
});
|
||||
let srv = test::start(|| App::new().service(Files::new("/", ".")));
|
||||
|
||||
// Valid range header
|
||||
let response = srv
|
||||
@ -979,9 +977,7 @@ mod tests {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_named_file_content_length_headers() {
|
||||
let srv = test::start(|| {
|
||||
App::new().service(Files::new("/", "."))
|
||||
});
|
||||
let srv = test::start(|| App::new().service(Files::new("/", ".")));
|
||||
|
||||
// Valid range header
|
||||
let response = srv
|
||||
@ -1020,15 +1016,9 @@ mod tests {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_head_content_length_headers() {
|
||||
let srv = test::start(|| {
|
||||
App::new().service(Files::new("/", "."))
|
||||
});
|
||||
let srv = test::start(|| App::new().service(Files::new("/", ".")));
|
||||
|
||||
let response = srv
|
||||
.head("/tests/test.binary")
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
let response = srv.head("/tests/test.binary").send().await.unwrap();
|
||||
|
||||
let content_length = response
|
||||
.headers()
|
||||
@ -1097,12 +1087,10 @@ mod tests {
|
||||
#[actix_rt::test]
|
||||
async fn test_named_file_content_encoding() {
|
||||
let mut srv = test::init_service(App::new().wrap(Compress::default()).service(
|
||||
web::resource("/").to(|| {
|
||||
async {
|
||||
NamedFile::open("Cargo.toml")
|
||||
.unwrap()
|
||||
.set_content_encoding(header::ContentEncoding::Identity)
|
||||
}
|
||||
web::resource("/").to(|| async {
|
||||
NamedFile::open("Cargo.toml")
|
||||
.unwrap()
|
||||
.set_content_encoding(header::ContentEncoding::Identity)
|
||||
}),
|
||||
))
|
||||
.await;
|
||||
@ -1119,12 +1107,10 @@ mod tests {
|
||||
#[actix_rt::test]
|
||||
async fn test_named_file_content_encoding_gzip() {
|
||||
let mut srv = test::init_service(App::new().wrap(Compress::default()).service(
|
||||
web::resource("/").to(|| {
|
||||
async {
|
||||
NamedFile::open("Cargo.toml")
|
||||
.unwrap()
|
||||
.set_content_encoding(header::ContentEncoding::Gzip)
|
||||
}
|
||||
web::resource("/").to(|| async {
|
||||
NamedFile::open("Cargo.toml")
|
||||
.unwrap()
|
||||
.set_content_encoding(header::ContentEncoding::Gzip)
|
||||
}),
|
||||
))
|
||||
.await;
|
||||
|
@ -8,7 +8,6 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
|
||||
use bitflags::bitflags;
|
||||
use mime;
|
||||
use mime_guess::from_path;
|
||||
|
||||
use actix_http::body::SizedStream;
|
||||
@ -90,7 +89,7 @@ impl NamedFile {
|
||||
};
|
||||
|
||||
let ct = from_path(&path).first_or_octet_stream();
|
||||
let disposition_type = match ct.type_() {
|
||||
let disposition = match ct.type_() {
|
||||
mime::IMAGE | mime::TEXT | mime::VIDEO => DispositionType::Inline,
|
||||
_ => DispositionType::Attachment,
|
||||
};
|
||||
@ -104,8 +103,8 @@ impl NamedFile {
|
||||
}))
|
||||
}
|
||||
let cd = ContentDisposition {
|
||||
disposition: disposition_type,
|
||||
parameters: parameters,
|
||||
disposition,
|
||||
parameters,
|
||||
};
|
||||
(ct, cd)
|
||||
};
|
||||
|
@ -21,12 +21,7 @@ pub enum BodySize {
|
||||
|
||||
impl BodySize {
|
||||
pub fn is_eof(&self) -> bool {
|
||||
match self {
|
||||
BodySize::None
|
||||
| BodySize::Empty
|
||||
| BodySize::Sized(0) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, BodySize::None | BodySize::Empty | BodySize::Sized(0))
|
||||
}
|
||||
}
|
||||
|
||||
@ -470,9 +465,9 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use futures_util::stream;
|
||||
use futures_util::future::poll_fn;
|
||||
use futures_util::pin_mut;
|
||||
use futures_util::stream;
|
||||
|
||||
impl Body {
|
||||
pub(crate) fn get_ref(&self) -> &[u8] {
|
||||
@ -606,10 +601,6 @@ mod tests {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_body_eq() {
|
||||
assert!(Body::None == Body::None);
|
||||
assert!(Body::None != Body::Empty);
|
||||
assert!(Body::Empty == Body::Empty);
|
||||
assert!(Body::Empty != Body::None);
|
||||
assert!(
|
||||
Body::Bytes(Bytes::from_static(b"1"))
|
||||
== Body::Bytes(Bytes::from_static(b"1"))
|
||||
@ -621,7 +612,7 @@ mod tests {
|
||||
async fn test_body_debug() {
|
||||
assert!(format!("{:?}", Body::None).contains("Body::None"));
|
||||
assert!(format!("{:?}", Body::Empty).contains("Body::Empty"));
|
||||
assert!(format!("{:?}", Body::Bytes(Bytes::from_static(b"1"))).contains("1"));
|
||||
assert!(format!("{:?}", Body::Bytes(Bytes::from_static(b"1"))).contains('1'));
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
|
@ -37,7 +37,10 @@ where
|
||||
trace!("Sending client request: {:?} {:?}", head, body.size());
|
||||
let head_req = head.as_ref().method == Method::HEAD;
|
||||
let length = body.size();
|
||||
let eof = matches!(length, BodySize::None | BodySize::Empty | BodySize::Sized(0));
|
||||
let eof = matches!(
|
||||
length,
|
||||
BodySize::None | BodySize::Empty | BodySize::Sized(0)
|
||||
);
|
||||
|
||||
let mut req = Request::new(());
|
||||
*req.uri_mut() = head.as_ref().uri.clone();
|
||||
|
@ -69,10 +69,7 @@ where
|
||||
inner: Rc::downgrade(&inner_rc),
|
||||
});
|
||||
|
||||
ConnectionPool(
|
||||
connector_rc,
|
||||
inner_rc,
|
||||
)
|
||||
ConnectionPool(connector_rc, inner_rc)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -964,7 +964,6 @@ impl ResponseError for actix::actors::resolver::ResolverError {}
|
||||
mod tests {
|
||||
use super::*;
|
||||
use http::{Error as HttpError, StatusCode};
|
||||
use httparse;
|
||||
use std::io;
|
||||
|
||||
#[test]
|
||||
|
@ -72,7 +72,7 @@ impl fmt::Debug for Extensions {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_remove() {
|
||||
let mut map = Extensions::new();
|
||||
|
@ -132,19 +132,11 @@ where
|
||||
B: MessageBody,
|
||||
{
|
||||
fn is_empty(&self) -> bool {
|
||||
if let State::None = self {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
matches!(self, State::None)
|
||||
}
|
||||
|
||||
fn is_call(&self) -> bool {
|
||||
if let State::ServiceCall(_) = self {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
matches!(self, State::ServiceCall(_))
|
||||
}
|
||||
}
|
||||
enum PollResponse {
|
||||
|
@ -303,55 +303,59 @@ where
|
||||
}
|
||||
}
|
||||
},
|
||||
ServiceResponseStateProj::SendPayload(ref mut stream, ref mut body) => loop {
|
||||
ServiceResponseStateProj::SendPayload(ref mut stream, ref mut body) => {
|
||||
loop {
|
||||
if let Some(ref mut buffer) = this.buffer {
|
||||
match stream.poll_capacity(cx) {
|
||||
Poll::Pending => return Poll::Pending,
|
||||
Poll::Ready(None) => return Poll::Ready(()),
|
||||
Poll::Ready(Some(Ok(cap))) => {
|
||||
let len = buffer.len();
|
||||
let bytes = buffer.split_to(std::cmp::min(cap, len));
|
||||
loop {
|
||||
if let Some(ref mut buffer) = this.buffer {
|
||||
match stream.poll_capacity(cx) {
|
||||
Poll::Pending => return Poll::Pending,
|
||||
Poll::Ready(None) => return Poll::Ready(()),
|
||||
Poll::Ready(Some(Ok(cap))) => {
|
||||
let len = buffer.len();
|
||||
let bytes = buffer.split_to(std::cmp::min(cap, len));
|
||||
|
||||
if let Err(e) = stream.send_data(bytes, false) {
|
||||
if let Err(e) = stream.send_data(bytes, false) {
|
||||
warn!("{:?}", e);
|
||||
return Poll::Ready(());
|
||||
} else if !buffer.is_empty() {
|
||||
let cap =
|
||||
std::cmp::min(buffer.len(), CHUNK_SIZE);
|
||||
stream.reserve_capacity(cap);
|
||||
} else {
|
||||
this.buffer.take();
|
||||
}
|
||||
}
|
||||
Poll::Ready(Some(Err(e))) => {
|
||||
warn!("{:?}", e);
|
||||
return Poll::Ready(());
|
||||
} else if !buffer.is_empty() {
|
||||
let cap = std::cmp::min(buffer.len(), CHUNK_SIZE);
|
||||
stream.reserve_capacity(cap);
|
||||
} else {
|
||||
this.buffer.take();
|
||||
}
|
||||
}
|
||||
Poll::Ready(Some(Err(e))) => {
|
||||
warn!("{:?}", e);
|
||||
return Poll::Ready(());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
match body.as_mut().poll_next(cx) {
|
||||
Poll::Pending => return Poll::Pending,
|
||||
Poll::Ready(None) => {
|
||||
if let Err(e) = stream.send_data(Bytes::new(), true) {
|
||||
warn!("{:?}", e);
|
||||
} else {
|
||||
match body.as_mut().poll_next(cx) {
|
||||
Poll::Pending => return Poll::Pending,
|
||||
Poll::Ready(None) => {
|
||||
if let Err(e) = stream.send_data(Bytes::new(), true)
|
||||
{
|
||||
warn!("{:?}", e);
|
||||
}
|
||||
return Poll::Ready(());
|
||||
}
|
||||
Poll::Ready(Some(Ok(chunk))) => {
|
||||
stream.reserve_capacity(std::cmp::min(
|
||||
chunk.len(),
|
||||
CHUNK_SIZE,
|
||||
));
|
||||
*this.buffer = Some(chunk);
|
||||
}
|
||||
Poll::Ready(Some(Err(e))) => {
|
||||
error!("Response payload stream error: {:?}", e);
|
||||
return Poll::Ready(());
|
||||
}
|
||||
return Poll::Ready(());
|
||||
}
|
||||
Poll::Ready(Some(Ok(chunk))) => {
|
||||
stream.reserve_capacity(std::cmp::min(
|
||||
chunk.len(),
|
||||
CHUNK_SIZE,
|
||||
));
|
||||
*this.buffer = Some(chunk);
|
||||
}
|
||||
Poll::Ready(Some(Err(e))) => {
|
||||
error!("Response payload stream error: {:?}", e);
|
||||
return Poll::Ready(());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use http::Method;
|
||||
use http::header;
|
||||
use http::Method;
|
||||
|
||||
header! {
|
||||
/// `Allow` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-7.4.1)
|
||||
|
@ -9,11 +9,13 @@
|
||||
|
||||
pub use self::accept_charset::AcceptCharset;
|
||||
//pub use self::accept_encoding::AcceptEncoding;
|
||||
pub use self::accept_language::AcceptLanguage;
|
||||
pub use self::accept::Accept;
|
||||
pub use self::accept_language::AcceptLanguage;
|
||||
pub use self::allow::Allow;
|
||||
pub use self::cache_control::{CacheControl, CacheDirective};
|
||||
pub use self::content_disposition::{ContentDisposition, DispositionType, DispositionParam};
|
||||
pub use self::content_disposition::{
|
||||
ContentDisposition, DispositionParam, DispositionType,
|
||||
};
|
||||
pub use self::content_language::ContentLanguage;
|
||||
pub use self::content_range::{ContentRange, ContentRangeSpec};
|
||||
pub use self::content_type::ContentType;
|
||||
@ -47,7 +49,7 @@ macro_rules! __hyper__deref {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
@ -74,8 +76,8 @@ macro_rules! test_header {
|
||||
($id:ident, $raw:expr) => {
|
||||
#[test]
|
||||
fn $id() {
|
||||
use $crate::test;
|
||||
use super::*;
|
||||
use $crate::test;
|
||||
|
||||
let raw = $raw;
|
||||
let a: Vec<Vec<u8>> = raw.iter().map(|x| x.to_vec()).collect();
|
||||
@ -118,7 +120,7 @@ macro_rules! test_header {
|
||||
// Test formatting
|
||||
if typed.is_some() {
|
||||
let raw = &($raw)[..];
|
||||
let mut iter = raw.iter().map(|b|str::from_utf8(&b[..]).unwrap());
|
||||
let mut iter = raw.iter().map(|b| str::from_utf8(&b[..]).unwrap());
|
||||
let mut joined = String::new();
|
||||
joined.push_str(iter.next().unwrap());
|
||||
for s in iter {
|
||||
@ -128,7 +130,7 @@ macro_rules! test_header {
|
||||
assert_eq!(format!("{}", typed.unwrap()), joined);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
@ -330,11 +332,10 @@ macro_rules! header {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
mod accept_charset;
|
||||
//mod accept_encoding;
|
||||
mod accept_language;
|
||||
mod accept;
|
||||
mod accept_language;
|
||||
mod allow;
|
||||
mod cache_control;
|
||||
mod content_disposition;
|
||||
|
@ -167,7 +167,6 @@ where
|
||||
mod tests {
|
||||
use bytes::Bytes;
|
||||
use encoding_rs::ISO_8859_2;
|
||||
use mime;
|
||||
|
||||
use super::*;
|
||||
use crate::test::TestRequest;
|
||||
|
@ -139,7 +139,7 @@ mod tests {
|
||||
let mut masked = unmasked.clone();
|
||||
apply_mask_fallback(&mut masked[1..], &mask);
|
||||
|
||||
let mut masked_fast = unmasked.clone();
|
||||
let mut masked_fast = unmasked;
|
||||
apply_mask(&mut masked_fast[1..], mask_u32);
|
||||
|
||||
assert_eq!(masked, masked_fast);
|
||||
|
@ -274,9 +274,7 @@ async fn test_h2_head_empty() {
|
||||
async fn test_h2_head_binary() {
|
||||
let mut srv = test_server(move || {
|
||||
HttpService::build()
|
||||
.h2(|_| {
|
||||
ok::<_, ()>(Response::Ok().body(STR))
|
||||
})
|
||||
.h2(|_| ok::<_, ()>(Response::Ok().body(STR)))
|
||||
.openssl(ssl_acceptor())
|
||||
.map_err(|_| ())
|
||||
})
|
||||
|
@ -280,9 +280,7 @@ async fn test_h2_head_empty() {
|
||||
async fn test_h2_head_binary() {
|
||||
let mut srv = test_server(move || {
|
||||
HttpService::build()
|
||||
.h2(|_| {
|
||||
ok::<_, ()>(Response::Ok().body(STR))
|
||||
})
|
||||
.h2(|_| ok::<_, ()>(Response::Ok().body(STR)))
|
||||
.rustls(ssl_acceptor())
|
||||
})
|
||||
.await;
|
||||
|
@ -489,9 +489,7 @@ async fn test_h1_head_empty() {
|
||||
async fn test_h1_head_binary() {
|
||||
let mut srv = test_server(|| {
|
||||
HttpService::build()
|
||||
.h1(|_| {
|
||||
ok::<_, ()>(Response::Ok().body(STR))
|
||||
})
|
||||
.h1(|_| ok::<_, ()>(Response::Ok().body(STR)))
|
||||
.tcp()
|
||||
})
|
||||
.await;
|
||||
|
@ -9,8 +9,6 @@ use std::{cmp, fmt};
|
||||
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use futures_util::stream::{LocalBoxStream, Stream, StreamExt};
|
||||
use httparse;
|
||||
use mime;
|
||||
|
||||
use actix_utils::task::LocalWaker;
|
||||
use actix_web::error::{ParseError, PayloadError};
|
||||
@ -876,11 +874,11 @@ mod tests {
|
||||
|
||||
impl SlowStream {
|
||||
fn new(bytes: Bytes) -> SlowStream {
|
||||
return SlowStream {
|
||||
bytes: bytes,
|
||||
SlowStream {
|
||||
bytes,
|
||||
pos: 0,
|
||||
ready: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,8 +30,8 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for Ws {
|
||||
async fn test_simple() {
|
||||
let mut srv = test::start(|| {
|
||||
App::new().service(web::resource("/").to(
|
||||
|req: HttpRequest, stream: web::Payload| {
|
||||
async move { ws::start(Ws, &req, stream) }
|
||||
|req: HttpRequest, stream: web::Payload| async move {
|
||||
ws::start(Ws, &req, stream)
|
||||
},
|
||||
))
|
||||
});
|
||||
@ -51,7 +51,7 @@ async fn test_simple() {
|
||||
.await
|
||||
.unwrap();
|
||||
let item = framed.next().await.unwrap().unwrap();
|
||||
assert_eq!(item, ws::Frame::Binary(Bytes::from_static(b"text").into()));
|
||||
assert_eq!(item, ws::Frame::Binary(Bytes::from_static(b"text")));
|
||||
|
||||
framed.send(ws::Message::Ping("text".into())).await.unwrap();
|
||||
let item = framed.next().await.unwrap().unwrap();
|
||||
|
@ -3,7 +3,7 @@ extern crate proc_macro;
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::{Span, TokenStream as TokenStream2};
|
||||
use quote::{format_ident, quote, ToTokens, TokenStreamExt};
|
||||
use syn::{AttributeArgs, Ident, NestedMeta, parse_macro_input};
|
||||
use syn::{parse_macro_input, AttributeArgs, Ident, NestedMeta};
|
||||
|
||||
enum ResourceType {
|
||||
Async,
|
||||
@ -196,7 +196,12 @@ impl ToTokens for Route {
|
||||
name,
|
||||
guard,
|
||||
ast,
|
||||
args: Args { path, guards, wrappers },
|
||||
args:
|
||||
Args {
|
||||
path,
|
||||
guards,
|
||||
wrappers,
|
||||
},
|
||||
resource_type,
|
||||
} = self;
|
||||
let resource_name = name.to_string();
|
||||
|
@ -2,11 +2,11 @@ use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
use actix_web::{http, test, web::Path, App, HttpResponse, Responder, Error};
|
||||
use actix_web::dev::{Service, Transform, ServiceRequest, ServiceResponse};
|
||||
use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform};
|
||||
use actix_web::http::header::{HeaderName, HeaderValue};
|
||||
use actix_web::{http, test, web::Path, App, Error, HttpResponse, Responder};
|
||||
use actix_web_codegen::{connect, delete, get, head, options, patch, post, put, trace};
|
||||
use futures_util::future;
|
||||
use actix_web::http::header::{HeaderName, HeaderValue};
|
||||
|
||||
// Make sure that we can name function as 'config'
|
||||
#[get("/config")]
|
||||
@ -112,6 +112,7 @@ where
|
||||
type Request = ServiceRequest;
|
||||
type Response = ServiceResponse<B>;
|
||||
type Error = Error;
|
||||
#[allow(clippy::type_complexity)]
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
@ -119,7 +120,6 @@ where
|
||||
}
|
||||
|
||||
fn call(&mut self, req: ServiceRequest) -> Self::Future {
|
||||
|
||||
let fut = self.service.call(req);
|
||||
|
||||
Box::pin(async move {
|
||||
@ -223,10 +223,7 @@ async fn test_auto_async() {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_wrap() {
|
||||
let srv = test::start(|| {
|
||||
App::new()
|
||||
.service(get_wrap)
|
||||
});
|
||||
let srv = test::start(|| App::new().service(get_wrap));
|
||||
|
||||
let request = srv.request(http::Method::GET, srv.url("/test/wrap"));
|
||||
let response = request.send().await.unwrap();
|
||||
|
@ -402,9 +402,12 @@ mod tests {
|
||||
|
||||
fn json_eq(err: JsonPayloadError, other: JsonPayloadError) -> bool {
|
||||
match err {
|
||||
JsonPayloadError::Payload(PayloadError::Overflow) =>
|
||||
matches!(other, JsonPayloadError::Payload(PayloadError::Overflow)),
|
||||
JsonPayloadError::ContentType => matches!(other, JsonPayloadError::ContentType),
|
||||
JsonPayloadError::Payload(PayloadError::Overflow) => {
|
||||
matches!(other, JsonPayloadError::Payload(PayloadError::Overflow))
|
||||
}
|
||||
JsonPayloadError::ContentType => {
|
||||
matches!(other, JsonPayloadError::ContentType)
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -167,8 +167,7 @@ async fn test_connection_reuse() {
|
||||
})
|
||||
.and_then(
|
||||
HttpService::new(map_config(
|
||||
App::new()
|
||||
.service(web::resource("/").route(web::to(|| HttpResponse::Ok()))),
|
||||
App::new().service(web::resource("/").route(web::to(HttpResponse::Ok))),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
.tcp(),
|
||||
@ -205,8 +204,7 @@ async fn test_connection_force_close() {
|
||||
})
|
||||
.and_then(
|
||||
HttpService::new(map_config(
|
||||
App::new()
|
||||
.service(web::resource("/").route(web::to(|| HttpResponse::Ok()))),
|
||||
App::new().service(web::resource("/").route(web::to(HttpResponse::Ok))),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
.tcp(),
|
||||
|
@ -32,8 +32,7 @@ async fn test_connection_window_size() {
|
||||
let srv = test_server(move || {
|
||||
HttpService::build()
|
||||
.h2(map_config(
|
||||
App::new()
|
||||
.service(web::resource("/").route(web::to(|| HttpResponse::Ok()))),
|
||||
App::new().service(web::resource("/").route(web::to(HttpResponse::Ok))),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
.openssl(ssl_acceptor())
|
||||
|
@ -64,9 +64,8 @@ async fn _test_connection_reuse_h2() {
|
||||
.and_then(
|
||||
HttpService::build()
|
||||
.h2(map_config(
|
||||
App::new().service(
|
||||
web::resource("/").route(web::to(|| HttpResponse::Ok())),
|
||||
),
|
||||
App::new()
|
||||
.service(web::resource("/").route(web::to(HttpResponse::Ok))),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
.openssl(ssl_acceptor())
|
||||
|
@ -45,9 +45,8 @@ async fn test_connection_reuse_h2() {
|
||||
.and_then(
|
||||
HttpService::build()
|
||||
.h2(map_config(
|
||||
App::new().service(
|
||||
web::resource("/").route(web::to(|| HttpResponse::Ok())),
|
||||
),
|
||||
App::new()
|
||||
.service(web::resource("/").route(web::to(HttpResponse::Ok))),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
.openssl(ssl_acceptor())
|
||||
|
21
src/app.rs
21
src/app.rs
@ -489,7 +489,7 @@ mod tests {
|
||||
#[actix_rt::test]
|
||||
async fn test_default_resource() {
|
||||
let mut srv = init_service(
|
||||
App::new().service(web::resource("/test").to(|| HttpResponse::Ok())),
|
||||
App::new().service(web::resource("/test").to(HttpResponse::Ok)),
|
||||
)
|
||||
.await;
|
||||
let req = TestRequest::with_uri("/test").to_request();
|
||||
@ -502,13 +502,13 @@ mod tests {
|
||||
|
||||
let mut srv = init_service(
|
||||
App::new()
|
||||
.service(web::resource("/test").to(|| HttpResponse::Ok()))
|
||||
.service(web::resource("/test").to(HttpResponse::Ok))
|
||||
.service(
|
||||
web::resource("/test2")
|
||||
.default_service(|r: ServiceRequest| {
|
||||
ok(r.into_response(HttpResponse::Created()))
|
||||
})
|
||||
.route(web::get().to(|| HttpResponse::Ok())),
|
||||
.route(web::get().to(HttpResponse::Ok)),
|
||||
)
|
||||
.default_service(|r: ServiceRequest| {
|
||||
ok(r.into_response(HttpResponse::MethodNotAllowed()))
|
||||
@ -585,7 +585,7 @@ mod tests {
|
||||
DefaultHeaders::new()
|
||||
.header(header::CONTENT_TYPE, HeaderValue::from_static("0001")),
|
||||
)
|
||||
.route("/test", web::get().to(|| HttpResponse::Ok())),
|
||||
.route("/test", web::get().to(HttpResponse::Ok)),
|
||||
)
|
||||
.await;
|
||||
let req = TestRequest::with_uri("/test").to_request();
|
||||
@ -601,7 +601,7 @@ mod tests {
|
||||
async fn test_router_wrap() {
|
||||
let mut srv = init_service(
|
||||
App::new()
|
||||
.route("/test", web::get().to(|| HttpResponse::Ok()))
|
||||
.route("/test", web::get().to(HttpResponse::Ok))
|
||||
.wrap(
|
||||
DefaultHeaders::new()
|
||||
.header(header::CONTENT_TYPE, HeaderValue::from_static("0001")),
|
||||
@ -632,7 +632,7 @@ mod tests {
|
||||
Ok(res)
|
||||
}
|
||||
})
|
||||
.service(web::resource("/test").to(|| HttpResponse::Ok())),
|
||||
.service(web::resource("/test").to(HttpResponse::Ok)),
|
||||
)
|
||||
.await;
|
||||
let req = TestRequest::with_uri("/test").to_request();
|
||||
@ -648,7 +648,7 @@ mod tests {
|
||||
async fn test_router_wrap_fn() {
|
||||
let mut srv = init_service(
|
||||
App::new()
|
||||
.route("/test", web::get().to(|| HttpResponse::Ok()))
|
||||
.route("/test", web::get().to(HttpResponse::Ok))
|
||||
.wrap_fn(|req, srv| {
|
||||
let fut = srv.call(req);
|
||||
async {
|
||||
@ -679,10 +679,9 @@ mod tests {
|
||||
.route(
|
||||
"/test",
|
||||
web::get().to(|req: HttpRequest| {
|
||||
HttpResponse::Ok().body(format!(
|
||||
"{}",
|
||||
req.url_for("youtube", &["12345"]).unwrap()
|
||||
))
|
||||
HttpResponse::Ok().body(
|
||||
req.url_for("youtube", &["12345"]).unwrap().to_string(),
|
||||
)
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
@ -475,7 +475,7 @@ mod tests {
|
||||
let mut app = init_service(
|
||||
App::new()
|
||||
.data(DropData(data.clone()))
|
||||
.service(web::resource("/test").to(|| HttpResponse::Ok())),
|
||||
.service(web::resource("/test").to(HttpResponse::Ok)),
|
||||
)
|
||||
.await;
|
||||
let req = TestRequest::with_uri("/test").to_request();
|
||||
|
@ -311,10 +311,9 @@ mod tests {
|
||||
.route(
|
||||
"/test",
|
||||
web::get().to(|req: HttpRequest| {
|
||||
HttpResponse::Ok().body(format!(
|
||||
"{}",
|
||||
req.url_for("youtube", &["12345"]).unwrap()
|
||||
))
|
||||
HttpResponse::Ok().body(
|
||||
req.url_for("youtube", &["12345"]).unwrap().to_string(),
|
||||
)
|
||||
}),
|
||||
),
|
||||
)
|
||||
@ -330,9 +329,9 @@ mod tests {
|
||||
async fn test_service() {
|
||||
let mut srv = init_service(App::new().configure(|cfg| {
|
||||
cfg.service(
|
||||
web::resource("/test").route(web::get().to(|| HttpResponse::Created())),
|
||||
web::resource("/test").route(web::get().to(HttpResponse::Created)),
|
||||
)
|
||||
.route("/index.html", web::get().to(|| HttpResponse::Ok()));
|
||||
.route("/index.html", web::get().to(HttpResponse::Ok));
|
||||
}))
|
||||
.await;
|
||||
|
||||
|
17
src/data.rs
17
src/data.rs
@ -200,14 +200,14 @@ mod tests {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_route_data_extractor() {
|
||||
let mut srv =
|
||||
init_service(App::new().service(web::resource("/").data(10usize).route(
|
||||
web::get().to(|data: web::Data<usize>| {
|
||||
let _ = data.clone();
|
||||
HttpResponse::Ok()
|
||||
}),
|
||||
)))
|
||||
.await;
|
||||
let mut srv = init_service(
|
||||
App::new().service(
|
||||
web::resource("/")
|
||||
.data(10usize)
|
||||
.route(web::get().to(|_data: web::Data<usize>| HttpResponse::Ok())),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
|
||||
let req = TestRequest::default().to_request();
|
||||
let resp = srv.call(req).await.unwrap();
|
||||
@ -233,7 +233,6 @@ mod tests {
|
||||
web::resource("/").data(10usize).route(web::get().to(
|
||||
|data: web::Data<usize>| {
|
||||
assert_eq!(**data, 10);
|
||||
let _ = data.clone();
|
||||
HttpResponse::Ok()
|
||||
},
|
||||
)),
|
||||
|
@ -626,7 +626,7 @@ mod tests {
|
||||
Ok(())
|
||||
};
|
||||
let s = format!("{}", FormatDisplay(&render));
|
||||
assert!(s.contains(&format!("{}", now.format("%Y-%m-%dT%H:%M:%S"))));
|
||||
assert!(s.contains(&now.format("%Y-%m-%dT%H:%M:%S")));
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
|
@ -91,9 +91,9 @@ where
|
||||
// That approach fails when a trailing slash is added,
|
||||
// and a duplicate slash is removed,
|
||||
// since the length of the strings remains the same
|
||||
//
|
||||
//
|
||||
// For example, the path "/v1//s" will be normalized to "/v1/s/"
|
||||
// Both of the paths have the same length,
|
||||
// Both of the paths have the same length,
|
||||
// so the change can not be deduced from the length comparison
|
||||
if path != original_path {
|
||||
let mut parts = head.uri.clone().into_parts();
|
||||
@ -129,7 +129,7 @@ mod tests {
|
||||
let mut app = init_service(
|
||||
App::new()
|
||||
.wrap(NormalizePath::default())
|
||||
.service(web::resource("/v1/something/").to(|| HttpResponse::Ok())),
|
||||
.service(web::resource("/v1/something/").to(HttpResponse::Ok)),
|
||||
)
|
||||
.await;
|
||||
|
||||
|
@ -607,7 +607,7 @@ mod tests {
|
||||
header::CONTENT_TYPE,
|
||||
HeaderValue::from_static("0001"),
|
||||
))
|
||||
.route(web::get().to(|| HttpResponse::Ok())),
|
||||
.route(web::get().to(HttpResponse::Ok)),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
@ -637,7 +637,7 @@ mod tests {
|
||||
})
|
||||
}
|
||||
})
|
||||
.route(web::get().to(|| HttpResponse::Ok())),
|
||||
.route(web::get().to(HttpResponse::Ok)),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
@ -684,9 +684,7 @@ mod tests {
|
||||
async fn test_default_resource() {
|
||||
let mut srv = init_service(
|
||||
App::new()
|
||||
.service(
|
||||
web::resource("/test").route(web::get().to(|| HttpResponse::Ok())),
|
||||
)
|
||||
.service(web::resource("/test").route(web::get().to(HttpResponse::Ok)))
|
||||
.default_service(|r: ServiceRequest| {
|
||||
ok(r.into_response(HttpResponse::BadRequest()))
|
||||
}),
|
||||
@ -705,7 +703,7 @@ mod tests {
|
||||
let mut srv = init_service(
|
||||
App::new().service(
|
||||
web::resource("/test")
|
||||
.route(web::get().to(|| HttpResponse::Ok()))
|
||||
.route(web::get().to(HttpResponse::Ok))
|
||||
.default_service(|r: ServiceRequest| {
|
||||
ok(r.into_response(HttpResponse::BadRequest()))
|
||||
}),
|
||||
@ -731,17 +729,17 @@ mod tests {
|
||||
.service(
|
||||
web::resource("/test/{p}")
|
||||
.guard(guard::Get())
|
||||
.to(|| HttpResponse::Ok()),
|
||||
.to(HttpResponse::Ok),
|
||||
)
|
||||
.service(
|
||||
web::resource("/test/{p}")
|
||||
.guard(guard::Put())
|
||||
.to(|| HttpResponse::Created()),
|
||||
.to(HttpResponse::Created),
|
||||
)
|
||||
.service(
|
||||
web::resource("/test/{p}")
|
||||
.guard(guard::Delete())
|
||||
.to(|| HttpResponse::NoContent()),
|
||||
.to(HttpResponse::NoContent),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
@ -783,7 +781,8 @@ mod tests {
|
||||
data3: web::Data<f64>| {
|
||||
assert_eq!(**data1, 10);
|
||||
assert_eq!(**data2, '*');
|
||||
assert_eq!(**data3, 1.0);
|
||||
let error = std::f64::EPSILON;
|
||||
assert!((**data3 - 1.0).abs() < error);
|
||||
HttpResponse::Ok()
|
||||
},
|
||||
),
|
||||
|
@ -480,7 +480,7 @@ pub(crate) mod tests {
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
match resp.response().body() {
|
||||
ResponseBody::Body(Body::Bytes(ref b)) => {
|
||||
let bytes: Bytes = b.clone().into();
|
||||
let bytes = b.clone();
|
||||
assert_eq!(bytes, Bytes::from_static(b"some"));
|
||||
}
|
||||
_ => panic!(),
|
||||
|
@ -362,7 +362,7 @@ mod tests {
|
||||
App::new()
|
||||
.service(
|
||||
web::resource("/test")
|
||||
.route(web::get().to(|| HttpResponse::Ok()))
|
||||
.route(web::get().to(HttpResponse::Ok))
|
||||
.route(web::put().to(|| async {
|
||||
Err::<HttpResponse, _>(error::ErrorBadRequest("err"))
|
||||
}))
|
||||
|
109
src/scope.rs
109
src/scope.rs
@ -678,12 +678,9 @@ mod tests {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_scope() {
|
||||
let mut srv = init_service(
|
||||
App::new().service(
|
||||
web::scope("/app")
|
||||
.service(web::resource("/path1").to(|| HttpResponse::Ok())),
|
||||
),
|
||||
)
|
||||
let mut srv = init_service(App::new().service(
|
||||
web::scope("/app").service(web::resource("/path1").to(HttpResponse::Ok)),
|
||||
))
|
||||
.await;
|
||||
|
||||
let req = TestRequest::with_uri("/app/path1").to_request();
|
||||
@ -696,8 +693,8 @@ mod tests {
|
||||
let mut srv = init_service(
|
||||
App::new().service(
|
||||
web::scope("/app")
|
||||
.service(web::resource("").to(|| HttpResponse::Ok()))
|
||||
.service(web::resource("/").to(|| HttpResponse::Created())),
|
||||
.service(web::resource("").to(HttpResponse::Ok))
|
||||
.service(web::resource("/").to(HttpResponse::Created)),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
@ -714,7 +711,7 @@ mod tests {
|
||||
#[actix_rt::test]
|
||||
async fn test_scope_root2() {
|
||||
let mut srv = init_service(App::new().service(
|
||||
web::scope("/app/").service(web::resource("").to(|| HttpResponse::Ok())),
|
||||
web::scope("/app/").service(web::resource("").to(HttpResponse::Ok)),
|
||||
))
|
||||
.await;
|
||||
|
||||
@ -730,7 +727,7 @@ mod tests {
|
||||
#[actix_rt::test]
|
||||
async fn test_scope_root3() {
|
||||
let mut srv = init_service(App::new().service(
|
||||
web::scope("/app/").service(web::resource("/").to(|| HttpResponse::Ok())),
|
||||
web::scope("/app/").service(web::resource("/").to(HttpResponse::Ok)),
|
||||
))
|
||||
.await;
|
||||
|
||||
@ -748,8 +745,8 @@ mod tests {
|
||||
let mut srv = init_service(
|
||||
App::new().service(
|
||||
web::scope("app")
|
||||
.route("/path1", web::get().to(|| HttpResponse::Ok()))
|
||||
.route("/path1", web::delete().to(|| HttpResponse::Ok())),
|
||||
.route("/path1", web::get().to(HttpResponse::Ok))
|
||||
.route("/path1", web::delete().to(HttpResponse::Ok)),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
@ -777,8 +774,8 @@ mod tests {
|
||||
App::new().service(
|
||||
web::scope("app").service(
|
||||
web::resource("path1")
|
||||
.route(web::get().to(|| HttpResponse::Ok()))
|
||||
.route(web::delete().to(|| HttpResponse::Ok())),
|
||||
.route(web::get().to(HttpResponse::Ok))
|
||||
.route(web::delete().to(HttpResponse::Ok)),
|
||||
),
|
||||
),
|
||||
)
|
||||
@ -807,7 +804,7 @@ mod tests {
|
||||
App::new().service(
|
||||
web::scope("/app")
|
||||
.guard(guard::Get())
|
||||
.service(web::resource("/path1").to(|| HttpResponse::Ok())),
|
||||
.service(web::resource("/path1").to(HttpResponse::Ok)),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
@ -842,7 +839,7 @@ mod tests {
|
||||
|
||||
match resp.response().body() {
|
||||
ResponseBody::Body(Body::Bytes(ref b)) => {
|
||||
let bytes: Bytes = b.clone().into();
|
||||
let bytes = b.clone();
|
||||
assert_eq!(bytes, Bytes::from_static(b"project: project1"));
|
||||
}
|
||||
_ => panic!(),
|
||||
@ -855,14 +852,9 @@ mod tests {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_nested_scope() {
|
||||
let mut srv = init_service(
|
||||
App::new().service(
|
||||
web::scope("/app")
|
||||
.service(web::scope("/t1").service(
|
||||
web::resource("/path1").to(|| HttpResponse::Created()),
|
||||
)),
|
||||
),
|
||||
)
|
||||
let mut srv = init_service(App::new().service(web::scope("/app").service(
|
||||
web::scope("/t1").service(web::resource("/path1").to(HttpResponse::Created)),
|
||||
)))
|
||||
.await;
|
||||
|
||||
let req = TestRequest::with_uri("/app/t1/path1").to_request();
|
||||
@ -872,14 +864,9 @@ mod tests {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_nested_scope_no_slash() {
|
||||
let mut srv = init_service(
|
||||
App::new().service(
|
||||
web::scope("/app")
|
||||
.service(web::scope("t1").service(
|
||||
web::resource("/path1").to(|| HttpResponse::Created()),
|
||||
)),
|
||||
),
|
||||
)
|
||||
let mut srv = init_service(App::new().service(web::scope("/app").service(
|
||||
web::scope("t1").service(web::resource("/path1").to(HttpResponse::Created)),
|
||||
)))
|
||||
.await;
|
||||
|
||||
let req = TestRequest::with_uri("/app/t1/path1").to_request();
|
||||
@ -893,8 +880,8 @@ mod tests {
|
||||
App::new().service(
|
||||
web::scope("/app").service(
|
||||
web::scope("/t1")
|
||||
.service(web::resource("").to(|| HttpResponse::Ok()))
|
||||
.service(web::resource("/").to(|| HttpResponse::Created())),
|
||||
.service(web::resource("").to(HttpResponse::Ok))
|
||||
.service(web::resource("/").to(HttpResponse::Created)),
|
||||
),
|
||||
),
|
||||
)
|
||||
@ -916,7 +903,7 @@ mod tests {
|
||||
web::scope("/app").service(
|
||||
web::scope("/t1")
|
||||
.guard(guard::Get())
|
||||
.service(web::resource("/path1").to(|| HttpResponse::Ok())),
|
||||
.service(web::resource("/path1").to(HttpResponse::Ok)),
|
||||
),
|
||||
),
|
||||
)
|
||||
@ -953,7 +940,7 @@ mod tests {
|
||||
|
||||
match resp.response().body() {
|
||||
ResponseBody::Body(Body::Bytes(ref b)) => {
|
||||
let bytes: Bytes = b.clone().into();
|
||||
let bytes = b.clone();
|
||||
assert_eq!(bytes, Bytes::from_static(b"project: project_1"));
|
||||
}
|
||||
_ => panic!(),
|
||||
@ -981,7 +968,7 @@ mod tests {
|
||||
|
||||
match resp.response().body() {
|
||||
ResponseBody::Body(Body::Bytes(ref b)) => {
|
||||
let bytes: Bytes = b.clone().into();
|
||||
let bytes = b.clone();
|
||||
assert_eq!(bytes, Bytes::from_static(b"project: test - 1"));
|
||||
}
|
||||
_ => panic!(),
|
||||
@ -997,7 +984,7 @@ mod tests {
|
||||
let mut srv = init_service(
|
||||
App::new().service(
|
||||
web::scope("/app")
|
||||
.service(web::resource("/path1").to(|| HttpResponse::Ok()))
|
||||
.service(web::resource("/path1").to(HttpResponse::Ok))
|
||||
.default_service(|r: ServiceRequest| {
|
||||
ok(r.into_response(HttpResponse::BadRequest()))
|
||||
}),
|
||||
@ -1018,9 +1005,10 @@ mod tests {
|
||||
async fn test_default_resource_propagation() {
|
||||
let mut srv = init_service(
|
||||
App::new()
|
||||
.service(web::scope("/app1").default_service(
|
||||
web::resource("").to(|| HttpResponse::BadRequest()),
|
||||
))
|
||||
.service(
|
||||
web::scope("/app1")
|
||||
.default_service(web::resource("").to(HttpResponse::BadRequest)),
|
||||
)
|
||||
.service(web::scope("/app2"))
|
||||
.default_service(|r: ServiceRequest| {
|
||||
ok(r.into_response(HttpResponse::MethodNotAllowed()))
|
||||
@ -1043,21 +1031,21 @@ mod tests {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_middleware() {
|
||||
let mut srv =
|
||||
init_service(
|
||||
App::new().service(
|
||||
web::scope("app")
|
||||
.wrap(DefaultHeaders::new().header(
|
||||
let mut srv = init_service(
|
||||
App::new().service(
|
||||
web::scope("app")
|
||||
.wrap(
|
||||
DefaultHeaders::new().header(
|
||||
header::CONTENT_TYPE,
|
||||
HeaderValue::from_static("0001"),
|
||||
))
|
||||
.service(
|
||||
web::resource("/test")
|
||||
.route(web::get().to(|| HttpResponse::Ok())),
|
||||
),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
)
|
||||
.service(
|
||||
web::resource("/test").route(web::get().to(HttpResponse::Ok)),
|
||||
),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
|
||||
let req = TestRequest::with_uri("/app/test").to_request();
|
||||
let resp = call_service(&mut srv, req).await;
|
||||
@ -1084,7 +1072,7 @@ mod tests {
|
||||
Ok(res)
|
||||
}
|
||||
})
|
||||
.route("/test", web::get().to(|| HttpResponse::Ok())),
|
||||
.route("/test", web::get().to(HttpResponse::Ok)),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
@ -1105,7 +1093,6 @@ mod tests {
|
||||
"/t",
|
||||
web::get().to(|data: web::Data<usize>| {
|
||||
assert_eq!(**data, 10);
|
||||
let _ = data.clone();
|
||||
HttpResponse::Ok()
|
||||
}),
|
||||
),
|
||||
@ -1141,7 +1128,6 @@ mod tests {
|
||||
"/t",
|
||||
web::get().to(|data: web::Data<usize>| {
|
||||
assert_eq!(**data, 10);
|
||||
let _ = data.clone();
|
||||
HttpResponse::Ok()
|
||||
}),
|
||||
),
|
||||
@ -1157,7 +1143,7 @@ mod tests {
|
||||
async fn test_scope_config() {
|
||||
let mut srv =
|
||||
init_service(App::new().service(web::scope("/app").configure(|s| {
|
||||
s.route("/path1", web::get().to(|| HttpResponse::Ok()));
|
||||
s.route("/path1", web::get().to(HttpResponse::Ok));
|
||||
})))
|
||||
.await;
|
||||
|
||||
@ -1171,7 +1157,7 @@ mod tests {
|
||||
let mut srv =
|
||||
init_service(App::new().service(web::scope("/app").configure(|s| {
|
||||
s.service(web::scope("/v1").configure(|s| {
|
||||
s.route("/", web::get().to(|| HttpResponse::Ok()));
|
||||
s.route("/", web::get().to(HttpResponse::Ok));
|
||||
}));
|
||||
})))
|
||||
.await;
|
||||
@ -1193,10 +1179,9 @@ mod tests {
|
||||
s.route(
|
||||
"/",
|
||||
web::get().to(|req: HttpRequest| async move {
|
||||
HttpResponse::Ok().body(format!(
|
||||
"{}",
|
||||
req.url_for("youtube", &["xxxxxx"]).unwrap().as_str()
|
||||
))
|
||||
HttpResponse::Ok().body(
|
||||
req.url_for("youtube", &["xxxxxx"]).unwrap().to_string(),
|
||||
)
|
||||
}),
|
||||
);
|
||||
}));
|
||||
|
@ -23,7 +23,6 @@ use futures_util::future::ok;
|
||||
use futures_util::StreamExt;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
use serde_json;
|
||||
use socket2::{Domain, Protocol, Socket, Type};
|
||||
|
||||
pub use actix_http::test::TestBuffer;
|
||||
|
@ -407,9 +407,15 @@ mod tests {
|
||||
|
||||
fn eq(err: UrlencodedError, other: UrlencodedError) -> bool {
|
||||
match err {
|
||||
UrlencodedError::Overflow { .. } => matches!(other, UrlencodedError::Overflow { .. }),
|
||||
UrlencodedError::UnknownLength => matches!(other, UrlencodedError::UnknownLength),
|
||||
UrlencodedError::ContentType => matches!(other, UrlencodedError::ContentType),
|
||||
UrlencodedError::Overflow { .. } => {
|
||||
matches!(other, UrlencodedError::Overflow { .. })
|
||||
}
|
||||
UrlencodedError::UnknownLength => {
|
||||
matches!(other, UrlencodedError::UnknownLength)
|
||||
}
|
||||
UrlencodedError::ContentType => {
|
||||
matches!(other, UrlencodedError::ContentType)
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -434,7 +434,9 @@ mod tests {
|
||||
fn json_eq(err: JsonPayloadError, other: JsonPayloadError) -> bool {
|
||||
match err {
|
||||
JsonPayloadError::Overflow => matches!(other, JsonPayloadError::Overflow),
|
||||
JsonPayloadError::ContentType => matches!(other, JsonPayloadError::ContentType),
|
||||
JsonPayloadError::ContentType => {
|
||||
matches!(other, JsonPayloadError::ContentType)
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@ -480,7 +482,7 @@ mod tests {
|
||||
.to_http_parts();
|
||||
|
||||
let s = Json::<MyObject>::from_request(&req, &mut pl).await;
|
||||
let mut resp = Response::from_error(s.err().unwrap().into());
|
||||
let mut resp = Response::from_error(s.err().unwrap());
|
||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||
|
||||
let body = load_stream(resp.take_body()).await.unwrap();
|
||||
|
@ -851,7 +851,7 @@ async fn test_slow_request() {
|
||||
use std::net;
|
||||
|
||||
let srv = test::start_with(test::config().client_timeout(200), || {
|
||||
App::new().service(web::resource("/").route(web::to(|| HttpResponse::Ok())))
|
||||
App::new().service(web::resource("/").route(web::to(HttpResponse::Ok)))
|
||||
});
|
||||
|
||||
let mut stream = net::TcpStream::connect(srv.addr()).unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user