mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-05 18:35:22 +02:00
Compare commits
19 Commits
real-async
...
files-v0.6
Author | SHA1 | Date | |
---|---|---|---|
08a9c66568 | |||
83be07d77d | |||
33da480709 | |||
fcfc727295 | |||
ac04d80d8e | |||
d2bd549eec | |||
46dde69d50 | |||
febba786fa | |||
561cc440b2 | |||
ccb90dd5a1 | |||
1c88af50c0 | |||
f4f459d420 | |||
d14e98b62b | |||
f4851b3914 | |||
68597b5426 | |||
9dc3ad754e | |||
17060ed993 | |||
0d9ca4d939 | |||
ff2904ee78 |
8
.github/workflows/ci-post-merge.yml
vendored
8
.github/workflows/ci-post-merge.yml
vendored
@ -45,7 +45,7 @@ jobs:
|
||||
toolchain: ${{ matrix.version.version }}
|
||||
|
||||
- name: Install cargo-hack
|
||||
uses: taiki-e/install-action@v2.22.0
|
||||
uses: taiki-e/install-action@v2.24.1
|
||||
with:
|
||||
tool: cargo-hack
|
||||
|
||||
@ -71,7 +71,7 @@ jobs:
|
||||
|
||||
- name: Clear the cargo caches
|
||||
run: |
|
||||
cargo install cargo-cache --version 0.8.3 --no-default-features --features ci-autoclean
|
||||
cargo --locked install cargo-cache --version 0.8.3 --no-default-features --features ci-autoclean
|
||||
cargo-cache
|
||||
|
||||
ci_feature_powerset_check:
|
||||
@ -85,7 +85,7 @@ jobs:
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.6.0
|
||||
|
||||
- name: Install cargo-hack
|
||||
uses: taiki-e/install-action@v2.22.0
|
||||
uses: taiki-e/install-action@v2.24.1
|
||||
with:
|
||||
tool: cargo-hack
|
||||
|
||||
@ -106,7 +106,7 @@ jobs:
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.6.0
|
||||
|
||||
- name: Install nextest
|
||||
uses: taiki-e/install-action@v2.22.0
|
||||
uses: taiki-e/install-action@v2.24.1
|
||||
with:
|
||||
tool: nextest
|
||||
|
||||
|
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -50,7 +50,7 @@ jobs:
|
||||
toolchain: ${{ matrix.version.version }}
|
||||
|
||||
- name: Install cargo-hack
|
||||
uses: taiki-e/install-action@v2.22.0
|
||||
uses: taiki-e/install-action@v2.24.1
|
||||
with:
|
||||
tool: cargo-hack
|
||||
|
||||
@ -83,7 +83,7 @@ jobs:
|
||||
|
||||
- name: Clear the cargo caches
|
||||
run: |
|
||||
cargo install cargo-cache --version 0.8.3 --no-default-features --features ci-autoclean
|
||||
cargo --locked install cargo-cache --version 0.8.3 --no-default-features --features ci-autoclean
|
||||
cargo-cache
|
||||
|
||||
io-uring:
|
||||
|
2
.github/workflows/coverage.yml
vendored
2
.github/workflows/coverage.yml
vendored
@ -23,7 +23,7 @@ jobs:
|
||||
components: llvm-tools-preview
|
||||
|
||||
- name: Install cargo-llvm-cov
|
||||
uses: taiki-e/install-action@v2.22.0
|
||||
uses: taiki-e/install-action@v2.24.1
|
||||
with:
|
||||
tool: cargo-llvm-cov
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
overrides:
|
||||
- files: '*.md'
|
||||
- files: "*.md"
|
||||
options:
|
||||
printWidth: 9999
|
||||
proseWrap: never
|
||||
|
@ -2,6 +2,13 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 0.6.5
|
||||
|
||||
- Fix handling of special characters in filenames.
|
||||
|
||||
## 0.6.4
|
||||
|
||||
- Fix handling of newlines in filenames.
|
||||
- Minimum supported Rust version (MSRV) is now 1.68 due to transitive `time` dependency.
|
||||
|
||||
## 0.6.3
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-files"
|
||||
version = "0.6.3"
|
||||
version = "0.6.5"
|
||||
authors = [
|
||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||
"Rob Ede <robjtede@icloud.com>",
|
||||
|
@ -1,18 +1,32 @@
|
||||
# actix-files
|
||||
# `actix-files`
|
||||
|
||||
> Static file serving for Actix Web
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-files)
|
||||
[](https://docs.rs/actix-files/0.6.3)
|
||||
[](https://docs.rs/actix-files/0.6.5)
|
||||

|
||||

|
||||
<br />
|
||||
[](https://deps.rs/crate/actix-files/0.6.3)
|
||||
[](https://deps.rs/crate/actix-files/0.6.5)
|
||||
[](https://crates.io/crates/actix-files)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
## Documentation & Resources
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
- [API Documentation](https://docs.rs/actix-files)
|
||||
- [Example Project](https://github.com/actix/examples/tree/master/basics/static-files)
|
||||
- Minimum Supported Rust Version (MSRV): 1.68
|
||||
<!-- cargo-rdme start -->
|
||||
|
||||
Static file serving for Actix Web.
|
||||
|
||||
Provides a non-blocking service for serving static files from disk.
|
||||
|
||||
## Examples
|
||||
|
||||
```rust
|
||||
use actix_web::App;
|
||||
use actix_files::Files;
|
||||
|
||||
let app = App::new()
|
||||
.service(Files::new("/static", ".").prefer_utf8(true));
|
||||
```
|
||||
|
||||
<!-- cargo-rdme end -->
|
||||
|
@ -568,6 +568,29 @@ mod tests {
|
||||
assert_eq!(bytes, data);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_static_files_with_special_characters() {
|
||||
// Create the file we want to test against ad-hoc. We can't check it in as otherwise
|
||||
// Windows can't even checkout this repository.
|
||||
let temp_dir = tempfile::tempdir().unwrap();
|
||||
let file_with_newlines = temp_dir.path().join("test\n\x0B\x0C\rnewline.text");
|
||||
fs::write(&file_with_newlines, "Look at my newlines").unwrap();
|
||||
|
||||
let srv = test::init_service(
|
||||
App::new().service(Files::new("/", temp_dir.path()).index_file("Cargo.toml")),
|
||||
)
|
||||
.await;
|
||||
let request = TestRequest::get()
|
||||
.uri("/test%0A%0B%0C%0Dnewline.text")
|
||||
.to_request();
|
||||
let response = test::call_service(&srv, request).await;
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
|
||||
let bytes = test::read_body(response).await;
|
||||
let data = web::Bytes::from(fs::read(file_with_newlines).unwrap());
|
||||
assert_eq!(bytes, data);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_files_not_allowed() {
|
||||
let srv = test::init_service(App::new().service(Files::new("/", "."))).await;
|
||||
@ -840,9 +863,9 @@ mod tests {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_percent_encoding_2() {
|
||||
let tmpdir = tempfile::tempdir().unwrap();
|
||||
let temp_dir = tempfile::tempdir().unwrap();
|
||||
let filename = match cfg!(unix) {
|
||||
true => "ض:?#[]{}<>()@!$&'`|*+,;= %20.test",
|
||||
true => "ض:?#[]{}<>()@!$&'`|*+,;= %20\n.test",
|
||||
false => "ض#[]{}()@!$&'`+,;= %20.test",
|
||||
};
|
||||
let filename_encoded = filename
|
||||
@ -852,9 +875,9 @@ mod tests {
|
||||
write!(&mut buf, "%{:02X}", c).unwrap();
|
||||
buf
|
||||
});
|
||||
std::fs::File::create(tmpdir.path().join(filename)).unwrap();
|
||||
std::fs::File::create(temp_dir.path().join(filename)).unwrap();
|
||||
|
||||
let srv = test::init_service(App::new().service(Files::new("", tmpdir.path()))).await;
|
||||
let srv = test::init_service(App::new().service(Files::new("/", temp_dir.path()))).await;
|
||||
|
||||
let req = TestRequest::get()
|
||||
.uri(&format!("/{}", filename_encoded))
|
||||
|
@ -24,7 +24,6 @@ use bitflags::bitflags;
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use mime::Mime;
|
||||
use mime_guess::from_path;
|
||||
|
||||
use crate::{encoding::equiv_utf8_text, range::HttpRange};
|
||||
|
||||
@ -128,7 +127,7 @@ impl NamedFile {
|
||||
}
|
||||
};
|
||||
|
||||
let ct = from_path(&path).first_or_octet_stream();
|
||||
let ct = mime_guess::from_path(&path).first_or_octet_stream();
|
||||
|
||||
let disposition = match ct.type_() {
|
||||
mime::IMAGE | mime::TEXT | mime::AUDIO | mime::VIDEO => DispositionType::Inline,
|
||||
@ -140,7 +139,13 @@ impl NamedFile {
|
||||
_ => DispositionType::Attachment,
|
||||
};
|
||||
|
||||
let mut parameters = vec![DispositionParam::Filename(String::from(filename.as_ref()))];
|
||||
// replace special characters in filenames which could occur on some filesystems
|
||||
let filename_s = filename
|
||||
.replace('\n', "%0A") // \n line break
|
||||
.replace('\x0B', "%0B") // \v vertical tab
|
||||
.replace('\x0C', "%0C") // \f form feed
|
||||
.replace('\r', "%0D"); // \r carriage return
|
||||
let mut parameters = vec![DispositionParam::Filename(filename_s)];
|
||||
|
||||
if !filename.is_ascii() {
|
||||
parameters.push(DispositionParam::FilenameExt(ExtendedValue {
|
||||
|
@ -1,7 +1,9 @@
|
||||
# actix-http-test
|
||||
# `actix-http-test`
|
||||
|
||||
> Various helpers for Actix applications to use during testing.
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-http-test)
|
||||
[](https://docs.rs/actix-http-test/3.1.0)
|
||||

|
||||
@ -11,6 +13,8 @@
|
||||
[](https://crates.io/crates/actix-http-test)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
## Documentation & Resources
|
||||
|
||||
- [API Documentation](https://docs.rs/actix-http-test)
|
||||
|
@ -2,14 +2,25 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Changed
|
||||
|
||||
- Updated `zstd` dependency to `0.13`.
|
||||
- Implemented `From<HeaderMap>` for `http::HeaderMap`.
|
||||
## 3.5.1
|
||||
|
||||
### Fixed
|
||||
|
||||
- Do not encode zero-sized response bodies
|
||||
- Prevent hang when returning zero-sized response bodies through compression layer.
|
||||
|
||||
## 3.5.0
|
||||
|
||||
### Added
|
||||
|
||||
- Implement `From<HeaderMap>` for `http::HeaderMap`.
|
||||
|
||||
### Changed
|
||||
|
||||
- Updated `zstd` dependency to `0.13`.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Prevent compression of zero-sized response bodies.
|
||||
|
||||
## 3.4.0
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-http"
|
||||
version = "3.4.0"
|
||||
version = "3.5.1"
|
||||
authors = [
|
||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||
"Rob Ede <robjtede@icloud.com>",
|
||||
|
@ -5,11 +5,11 @@
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-http)
|
||||
[](https://docs.rs/actix-http/3.4.0)
|
||||
[](https://docs.rs/actix-http/3.5.1)
|
||||

|
||||

|
||||
<br />
|
||||
[](https://deps.rs/crate/actix-http/3.4.0)
|
||||
[](https://deps.rs/crate/actix-http/3.5.1)
|
||||
[](https://crates.io/crates/actix-http)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
|
@ -50,10 +50,21 @@ impl<B: MessageBody> Encoder<B> {
|
||||
}
|
||||
}
|
||||
|
||||
fn empty() -> Self {
|
||||
Encoder {
|
||||
body: EncoderBody::Full { body: Bytes::new() },
|
||||
encoder: None,
|
||||
fut: None,
|
||||
eof: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn response(encoding: ContentEncoding, head: &mut ResponseHead, body: B) -> Self {
|
||||
// no need to compress an empty body
|
||||
if matches!(body.size(), BodySize::None | BodySize::Sized(0)) {
|
||||
return Self::none();
|
||||
// no need to compress empty bodies
|
||||
match body.size() {
|
||||
BodySize::None => return Self::none(),
|
||||
BodySize::Sized(0) => return Self::empty(),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let should_encode = !(head.headers().contains_key(&CONTENT_ENCODING)
|
||||
|
@ -16,7 +16,10 @@ pub struct RequestHead {
|
||||
pub uri: Uri,
|
||||
pub version: Version,
|
||||
pub headers: HeaderMap,
|
||||
|
||||
/// Will only be None when called in unit tests unless [`TestRequest::peer_addr`] is used.
|
||||
pub peer_addr: Option<net::SocketAddr>,
|
||||
|
||||
flags: Flags,
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ impl<P> Request<P> {
|
||||
/// Peer address is the directly connected peer's socket address. If a proxy is used in front of
|
||||
/// the Actix Web server, then it would be address of this proxy.
|
||||
///
|
||||
/// Will only return None when called in unit tests.
|
||||
/// Will only return None when called in unit tests unless set manually.
|
||||
#[inline]
|
||||
pub fn peer_addr(&self) -> Option<net::SocketAddr> {
|
||||
self.head().peer_addr
|
||||
|
@ -1,7 +1,9 @@
|
||||
# actix-multipart-derive
|
||||
# `actix-multipart-derive`
|
||||
|
||||
> The derive macro implementation for actix-multipart-derive.
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-multipart-derive)
|
||||
[](https://docs.rs/actix-multipart-derive/0.6.1)
|
||||

|
||||
@ -11,6 +13,8 @@
|
||||
[](https://crates.io/crates/actix-multipart-derive)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
## Documentation & Resources
|
||||
|
||||
- [API Documentation](https://docs.rs/actix-multipart-derive)
|
||||
|
@ -1,7 +1,9 @@
|
||||
# actix-multipart
|
||||
# `actix-multipart`
|
||||
|
||||
> Multipart form support for Actix Web.
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-multipart)
|
||||
[](https://docs.rs/actix-multipart/0.6.1)
|
||||

|
||||
@ -11,6 +13,8 @@
|
||||
[](https://crates.io/crates/actix-multipart)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
## Documentation & Resources
|
||||
|
||||
- [API Documentation](https://docs.rs/actix-multipart)
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 0.5.2
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.68 due to transitive `time` dependency.
|
||||
|
||||
## 0.5.1
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-router"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
authors = [
|
||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||
"Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com>",
|
||||
|
@ -1,14 +1,18 @@
|
||||
# `actix-router`
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-router)
|
||||
[](https://docs.rs/actix-router/0.5.1)
|
||||
[](https://docs.rs/actix-router/0.5.2)
|
||||

|
||||

|
||||
<br />
|
||||
[](https://deps.rs/crate/actix-router/0.5.1)
|
||||
[](https://deps.rs/crate/actix-router/0.5.2)
|
||||
[](https://crates.io/crates/actix-router)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
<!-- cargo-rdme start -->
|
||||
|
||||
Resource path matching and router.
|
||||
|
@ -1,7 +1,9 @@
|
||||
# actix-web-actors
|
||||
# `actix-web-actors`
|
||||
|
||||
> Actix actors support for Actix Web.
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-web-actors)
|
||||
[](https://docs.rs/actix-web-actors/4.2.0)
|
||||

|
||||
@ -11,6 +13,8 @@
|
||||
[](https://crates.io/crates/actix-web-actors)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
## Documentation & Resources
|
||||
|
||||
- [API Documentation](https://docs.rs/actix-web-actors)
|
||||
|
@ -1,7 +1,9 @@
|
||||
# actix-web-codegen
|
||||
# `actix-web-codegen`
|
||||
|
||||
> Routing and runtime macros for Actix Web.
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-web-codegen)
|
||||
[](https://docs.rs/actix-web-codegen/4.2.2)
|
||||

|
||||
@ -11,6 +13,8 @@
|
||||
[](https://crates.io/crates/actix-web-codegen)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
## Documentation & Resources
|
||||
|
||||
- [API Documentation](https://docs.rs/actix-web-codegen)
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 4.4.1
|
||||
|
||||
### Changed
|
||||
|
||||
- Updated `zstd` dependency to `0.13`.
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-web"
|
||||
version = "4.4.0"
|
||||
version = "4.4.1"
|
||||
description = "Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust"
|
||||
authors = [
|
||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||
@ -75,7 +75,7 @@ actix-service = "2"
|
||||
actix-utils = "3"
|
||||
actix-tls = { version = "3.1", default-features = false, optional = true }
|
||||
|
||||
actix-http = { version = "3.4", features = ["ws"] }
|
||||
actix-http = { version = "3.5", features = ["ws"] }
|
||||
actix-router = "0.5"
|
||||
actix-web-codegen = { version = "4.2", optional = true }
|
||||
|
||||
|
@ -8,10 +8,10 @@
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-web)
|
||||
[](https://docs.rs/actix-web/4.4.0)
|
||||
[](https://docs.rs/actix-web/4.4.1)
|
||||

|
||||

|
||||
[](https://deps.rs/crate/actix-web/4.4.0)
|
||||
[](https://deps.rs/crate/actix-web/4.4.1)
|
||||
<br />
|
||||
[](https://github.com/actix/actix-web/actions/workflows/ci.yml)
|
||||
[](https://codecov.io/gh/actix/actix-web)
|
||||
|
@ -221,12 +221,9 @@ impl ServiceRequest {
|
||||
|
||||
/// Returns peer's socket address.
|
||||
///
|
||||
/// Peer address is the directly connected peer's socket address. If a proxy is used in front of
|
||||
/// the Actix Web server, then it would be address of this proxy.
|
||||
/// See [`HttpRequest::peer_addr`] for more details.
|
||||
///
|
||||
/// To get client connection information `ConnectionInfo` should be used.
|
||||
///
|
||||
/// Will only return None when called in unit tests.
|
||||
/// [`HttpRequest::peer_addr`]: crate::HttpRequest::peer_addr
|
||||
#[inline]
|
||||
pub fn peer_addr(&self) -> Option<net::SocketAddr> {
|
||||
self.head().peer_addr
|
||||
|
@ -86,76 +86,77 @@ impl Default for TestRequest {
|
||||
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
impl TestRequest {
|
||||
/// Create TestRequest and set request uri
|
||||
pub fn with_uri(path: &str) -> TestRequest {
|
||||
TestRequest::default().uri(path)
|
||||
/// Constructs test request and sets request URI.
|
||||
pub fn with_uri(uri: &str) -> TestRequest {
|
||||
TestRequest::default().uri(uri)
|
||||
}
|
||||
|
||||
/// Create TestRequest and set method to `Method::GET`
|
||||
/// Constructs test request with GET method.
|
||||
pub fn get() -> TestRequest {
|
||||
TestRequest::default().method(Method::GET)
|
||||
}
|
||||
|
||||
/// Create TestRequest and set method to `Method::POST`
|
||||
/// Constructs test request with POST method.
|
||||
pub fn post() -> TestRequest {
|
||||
TestRequest::default().method(Method::POST)
|
||||
}
|
||||
|
||||
/// Create TestRequest and set method to `Method::PUT`
|
||||
/// Constructs test request with PUT method.
|
||||
pub fn put() -> TestRequest {
|
||||
TestRequest::default().method(Method::PUT)
|
||||
}
|
||||
|
||||
/// Create TestRequest and set method to `Method::PATCH`
|
||||
/// Constructs test request with PATCH method.
|
||||
pub fn patch() -> TestRequest {
|
||||
TestRequest::default().method(Method::PATCH)
|
||||
}
|
||||
|
||||
/// Create TestRequest and set method to `Method::DELETE`
|
||||
/// Constructs test request with DELETE method.
|
||||
pub fn delete() -> TestRequest {
|
||||
TestRequest::default().method(Method::DELETE)
|
||||
}
|
||||
|
||||
/// Set HTTP version of this request
|
||||
/// Sets HTTP version of this request.
|
||||
pub fn version(mut self, ver: Version) -> Self {
|
||||
self.req.version(ver);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set HTTP method of this request
|
||||
/// Sets method of this request.
|
||||
pub fn method(mut self, meth: Method) -> Self {
|
||||
self.req.method(meth);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set HTTP URI of this request
|
||||
/// Sets URI of this request.
|
||||
pub fn uri(mut self, path: &str) -> Self {
|
||||
self.req.uri(path);
|
||||
self
|
||||
}
|
||||
|
||||
/// Insert a header, replacing any that were set with an equivalent field name.
|
||||
/// Inserts a header, replacing any that were set with an equivalent field name.
|
||||
pub fn insert_header(mut self, header: impl TryIntoHeaderPair) -> Self {
|
||||
self.req.insert_header(header);
|
||||
self
|
||||
}
|
||||
|
||||
/// Append a header, keeping any that were set with an equivalent field name.
|
||||
/// Appends a header, keeping any that were set with an equivalent field name.
|
||||
pub fn append_header(mut self, header: impl TryIntoHeaderPair) -> Self {
|
||||
self.req.append_header(header);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set cookie for this request.
|
||||
/// Sets cookie for this request.
|
||||
#[cfg(feature = "cookies")]
|
||||
pub fn cookie(mut self, cookie: Cookie<'_>) -> Self {
|
||||
self.cookies.add(cookie.into_owned());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set request path pattern parameter.
|
||||
/// Sets request path pattern parameter.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use actix_web::test::TestRequest;
|
||||
///
|
||||
@ -171,19 +172,19 @@ impl TestRequest {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set peer addr.
|
||||
/// Sets peer address.
|
||||
pub fn peer_addr(mut self, addr: SocketAddr) -> Self {
|
||||
self.peer_addr = Some(addr);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set request payload.
|
||||
/// Sets request payload.
|
||||
pub fn set_payload(mut self, data: impl Into<Bytes>) -> Self {
|
||||
self.req.set_payload(data);
|
||||
self
|
||||
}
|
||||
|
||||
/// Serialize `data` to a URL encoded form and set it as the request payload.
|
||||
/// Serializes `data` to a URL encoded form and set it as the request payload.
|
||||
///
|
||||
/// The `Content-Type` header is set to `application/x-www-form-urlencoded`.
|
||||
pub fn set_form(mut self, data: impl Serialize) -> Self {
|
||||
@ -194,7 +195,7 @@ impl TestRequest {
|
||||
self
|
||||
}
|
||||
|
||||
/// Serialize `data` to JSON and set it as the request payload.
|
||||
/// Serializes `data` to JSON and set it as the request payload.
|
||||
///
|
||||
/// The `Content-Type` header is set to `application/json`.
|
||||
pub fn set_json(mut self, data: impl Serialize) -> Self {
|
||||
@ -204,27 +205,33 @@ impl TestRequest {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set application data. This is equivalent of `App::data()` method
|
||||
/// for testing purpose.
|
||||
pub fn data<T: 'static>(mut self, data: T) -> Self {
|
||||
self.app_data.insert(Data::new(data));
|
||||
self
|
||||
}
|
||||
|
||||
/// Set application data. This is equivalent of `App::app_data()` method
|
||||
/// for testing purpose.
|
||||
/// Inserts application data.
|
||||
///
|
||||
/// This is equivalent of `App::app_data()` method for testing purpose.
|
||||
pub fn app_data<T: 'static>(mut self, data: T) -> Self {
|
||||
self.app_data.insert(data);
|
||||
self
|
||||
}
|
||||
|
||||
/// Inserts application data.
|
||||
///
|
||||
/// This is equivalent of `App::data()` method for testing purpose.
|
||||
#[doc(hidden)]
|
||||
pub fn data<T: 'static>(mut self, data: T) -> Self {
|
||||
self.app_data.insert(Data::new(data));
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets resource map.
|
||||
#[cfg(test)]
|
||||
/// Set request config
|
||||
pub(crate) fn rmap(mut self, rmap: ResourceMap) -> Self {
|
||||
self.rmap = rmap;
|
||||
self
|
||||
}
|
||||
|
||||
/// Finalizes test request.
|
||||
///
|
||||
/// This request builder will be useless after calling `finish()`.
|
||||
fn finish(&mut self) -> Request {
|
||||
// mut used when cookie feature is enabled
|
||||
#[allow(unused_mut)]
|
||||
@ -251,14 +258,14 @@ impl TestRequest {
|
||||
req
|
||||
}
|
||||
|
||||
/// Complete request creation and generate `Request` instance
|
||||
/// Finalizes request creation and returns `Request` instance.
|
||||
pub fn to_request(mut self) -> Request {
|
||||
let mut req = self.finish();
|
||||
req.head_mut().peer_addr = self.peer_addr;
|
||||
req
|
||||
}
|
||||
|
||||
/// Complete request creation and generate `ServiceRequest` instance
|
||||
/// Finalizes request creation and returns `ServiceRequest` instance.
|
||||
pub fn to_srv_request(mut self) -> ServiceRequest {
|
||||
let (mut head, payload) = self.finish().into_parts();
|
||||
head.peer_addr = self.peer_addr;
|
||||
@ -279,12 +286,12 @@ impl TestRequest {
|
||||
)
|
||||
}
|
||||
|
||||
/// Complete request creation and generate `ServiceResponse` instance
|
||||
/// Finalizes request creation and returns `ServiceResponse` instance.
|
||||
pub fn to_srv_response<B>(self, res: HttpResponse<B>) -> ServiceResponse<B> {
|
||||
self.to_srv_request().into_response(res)
|
||||
}
|
||||
|
||||
/// Complete request creation and generate `HttpRequest` instance
|
||||
/// Finalizes request creation and returns `HttpRequest` instance.
|
||||
pub fn to_http_request(mut self) -> HttpRequest {
|
||||
let (mut head, _) = self.finish().into_parts();
|
||||
head.peer_addr = self.peer_addr;
|
||||
@ -302,7 +309,7 @@ impl TestRequest {
|
||||
)
|
||||
}
|
||||
|
||||
/// Complete request creation and generate `HttpRequest` and `Payload` instances
|
||||
/// Finalizes request creation and returns `HttpRequest` and `Payload` pair.
|
||||
pub fn to_http_parts(mut self) -> (HttpRequest, Payload) {
|
||||
let (mut head, payload) = self.finish().into_parts();
|
||||
head.peer_addr = self.peer_addr;
|
||||
@ -322,7 +329,7 @@ impl TestRequest {
|
||||
(req, payload)
|
||||
}
|
||||
|
||||
/// Complete request creation, calls service and waits for response future completion.
|
||||
/// Finalizes request creation, calls service, and waits for response future completion.
|
||||
pub async fn send_request<S, B, E>(self, app: &S) -> S::Response
|
||||
where
|
||||
S: Service<Request, Response = ServiceResponse<B>, Error = E>,
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 3.3.0
|
||||
|
||||
- Update `trust-dns-resolver` dependency to `0.23`.
|
||||
- Updated `zstd` dependency to `0.13`.
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "awc"
|
||||
version = "3.2.0"
|
||||
version = "3.3.0"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "Async HTTP and WebSocket client library"
|
||||
keywords = ["actix", "http", "framework", "async", "web"]
|
||||
@ -61,7 +61,7 @@ dangerous-h2c = []
|
||||
[dependencies]
|
||||
actix-codec = "0.5"
|
||||
actix-service = "2"
|
||||
actix-http = { version = "3.4", features = ["http2", "ws"] }
|
||||
actix-http = { version = "3.5", features = ["http2", "ws"] }
|
||||
actix-rt = { version = "2.1", default-features = false }
|
||||
actix-tls = { version = "3.1", features = ["connect", "uri"] }
|
||||
actix-utils = "3"
|
||||
@ -94,7 +94,7 @@ tls-rustls-0_21 = { package = "rustls", version = "0.21", optional = true, featu
|
||||
trust-dns-resolver = { version = "0.23", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-http = { version = "3.4", features = ["openssl"] }
|
||||
actix-http = { version = "3.5", features = ["openssl"] }
|
||||
actix-http-test = { version = "3", features = ["openssl"] }
|
||||
actix-server = "2"
|
||||
actix-test = { version = "0.1", features = ["openssl", "rustls-0_21"] }
|
||||
|
@ -1,13 +1,17 @@
|
||||
# awc (Actix Web Client)
|
||||
# `awc` (Actix Web Client)
|
||||
|
||||
> Async HTTP and WebSocket client library.
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/awc)
|
||||
[](https://docs.rs/awc/3.2.0)
|
||||
[](https://docs.rs/awc/3.3.0)
|
||||

|
||||
[](https://deps.rs/crate/awc/3.2.0)
|
||||
[](https://deps.rs/crate/awc/3.3.0)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
## Documentation & Resources
|
||||
|
||||
- [API Documentation](https://docs.rs/awc)
|
||||
|
10
justfile
10
justfile
@ -1,6 +1,11 @@
|
||||
_list:
|
||||
@just --list
|
||||
|
||||
# Format workspace.
|
||||
fmt:
|
||||
cargo +nightly fmt
|
||||
npx -y prettier --write $(fd --type=file --hidden --extension=md --extension=yml)
|
||||
|
||||
# Document crates in workspace.
|
||||
doc:
|
||||
RUSTDOCFLAGS="--cfg=docsrs" cargo +nightly doc --no-deps --workspace --features=rustls,openssl
|
||||
@ -9,3 +14,8 @@ doc:
|
||||
doc-watch:
|
||||
RUSTDOCFLAGS="--cfg=docsrs" cargo +nightly doc --no-deps --workspace --features=rustls,openssl --open
|
||||
cargo watch -- RUSTDOCFLAGS="--cfg=docsrs" cargo +nightly doc --no-deps --workspace --features=rustls,openssl
|
||||
|
||||
# Update READMEs from crate root documentation.
|
||||
update-readmes: && fmt
|
||||
cd ./actix-files && cargo rdme --force
|
||||
cd ./actix-router && cargo rdme --force
|
||||
|
19
scripts/bump
19
scripts/bump
@ -5,7 +5,7 @@
|
||||
|
||||
# requires github cli tool for automatic release draft creation
|
||||
|
||||
set -euo pipefail
|
||||
set -eEuo pipefail
|
||||
|
||||
DIR=$1
|
||||
|
||||
@ -112,17 +112,25 @@ echo
|
||||
read -p "Update all references: (y/N) " UPDATE_REFERENCES
|
||||
UPDATE_REFERENCES="${UPDATE_REFERENCES:-n}"
|
||||
|
||||
|
||||
if [ "$UPDATE_REFERENCES" = 'y' ] || [ "$UPDATE_REFERENCES" = 'Y' ]; then
|
||||
if [[ $NEW_VERSION == *".0.0" ]]; then
|
||||
NEW_VERSION_SPEC="${NEW_VERSION%.0.0}"
|
||||
elif [[ $NEW_VERSION == *".0" ]]; then
|
||||
NEW_VERSION_SPEC="${NEW_VERSION%.0}"
|
||||
else
|
||||
NEW_VERSION_SPEC="$NEW_VERSION"
|
||||
fi
|
||||
|
||||
for f in $(fd Cargo.toml); do
|
||||
sed -i.bak -E \
|
||||
"s/^(${PACKAGE_NAME} ?= ?\")[^\"]+(\")$/\1${NEW_VERSION}\2/g" $f
|
||||
"s/^(${PACKAGE_NAME} ?= ?\")[^\"]+(\")$/\1${NEW_VERSION_SPEC}\2/g" $f
|
||||
sed -i.bak -E \
|
||||
"s/^(${PACKAGE_NAME} ?=.*version ?= ?\")[^\"]+(\".*)$/\1${NEW_VERSION}\2/g" $f
|
||||
"s/^(${PACKAGE_NAME} ?=.*version ?= ?\")[^\"]+(\".*)$/\1${NEW_VERSION_SPEC}\2/g" $f
|
||||
sed -i.bak -E \
|
||||
"s/^(.*package ?= ?\"${PACKAGE_NAME}\".*version ?= ?\")[^\"]+(\".*)$/\1${NEW_VERSION}\2/g" $f
|
||||
"s/^(.*package ?= ?\"${PACKAGE_NAME}\".*version ?= ?\")[^\"]+(\".*)$/\1${NEW_VERSION_SPEC}\2/g" $f
|
||||
sed -i.bak -E \
|
||||
"s/^(.*version ?= ?\")[^\"]+(\".*package ?= ?\"${PACKAGE_NAME}\".*)$/\1${NEW_VERSION}\2/g" $f
|
||||
"s/^(.*version ?= ?\")[^\"]+(\".*package ?= ?\"${PACKAGE_NAME}\".*)$/\1${NEW_VERSION_SPEC}\2/g" $f
|
||||
|
||||
# remove backup file
|
||||
rm -f $f.bak
|
||||
@ -132,6 +140,7 @@ fi
|
||||
|
||||
if [ $MACOS ]; then
|
||||
printf "chore($PACKAGE_NAME): prepare release $NEW_VERSION" | pbcopy
|
||||
echo "placed the recommended commit message on the clipboard"
|
||||
else
|
||||
echo
|
||||
echo "commit message:"
|
||||
|
Reference in New Issue
Block a user