Skip to content

Commit

Permalink
change rustfmt line width to 96
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Feb 11, 2021
1 parent c1af508 commit 31d9ed8
Show file tree
Hide file tree
Showing 56 changed files with 463 additions and 756 deletions.
14 changes: 4 additions & 10 deletions actix-files/src/chunked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ impl fmt::Debug for ChunkedReadFile {
impl Stream for ChunkedReadFile {
type Item = Result<Bytes, Error>;

fn poll_next(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>> {
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let this = self.as_mut().get_mut();
match this.state {
ChunkedReadFileState::File(ref mut file) => {
Expand All @@ -68,16 +65,13 @@ impl Stream for ChunkedReadFile {
.expect("ChunkedReadFile polled after completion");

let fut = spawn_blocking(move || {
let max_bytes =
cmp::min(size.saturating_sub(counter), 65_536) as usize;
let max_bytes = cmp::min(size.saturating_sub(counter), 65_536) as usize;

let mut buf = Vec::with_capacity(max_bytes);
file.seek(io::SeekFrom::Start(offset))?;

let n_bytes = file
.by_ref()
.take(max_bytes as u64)
.read_to_end(&mut buf)?;
let n_bytes =
file.by_ref().take(max_bytes as u64).read_to_end(&mut buf)?;

if n_bytes == 0 {
return Err(io::ErrorKind::UnexpectedEof.into());
Expand Down
4 changes: 1 addition & 3 deletions actix-files/src/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ pub(crate) fn directory_listing(
if dir.is_visible(&entry) {
let entry = entry.unwrap();
let p = match entry.path().strip_prefix(&dir.path) {
Ok(p) if cfg!(windows) => {
base.join(p).to_string_lossy().replace("\\", "/")
}
Ok(p) if cfg!(windows) => base.join(p).to_string_lossy().replace("\\", "/"),
Ok(p) => base.join(p).to_string_lossy().into_owned(),
Err(_) => continue,
};
Expand Down
12 changes: 5 additions & 7 deletions actix-files/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use std::{cell::RefCell, fmt, io, path::PathBuf, rc::Rc};

use actix_service::{boxed, IntoServiceFactory, ServiceFactory, ServiceFactoryExt};
use actix_web::{
dev::{
AppService, HttpServiceFactory, ResourceDef, ServiceRequest, ServiceResponse,
},
dev::{AppService, HttpServiceFactory, ResourceDef, ServiceRequest, ServiceResponse},
error::Error,
guard::Guard,
http::header::DispositionType,
Expand All @@ -13,8 +11,8 @@ use actix_web::{
use futures_util::future::{ok, FutureExt, LocalBoxFuture};

use crate::{
directory_listing, named, Directory, DirectoryRenderer, FilesService,
HttpNewService, MimeOverride,
directory_listing, named, Directory, DirectoryRenderer, FilesService, HttpNewService,
MimeOverride,
};

/// Static files handling service.
Expand Down Expand Up @@ -129,8 +127,8 @@ impl Files {
/// Set custom directory renderer
pub fn files_listing_renderer<F>(mut self, f: F) -> Self
where
for<'r, 's> F: Fn(&'r Directory, &'s HttpRequest) -> Result<ServiceResponse, io::Error>
+ 'static,
for<'r, 's> F:
Fn(&'r Directory, &'s HttpRequest) -> Result<ServiceResponse, io::Error> + 'static,
{
self.renderer = Rc::new(f);
self
Expand Down
23 changes: 9 additions & 14 deletions actix-files/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ mod tests {
#[actix_rt::test]
async fn test_if_modified_since_without_if_none_match() {
let file = NamedFile::open("Cargo.toml").unwrap();
let since =
header::HttpDate::from(SystemTime::now().add(Duration::from_secs(60)));
let since = header::HttpDate::from(SystemTime::now().add(Duration::from_secs(60)));

let req = TestRequest::default()
.insert_header((header::IF_MODIFIED_SINCE, since))
Expand All @@ -123,8 +122,7 @@ mod tests {
#[actix_rt::test]
async fn test_if_modified_since_with_if_none_match() {
let file = NamedFile::open("Cargo.toml").unwrap();
let since =
header::HttpDate::from(SystemTime::now().add(Duration::from_secs(60)));
let since = header::HttpDate::from(SystemTime::now().add(Duration::from_secs(60)));

let req = TestRequest::default()
.insert_header((header::IF_NONE_MATCH, "miss_etag"))
Expand Down Expand Up @@ -212,8 +210,7 @@ mod tests {
#[actix_rt::test]
async fn test_named_file_non_ascii_file_name() {
let mut file =
NamedFile::from_file(File::open("Cargo.toml").unwrap(), "貨物.toml")
.unwrap();
NamedFile::from_file(File::open("Cargo.toml").unwrap(), "貨物.toml").unwrap();
{
file.file();
let _f: &File = &file;
Expand Down Expand Up @@ -605,10 +602,9 @@ mod tests {

#[actix_rt::test]
async fn test_static_files() {
let srv = test::init_service(
App::new().service(Files::new("/", ".").show_files_listing()),
)
.await;
let srv =
test::init_service(App::new().service(Files::new("/", ".").show_files_listing()))
.await;
let req = TestRequest::with_uri("/missing").to_request();

let resp = test::call_service(&srv, req).await;
Expand All @@ -620,10 +616,9 @@ mod tests {
let resp = test::call_service(&srv, req).await;
assert_eq!(resp.status(), StatusCode::NOT_FOUND);

let srv = test::init_service(
App::new().service(Files::new("/", ".").show_files_listing()),
)
.await;
let srv =
test::init_service(App::new().service(Files::new("/", ".").show_files_listing()))
.await;
let req = TestRequest::with_uri("/tests").to_request();
let resp = test::call_service(&srv, req).await;
assert_eq!(
Expand Down
15 changes: 3 additions & 12 deletions actix-files/src/named.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use actix_web::{
dev::{BodyEncoding, SizedStream},
http::{
header::{
self, Charset, ContentDisposition, DispositionParam, DispositionType,
ExtendedValue,
self, Charset, ContentDisposition, DispositionParam, DispositionType, ExtendedValue,
},
ContentEncoding, StatusCode,
},
Expand Down Expand Up @@ -395,18 +394,10 @@ impl NamedFile {
resp.encoding(ContentEncoding::Identity);
resp.insert_header((
header::CONTENT_RANGE,
format!(
"bytes {}-{}/{}",
offset,
offset + length - 1,
self.md.len()
),
format!("bytes {}-{}/{}", offset, offset + length - 1, self.md.len()),
));
} else {
resp.insert_header((
header::CONTENT_RANGE,
format!("bytes */{}", length),
));
resp.insert_header((header::CONTENT_RANGE, format!("bytes */{}", length)));
return resp.status(StatusCode::RANGE_NOT_SATISFIABLE).finish();
};
} else {
Expand Down
6 changes: 2 additions & 4 deletions actix-files/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ impl HttpRange {
if start_str.is_empty() {
// If no start is specified, end specifies the
// range start relative to the end of the file.
let mut length: i64 =
end_str.parse().map_err(|_| ParseRangeErr(()))?;
let mut length: i64 = end_str.parse().map_err(|_| ParseRangeErr(()))?;

if length > size_sig {
length = size_sig;
Expand All @@ -72,8 +71,7 @@ impl HttpRange {
// If no end is specified, range extends to end of the file.
size_sig - start
} else {
let mut end: i64 =
end_str.parse().map_err(|_| ParseRangeErr(()))?;
let mut end: i64 = end_str.parse().map_err(|_| ParseRangeErr(()))?;

if start > end {
return Err(ParseRangeErr(()));
Expand Down
7 changes: 3 additions & 4 deletions actix-files/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use actix_web::{
use futures_util::future::{ok, Either, LocalBoxFuture, Ready};

use crate::{
named, Directory, DirectoryRenderer, FilesError, HttpService, MimeOverride,
NamedFile, PathBufWrap,
named, Directory, DirectoryRenderer, FilesError, HttpService, MimeOverride, NamedFile,
PathBufWrap,
};

/// Assembled file serving service.
Expand Down Expand Up @@ -138,8 +138,7 @@ impl Service<ServiceRequest> for FilesService {
match NamedFile::open(path) {
Ok(mut named_file) => {
if let Some(ref mime_override) = self.mime_override {
let new_disposition =
mime_override(&named_file.content_type.type_());
let new_disposition = mime_override(&named_file.content_type.type_());
named_file.content_disposition.disposition = new_disposition;
}
named_file.flags = self.file_flags;
Expand Down
7 changes: 3 additions & 4 deletions actix-files/tests/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ async fn test_utf8_file_contents() {
);

// prefer UTF-8 encoding
let srv = test::init_service(
App::new().service(Files::new("/", "./tests").prefer_utf8(true)),
)
.await;
let srv =
test::init_service(App::new().service(Files::new("/", "./tests").prefer_utf8(true)))
.await;

let req = TestRequest::with_uri("/utf8.txt").to_request();
let res = test::call_service(&srv, req).await;
Expand Down
9 changes: 3 additions & 6 deletions actix-http-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ pub async fn test_server_with_addr<F: ServiceFactory<TcpStream>>(
/// 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();
Expand Down Expand Up @@ -248,8 +247,7 @@ impl TestServer {
pub async fn ws_at(
&mut self,
path: &str,
) -> Result<Framed<impl AsyncRead + AsyncWrite, ws::Codec>, awc::error::WsClientError>
{
) -> Result<Framed<impl AsyncRead + AsyncWrite, ws::Codec>, awc::error::WsClientError> {
let url = self.url(path);
let connect = self.client.ws(url).connect();
connect.await.map(|(_, framed)| framed)
Expand All @@ -258,8 +256,7 @@ impl TestServer {
/// Connect to a websocket server
pub async fn ws(
&mut self,
) -> Result<Framed<impl AsyncRead + AsyncWrite, ws::Codec>, awc::error::WsClientError>
{
) -> Result<Framed<impl AsyncRead + AsyncWrite, ws::Codec>, awc::error::WsClientError> {
self.ws_at("/").await
}

Expand Down
2 changes: 1 addition & 1 deletion actix-http/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use http::{header, Method, Uri, Version};

use crate::extensions::Extensions;
use crate::header::HeaderMap;
use crate::HttpMessage;
use crate::message::{Message, RequestHead};
use crate::payload::{Payload, PayloadStream};
use crate::HttpMessage;

/// Request
pub struct Request<P = PayloadStream> {
Expand Down
53 changes: 15 additions & 38 deletions actix-multipart/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use futures_util::stream::{LocalBoxStream, Stream, StreamExt};

use actix_utils::task::LocalWaker;
use actix_web::error::{ParseError, PayloadError};
use actix_web::http::header::{
self, ContentDisposition, HeaderMap, HeaderName, HeaderValue,
};
use actix_web::http::header::{self, ContentDisposition, HeaderMap, HeaderName, HeaderValue};

use crate::error::MultipartError;

Expand Down Expand Up @@ -120,10 +118,7 @@ impl Multipart {
impl Stream for Multipart {
type Item = Result<Field, MultipartError>;

fn poll_next(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>> {
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
if let Some(err) = self.error.take() {
Poll::Ready(Some(Err(err)))
} else if self.safety.current() {
Expand All @@ -142,9 +137,7 @@ impl Stream for Multipart {
}

impl InnerMultipart {
fn read_headers(
payload: &mut PayloadBuffer,
) -> Result<Option<HeaderMap>, MultipartError> {
fn read_headers(payload: &mut PayloadBuffer) -> Result<Option<HeaderMap>, MultipartError> {
match payload.read_until(b"\r\n\r\n")? {
None => {
if payload.eof {
Expand Down Expand Up @@ -226,8 +219,7 @@ impl InnerMultipart {
if chunk.len() < boundary.len() {
continue;
}
if &chunk[..2] == b"--"
&& &chunk[2..chunk.len() - 2] == boundary.as_bytes()
if &chunk[..2] == b"--" && &chunk[2..chunk.len() - 2] == boundary.as_bytes()
{
break;
} else {
Expand Down Expand Up @@ -273,9 +265,7 @@ impl InnerMultipart {
match field.borrow_mut().poll(safety) {
Poll::Pending => return Poll::Pending,
Poll::Ready(Some(Ok(_))) => continue,
Poll::Ready(Some(Err(e))) => {
return Poll::Ready(Some(Err(e)))
}
Poll::Ready(Some(Err(e))) => return Poll::Ready(Some(Err(e))),
Poll::Ready(None) => true,
}
}
Expand Down Expand Up @@ -311,10 +301,7 @@ impl InnerMultipart {
}
// read boundary
InnerState::Boundary => {
match InnerMultipart::read_boundary(
&mut *payload,
&self.boundary,
)? {
match InnerMultipart::read_boundary(&mut *payload, &self.boundary)? {
None => return Poll::Pending,
Some(eof) => {
if eof {
Expand Down Expand Up @@ -418,8 +405,7 @@ impl Field {
pub fn content_disposition(&self) -> Option<ContentDisposition> {
// RFC 7578: 'Each part MUST contain a Content-Disposition header field
// where the disposition type is "form-data".'
if let Some(content_disposition) = self.headers.get(&header::CONTENT_DISPOSITION)
{
if let Some(content_disposition) = self.headers.get(&header::CONTENT_DISPOSITION) {
ContentDisposition::from_raw(content_disposition).ok()
} else {
None
Expand All @@ -430,15 +416,10 @@ impl Field {
impl Stream for Field {
type Item = Result<Bytes, MultipartError>;

fn poll_next(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>> {
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
if self.safety.current() {
let mut inner = self.inner.borrow_mut();
if let Some(mut payload) =
inner.payload.as_ref().unwrap().get_mut(&self.safety)
{
if let Some(mut payload) = inner.payload.as_ref().unwrap().get_mut(&self.safety) {
payload.poll_stream(cx)?;
}
inner.poll(&self.safety)
Expand Down Expand Up @@ -607,8 +588,7 @@ impl InnerField {
return Poll::Ready(None);
}

let result = if let Some(mut payload) = self.payload.as_ref().unwrap().get_mut(s)
{
let result = if let Some(mut payload) = self.payload.as_ref().unwrap().get_mut(s) {
if !self.eof {
let res = if let Some(ref mut len) = self.length {
InnerField::read_len(&mut *payload, len)
Expand All @@ -628,7 +608,9 @@ impl InnerField {
Ok(None) => Poll::Pending,
Ok(Some(line)) => {
if line.as_ref() != b"\r\n" {
log::warn!("multipart field did not read all the data or it is malformed");
log::warn!(
"multipart field did not read all the data or it is malformed"
);
}
Poll::Ready(None)
}
Expand Down Expand Up @@ -804,9 +786,7 @@ impl PayloadBuffer {
/// Read bytes until new line delimiter or eof
pub fn readline_or_eof(&mut self) -> Result<Option<Bytes>, MultipartError> {
match self.readline() {
Err(MultipartError::Incomplete) if self.eof => {
Ok(Some(self.buf.split().freeze()))
}
Err(MultipartError::Incomplete) if self.eof => Ok(Some(self.buf.split().freeze())),
line => line,
}
}
Expand Down Expand Up @@ -902,10 +882,7 @@ mod tests {
impl Stream for SlowStream {
type Item = Result<Bytes, PayloadError>;

fn poll_next(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>> {
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let this = self.get_mut();
if !this.ready {
this.ready = true;
Expand Down
Loading

0 comments on commit 31d9ed8

Please sign in to comment.