mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-19 07:46:12 +02:00
Compare commits
6 Commits
multipart-
...
files-chun
Author | SHA1 | Date | |
---|---|---|---|
|
c759bdef4c | ||
|
3f03af1c59 | ||
|
25c0673278 | ||
|
e7a05f9892 | ||
|
2f13e5f675 | ||
|
9f964751f6 |
@@ -33,7 +33,6 @@ mod path_buf;
|
||||
mod range;
|
||||
mod service;
|
||||
|
||||
pub use self::chunked::ChunkedReadFile;
|
||||
pub use self::directory::Directory;
|
||||
pub use self::files::Files;
|
||||
pub use self::named::NamedFile;
|
||||
|
@@ -21,8 +21,9 @@ use actix_web::{
|
||||
Error, HttpMessage, HttpRequest, HttpResponse, Responder,
|
||||
};
|
||||
use bitflags::bitflags;
|
||||
use bytes::Bytes;
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use futures_core::{future::LocalBoxFuture, Stream};
|
||||
use mime_guess::from_path;
|
||||
|
||||
use crate::{encoding::equiv_utf8_text, range::HttpRange};
|
||||
@@ -527,6 +528,11 @@ impl NamedFile {
|
||||
|
||||
res.body(SizedStream::new(length, reader))
|
||||
}
|
||||
|
||||
/// Returns stream of chunks for the complete file.
|
||||
pub fn into_chunk_stream(self) -> impl Stream<Item = Result<Bytes, Error>> {
|
||||
chunked::new_chunked_read(self.md.len(), 0, self.file)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if `req` has no `If-Match` header or one which matches `etag`.
|
||||
|
@@ -4,7 +4,8 @@
|
||||
|
||||
|
||||
## 4.0.1 - 2022-02-25
|
||||
- No significant changes since `4.0.0`.
|
||||
### Fixed
|
||||
- Use stable version in readme example.
|
||||
|
||||
|
||||
## 4.0.0 - 2022-02-25
|
||||
|
@@ -3,7 +3,7 @@
|
||||
This guide walks you through the process of migrating from v3.x.y to v4.x.y.
|
||||
If you are migrating to v4.x.y from an older version of Actix Web (v2.x.y or earlier), check out the other historical migration notes in this folder.
|
||||
|
||||
This document is not designed to be exhaustive—it focuses on the most significant changes coming in v4. You can find an exhaustive changelog in the changelogs for [`actix-web`](./CHANGES.md#400---2022-02-25) and [`actix-http`](../actix-http/CHANGES.md#300---2022-02-25), complete of PR links. If you think that some of the changes that we omitted deserve to be called out in this document, please open an issue or submit a PR.
|
||||
This document is not designed to be exhaustive—it focuses on the most significant changes in v4. You can find an exhaustive changelog in the changelogs for [`actix-web`](./CHANGES.md#400---2022-02-25) and [`actix-http`](../actix-http/CHANGES.md#300---2022-02-25), complete with PR links. If you think there are any changes that deserve to be called out in this document, please open an issue or pull request.
|
||||
|
||||
Headings marked with :warning: are **breaking behavioral changes**. They will probably not surface as compile-time errors though automated tests _might_ detect their effects on your app.
|
||||
|
||||
@@ -29,7 +29,7 @@ Headings marked with :warning: are **breaking behavioral changes**. They will pr
|
||||
- [Server Must Be Polled :warning:](#server-must-be-polled-warning)
|
||||
- [Guards API](#guards-api)
|
||||
- [Returning `HttpResponse` synchronously](#returning-httpresponse-synchronously)
|
||||
- [`#[actix_web::main]` and `#[tokio::main]`](#actixwebmain-and-tokiomain)
|
||||
- [`#[actix_web::main]` and `#[tokio::main]`](#actix_webmain-and-tokiomain)
|
||||
- [`web::block`](#webblock)
|
||||
|
||||
## MSRV
|
||||
@@ -111,6 +111,8 @@ The inner field for `web::Path` is now private. It was causing ambiguity when tr
|
||||
+ let (foo, bar) = params.into_inner();
|
||||
```
|
||||
|
||||
An alternative [path param type with public field but no `Deref` impl is available in `actix-web-lab`](https://docs.rs/actix-web-lab/0.12.0/actix_web_lab/extract/struct.Path.html).
|
||||
|
||||
## Rustls Crate Upgrade
|
||||
|
||||
Actix Web now depends on version 0.20 of `rustls`. As a result, the server config builder has changed. [See the updated example project.](https://github.com/actix/examples/tree/master/https-tls/rustls/)
|
||||
|
@@ -159,7 +159,7 @@ impl ConnectionInfo {
|
||||
pub fn realip_remote_addr(&self) -> Option<&str> {
|
||||
self.realip_remote_addr
|
||||
.as_deref()
|
||||
.or_else(|| self.peer_addr.as_deref())
|
||||
.or(self.peer_addr.as_deref())
|
||||
}
|
||||
|
||||
/// Returns serialized IP address of the peer connection.
|
||||
|
@@ -151,7 +151,7 @@ impl ResourceMap {
|
||||
.char_indices()
|
||||
.filter_map(|(i, c)| (c == '/').then(|| i))
|
||||
.nth(2)
|
||||
.unwrap_or_else(|| path.len());
|
||||
.unwrap_or(path.len());
|
||||
|
||||
(
|
||||
Cow::Borrowed(&path[..third_slash_index]),
|
||||
|
@@ -24,10 +24,10 @@ use crate::cookie::{Cookie, CookieJar};
|
||||
///
|
||||
/// For unit testing, actix provides a request builder type and a simple handler runner. TestRequest implements a builder-like pattern.
|
||||
/// You can generate various types of request via TestRequest's methods:
|
||||
/// * `TestRequest::to_request` creates `actix_http::Request` instance.
|
||||
/// * `TestRequest::to_srv_request` creates `ServiceRequest` instance, which is used for testing middlewares and chain adapters.
|
||||
/// * `TestRequest::to_srv_response` creates `ServiceResponse` instance.
|
||||
/// * `TestRequest::to_http_request` creates `HttpRequest` instance, which is used for testing handlers.
|
||||
/// - [`TestRequest::to_request`] creates an [`actix_http::Request`](Request).
|
||||
/// - [`TestRequest::to_srv_request`] creates a [`ServiceRequest`], which is used for testing middlewares and chain adapters.
|
||||
/// - [`TestRequest::to_srv_response`] creates a [`ServiceResponse`].
|
||||
/// - [`TestRequest::to_http_request`] creates an [`HttpRequest`], which is used for testing handlers.
|
||||
///
|
||||
/// ```
|
||||
/// use actix_web::{test, HttpRequest, HttpResponse, HttpMessage};
|
||||
@@ -42,15 +42,17 @@ use crate::cookie::{Cookie, CookieJar};
|
||||
/// }
|
||||
///
|
||||
/// #[actix_web::test]
|
||||
/// # // force rustdoc to display the correct thing and also compile check the test
|
||||
/// # async fn _test() {}
|
||||
/// async fn test_index() {
|
||||
/// let req = test::TestRequest::default().insert_header("content-type", "text/plain")
|
||||
/// let req = test::TestRequest::default().insert_header(header::ContentType::plaintext())
|
||||
/// .to_http_request();
|
||||
///
|
||||
/// let resp = index(req).await.unwrap();
|
||||
/// let resp = index(req).await;
|
||||
/// assert_eq!(resp.status(), StatusCode::OK);
|
||||
///
|
||||
/// let req = test::TestRequest::default().to_http_request();
|
||||
/// let resp = index(req).await.unwrap();
|
||||
/// let resp = index(req).await;
|
||||
/// assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||
/// }
|
||||
/// ```
|
||||
|
Reference in New Issue
Block a user