update changelogs

This commit is contained in:
Rob Ede 2021-11-22 00:38:04 +00:00
parent fae8956265
commit a717ed7e75
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
8 changed files with 37 additions and 41 deletions

View File

@ -143,8 +143,6 @@ actix-web-actors = { path = "actix-web-actors" }
actix-web-codegen = { path = "actix-web-codegen" } actix-web-codegen = { path = "actix-web-codegen" }
awc = { path = "awc" } awc = { path = "awc" }
actix-rt = { git = "https://github.com/actix/actix-net.git" }
[[test]] [[test]]
name = "test_server" name = "test_server"
required-features = ["compress-brotli", "compress-gzip", "compress-zstd", "cookies"] required-features = ["compress-brotli", "compress-gzip", "compress-zstd", "cookies"]

View File

@ -2,7 +2,11 @@
## Unreleased - 2021-xx-xx ## Unreleased - 2021-xx-xx
* Add crate feature `experimental-io-uring`, enabling async file I/O to be utilized. This feature is only available on Linux OSes with recent kernel versions. This feature is semver-exempt. [#2408] * Add crate feature `experimental-io-uring`, enabling async file I/O to be utilized. This feature is only available on Linux OSes with recent kernel versions. This feature is semver-exempt. [#2408]
* Add `NamedFile::open_async`. [#2408]
* Fix 304 Not Modified responses to omit the Content-Length header, as per the spec. [#2453] * Fix 304 Not Modified responses to omit the Content-Length header, as per the spec. [#2453]
* The `Responder` impl for `NamedFile` now has a boxed future associated type. [#2408]
* The `Service` impl for `NamedFileService` now has a boxed future associated type. [#2408]
* Add `impl Clone` for `FilesService`. [#2408]
[#2408]: https://github.com/actix/actix-web/pull/2408 [#2408]: https://github.com/actix/actix-web/pull/2408
[#2453]: https://github.com/actix/actix-web/pull/2453 [#2453]: https://github.com/actix/actix-web/pull/2453

View File

@ -14,9 +14,8 @@ use pin_project_lite::pin_project;
use super::named::File; use super::named::File;
pin_project! { pin_project! {
/// Adapter to read a `std::file::File` in chunks.
#[doc(hidden)] #[doc(hidden)]
/// A helper created from a `std::fs::File` which reads the file
/// chunk-by-chunk on a `ThreadPool`.
pub struct ChunkedReadFile<F, Fut> { pub struct ChunkedReadFile<F, Fut> {
size: u64, size: u64,
offset: u64, offset: u64,
@ -32,13 +31,8 @@ pin_project! {
#[project = ChunkedReadFileStateProj] #[project = ChunkedReadFileStateProj]
#[project_replace = ChunkedReadFileStateProjReplace] #[project_replace = ChunkedReadFileStateProjReplace]
enum ChunkedReadFileState<Fut> { enum ChunkedReadFileState<Fut> {
File { File { file: Option<File>, },
file: Option<File>, Future { #[pin] fut: Fut },
},
Future {
#[pin]
fut: Fut
}
} }
} }
@ -47,13 +41,8 @@ pin_project! {
#[project = ChunkedReadFileStateProj] #[project = ChunkedReadFileStateProj]
#[project_replace = ChunkedReadFileStateProjReplace] #[project_replace = ChunkedReadFileStateProjReplace]
enum ChunkedReadFileState<Fut> { enum ChunkedReadFileState<Fut> {
File { File { file: Option<(File, BytesMut)> },
file: Option<(File, BytesMut)>, Future { #[pin] fut: Fut },
},
Future {
#[pin]
fut: Fut
}
} }
} }
@ -88,7 +77,7 @@ async fn chunked_read_file_callback(
offset: u64, offset: u64,
max_bytes: usize, max_bytes: usize,
) -> Result<(File, Bytes), Error> { ) -> Result<(File, Bytes), Error> {
use io::{Read, Seek}; use io::{Read as _, Seek as _};
let res = actix_web::rt::task::spawn_blocking(move || { let res = actix_web::rt::task::spawn_blocking(move || {
let mut buf = Vec::with_capacity(max_bytes); let mut buf = Vec::with_capacity(max_bytes);
@ -117,6 +106,7 @@ async fn chunked_read_file_callback(
mut bytes_mut: BytesMut, mut bytes_mut: BytesMut,
) -> io::Result<(File, Bytes, BytesMut)> { ) -> io::Result<(File, Bytes, BytesMut)> {
bytes_mut.reserve(max_bytes); bytes_mut.reserve(max_bytes);
let (res, mut bytes_mut) = file.read_at(bytes_mut, offset).await; let (res, mut bytes_mut) = file.read_at(bytes_mut, offset).await;
let n_bytes = res?; let n_bytes = res?;

View File

@ -33,12 +33,12 @@ mod path_buf;
mod range; mod range;
mod service; mod service;
pub use crate::chunked::ChunkedReadFile; pub use self::chunked::ChunkedReadFile;
pub use crate::directory::Directory; pub use self::directory::Directory;
pub use crate::files::Files; pub use self::files::Files;
pub use crate::named::NamedFile; pub use self::named::NamedFile;
pub use crate::range::HttpRange; pub use self::range::HttpRange;
pub use crate::service::FilesService; pub use self::service::FilesService;
use self::directory::{directory_listing, DirectoryRenderer}; use self::directory::{directory_listing, DirectoryRenderer};
use self::error::FilesError; use self::error::FilesError;
@ -81,7 +81,6 @@ mod tests {
}; };
use super::*; use super::*;
use crate::named::File; use crate::named::File;
#[actix_web::test] #[actix_web::test]

View File

@ -90,7 +90,7 @@ impl fmt::Debug for NamedFile {
"file", "file",
#[cfg(feature = "experimental-io-uring")] #[cfg(feature = "experimental-io-uring")]
{ {
&"File" &"tokio_uring::File"
}, },
#[cfg(not(feature = "experimental-io-uring"))] #[cfg(not(feature = "experimental-io-uring"))]
{ {
@ -120,7 +120,6 @@ impl NamedFile {
/// `ContentDisposition` headers. /// `ContentDisposition` headers.
/// ///
/// # Examples /// # Examples
///
/// ```ignore /// ```ignore
/// use actix_files::NamedFile; /// use actix_files::NamedFile;
/// use std::io::{self, Write}; /// use std::io::{self, Write};
@ -194,12 +193,14 @@ impl NamedFile {
let fd = file.as_raw_fd(); let fd = file.as_raw_fd();
// SAFETY: fd is borrowed and lives longer than the unsafe block. // SAFETY: fd is borrowed and lives longer than the unsafe block
unsafe { unsafe {
let fs = std::fs::File::from_raw_fd(fd); let file = std::fs::File::from_raw_fd(fd);
let res = fs.metadata(); let md = file.metadata();
std::mem::forget(fs); // SAFETY: forget the fd before exiting block in success or error case but don't
res? // run destructor (that would close file handle)
std::mem::forget(file);
md?
} }
} }
}; };
@ -224,10 +225,8 @@ impl NamedFile {
/// Attempts to open a file in read-only mode. /// Attempts to open a file in read-only mode.
/// ///
/// # Examples /// # Examples
///
/// ``` /// ```
/// use actix_files::NamedFile; /// use actix_files::NamedFile;
///
/// let file = NamedFile::open("foo.txt"); /// let file = NamedFile::open("foo.txt");
/// ``` /// ```
pub fn open<P: AsRef<Path>>(path: P) -> io::Result<NamedFile> { pub fn open<P: AsRef<Path>>(path: P) -> io::Result<NamedFile> {
@ -237,11 +236,12 @@ impl NamedFile {
/// Attempts to open a file asynchronously in read-only mode. /// Attempts to open a file asynchronously in read-only mode.
/// ///
/// # Examples /// When the `experimental-io-uring` crate feature is enabled, this will be async.
/// Otherwise, it will be just like [`open`][Self::open].
/// ///
/// # Examples
/// ``` /// ```
/// use actix_files::NamedFile; /// use actix_files::NamedFile;
///
/// # async fn open() { /// # async fn open() {
/// let file = NamedFile::open_async("foo.txt").await.unwrap(); /// let file = NamedFile::open_async("foo.txt").await.unwrap();
/// # } /// # }
@ -271,7 +271,6 @@ impl NamedFile {
/// Retrieve the path of this file. /// Retrieve the path of this file.
/// ///
/// # Examples /// # Examples
///
/// ``` /// ```
/// # use std::io; /// # use std::io;
/// use actix_files::NamedFile; /// use actix_files::NamedFile;
@ -584,13 +583,13 @@ fn none_match(etag: Option<&header::EntityTag>, req: &HttpRequest) -> bool {
impl Deref for NamedFile { impl Deref for NamedFile {
type Target = File; type Target = File;
fn deref(&self) -> &File { fn deref(&self) -> &Self::Target {
&self.file &self.file
} }
} }
impl DerefMut for NamedFile { impl DerefMut for NamedFile {
fn deref_mut(&mut self) -> &mut File { fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.file &mut self.file
} }
} }

View File

@ -17,7 +17,7 @@ use crate::{
/// Assembled file serving service. /// Assembled file serving service.
#[derive(Clone)] #[derive(Clone)]
pub struct FilesService(pub Rc<FilesServiceInner>); pub struct FilesService(pub(crate) Rc<FilesServiceInner>);
impl Deref for FilesService { impl Deref for FilesService {
type Target = FilesServiceInner; type Target = FilesServiceInner;

View File

@ -1,6 +1,9 @@
# Changes # Changes
## Unreleased - 2021-xx-xx ## Unreleased - 2021-xx-xx
* Fix compatibility with experimental `io-uring` feature of `actix-rt`. [#2408]
[#2408]: https://github.com/actix/actix-web/pull/2408
## 3.0.0-beta.6 - 2021-11-15 ## 3.0.0-beta.6 - 2021-11-15

View File

@ -1,6 +1,9 @@
# Changes # Changes
## Unreleased - 2021-xx-xx ## Unreleased - 2021-xx-xx
* Fix compatibility with experimental `io-uring` feature of `actix-rt`. [#2408]
[#2408]: https://github.com/actix/actix-web/pull/2408
## 0.1.0-beta.6 - 2021-11-15 ## 0.1.0-beta.6 - 2021-11-15