mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-04 01:51:30 +02:00
Compare commits
17 Commits
files-v0.2
...
identity-v
Author | SHA1 | Date | |
---|---|---|---|
39f4b2b39e | |||
f6ff056b8a | |||
51ab4fb73d | |||
f5fd6bc49f | |||
2803fcbe22 | |||
67793c5d92 | |||
bcb5086c91 | |||
7bd2270290 | |||
a4ad5e6b69 | |||
6db909a3e7 | |||
642ae161c0 | |||
7b3c99b933 | |||
f86ce0390e | |||
7882f545e5 | |||
1c75e6876b | |||
6a0cd2dced | |||
c7f3915779 |
59
.github/workflows/macos.yml
vendored
Normal file
59
.github/workflows/macos.yml
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
name: CI (macOS)
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build_and_test:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
version:
|
||||
- stable
|
||||
- nightly
|
||||
|
||||
name: ${{ matrix.version }} - x86_64-apple-darwin
|
||||
runs-on: macOS-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
|
||||
- name: Install ${{ matrix.version }}
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.version }}-x86_64-apple-darwin
|
||||
profile: minimal
|
||||
override: true
|
||||
|
||||
- name: Generate Cargo.lock
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: update
|
||||
- name: Cache cargo registry
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.cargo/registry
|
||||
key: ${{ matrix.version }}-x86_64-apple-darwin-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
||||
- name: Cache cargo index
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.cargo/git
|
||||
key: ${{ matrix.version }}-x86_64-apple-darwin-cargo-index-${{ hashFiles('**/Cargo.lock') }}
|
||||
- name: Cache cargo build
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: target
|
||||
key: ${{ matrix.version }}-x86_64-apple-darwin-cargo-build-${{ hashFiles('**/Cargo.lock') }}
|
||||
|
||||
- name: check build
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: check
|
||||
args: --all --bins --examples --tests
|
||||
|
||||
- name: tests
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
args: --all --all-features --no-fail-fast -- --nocapture
|
||||
--skip=test_h2_content_length
|
||||
--skip=test_reading_deflate_encoding_large_random_rustls
|
67
.github/workflows/main.yml
vendored
67
.github/workflows/main.yml
vendored
@ -1,67 +0,0 @@
|
||||
name: CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
env:
|
||||
VCPKGRS_DYNAMIC: 1
|
||||
|
||||
jobs:
|
||||
build_and_test:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
toolchain:
|
||||
- x86_64-pc-windows-msvc
|
||||
# - i686-pc-windows-msvc
|
||||
- x86_64-apple-darwin
|
||||
version:
|
||||
- stable
|
||||
- nightly
|
||||
include:
|
||||
- toolchain: x86_64-pc-windows-msvc
|
||||
os: windows-latest
|
||||
arch: x64
|
||||
# - toolchain: i686-pc-windows-msvc
|
||||
# os: windows-latest
|
||||
# arch: x86
|
||||
- toolchain: x86_64-apple-darwin
|
||||
os: macOS-latest
|
||||
|
||||
name: ${{ matrix.version }} - ${{ matrix.toolchain }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
|
||||
- name: Install ${{ matrix.version }}
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.version }}-${{ matrix.toolchain }}
|
||||
default: true
|
||||
|
||||
- name: Install OpenSSL
|
||||
if: matrix.os == 'windows-latest'
|
||||
run: |
|
||||
vcpkg integrate install
|
||||
vcpkg install openssl:${{ matrix.arch }}-windows
|
||||
|
||||
- name: check nightly
|
||||
if: matrix.version == 'nightly'
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: check
|
||||
args: --all --benches --bins --examples --tests
|
||||
|
||||
- name: check stable
|
||||
if: matrix.version == 'stable'
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: check
|
||||
args: --all --bins --examples --tests
|
||||
|
||||
- name: tests
|
||||
if: matrix.toolchain != 'x86_64-pc-windows-gnu'
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
args: --all --all-features -- --nocapture
|
79
.github/workflows/windows.yml
vendored
Normal file
79
.github/workflows/windows.yml
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
name: CI (Windows)
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
env:
|
||||
VCPKGRS_DYNAMIC: 1
|
||||
|
||||
jobs:
|
||||
build_and_test:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
version:
|
||||
- stable
|
||||
- nightly
|
||||
|
||||
name: ${{ matrix.version }} - x86_64-pc-windows-msvc
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
|
||||
- name: Install ${{ matrix.version }}
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.version }}-x86_64-pc-windows-msvc
|
||||
profile: minimal
|
||||
override: true
|
||||
|
||||
- name: Generate Cargo.lock
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: update
|
||||
- name: Cache cargo registry
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.cargo/registry
|
||||
key: ${{ matrix.version }}-x86_64-pc-windows-msvc-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
||||
- name: Cache cargo index
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.cargo/git
|
||||
key: ${{ matrix.version }}-x86_64-pc-windows-msvc-cargo-index-${{ hashFiles('**/Cargo.lock') }}
|
||||
- name: Cache cargo build
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: target
|
||||
key: ${{ matrix.version }}-x86_64-pc-windows-msvc-cargo-build-${{ hashFiles('**/Cargo.lock') }}
|
||||
- name: Cache vcpkg package
|
||||
uses: actions/cache@v1
|
||||
id: cache-vcpkg
|
||||
with:
|
||||
path: C:\vcpkg
|
||||
key: windows_x64-${{ matrix.version }}-vcpkg
|
||||
|
||||
- name: Install OpenSSL
|
||||
if: steps.cache-vcpkg.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
vcpkg integrate install
|
||||
vcpkg install openssl:x64-windows
|
||||
|
||||
- name: check build
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: check
|
||||
args: --all --bins --examples --tests
|
||||
|
||||
- name: tests
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
args: --all --all-features --no-fail-fast -- --nocapture
|
||||
--skip=test_h2_content_length
|
||||
--skip=test_reading_deflate_encoding_large_random_rustls
|
||||
--skip=test_params
|
||||
--skip=test_simple
|
||||
--skip=test_expect_continue
|
||||
--skip=test_http10_keepalive
|
||||
--skip=test_slow_request
|
10
CHANGES.md
10
CHANGES.md
@ -1,5 +1,15 @@
|
||||
# Changes
|
||||
|
||||
## [2.0.0] - 2019-12-25
|
||||
|
||||
### Changed
|
||||
|
||||
* Rename `HttpServer::start()` to `HttpServer::run()`
|
||||
|
||||
* Allow to gracefully stop test server via `TestServer::stop()`
|
||||
|
||||
* Allow to specify multi-patterns for resources
|
||||
|
||||
## [2.0.0-rc] - 2019-12-20
|
||||
|
||||
### Changed
|
||||
|
16
Cargo.toml
16
Cargo.toml
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-web"
|
||||
version = "2.0.0-rc"
|
||||
version = "2.0.0"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "Actix web is a simple, pragmatic and extremely fast web framework for Rust."
|
||||
readme = "README.md"
|
||||
@ -60,18 +60,18 @@ rustls = ["actix-tls/rustls", "awc/rustls", "rust-tls"]
|
||||
|
||||
[dependencies]
|
||||
actix-codec = "0.2.0"
|
||||
actix-service = "1.0.0"
|
||||
actix-utils = "1.0.3"
|
||||
actix-router = "0.2.0"
|
||||
actix-service = "1.0.1"
|
||||
actix-utils = "1.0.4"
|
||||
actix-router = "0.2.1"
|
||||
actix-rt = "1.0.0"
|
||||
actix-server = "1.0.0"
|
||||
actix-testing = "1.0.0"
|
||||
actix-macros = "0.1.0"
|
||||
actix-threadpool = "0.3.0"
|
||||
actix-threadpool = "0.3.1"
|
||||
actix-tls = "1.0.0"
|
||||
|
||||
actix-web-codegen = "0.2.0"
|
||||
actix-http = "1.0.0"
|
||||
actix-http = "1.0.1"
|
||||
awc = { version = "1.0.1", default-features = false }
|
||||
|
||||
bytes = "0.5.3"
|
||||
@ -93,7 +93,7 @@ open-ssl = { version="0.10", package = "openssl", optional = true }
|
||||
rust-tls = { version = "0.16.0", package = "rustls", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
actix = "0.9.0-alpha.2"
|
||||
actix = "0.9.0"
|
||||
rand = "0.7"
|
||||
env_logger = "0.6"
|
||||
serde_derive = "1.0"
|
||||
@ -115,4 +115,4 @@ actix-identity = { path = "actix-identity" }
|
||||
actix-session = { path = "actix-session" }
|
||||
actix-files = { path = "actix-files" }
|
||||
actix-multipart = { path = "actix-multipart" }
|
||||
awc = { path = "awc" }
|
||||
awc = { path = "awc" }
|
38
MIGRATION.md
38
MIGRATION.md
@ -1,15 +1,49 @@
|
||||
## 2.0.0
|
||||
|
||||
* `HttpServer::start()` renamed to `HttpServer::run()`. It also possible to
|
||||
`.await` on `run` method result, in that case it awaits server exit.
|
||||
|
||||
* `App::register_data()` renamed to `App::app_data()` and accepts any type `T: 'static`.
|
||||
Stored data is available via `HttpRequest::app_data()` method at runtime.
|
||||
|
||||
* Extractor configuration must be registered with `App::app_data()` instead of `App::data()`
|
||||
|
||||
* Sync handlers has been removed. `.to_async()` method has been renamed to `.to()`
|
||||
|
||||
replace `fn` with `async fn` to convert sync handler to async
|
||||
|
||||
* `TestServer::new()` renamed to `TestServer::start()`
|
||||
* `actix_http_test::TestServer` moved to `actix_web::test` module. To start
|
||||
test server use `test::start()` or `test_start_with_config()` methods
|
||||
|
||||
* `ResponseError` trait has been reafctored. `ResponseError::error_response()` renders
|
||||
http response.
|
||||
|
||||
* Feature `rust-tls` renamed to `rustls`
|
||||
|
||||
instead of
|
||||
|
||||
```rust
|
||||
actix-web = { version = "2.0.0", features = ["rust-tls"] }
|
||||
```
|
||||
|
||||
use
|
||||
|
||||
```rust
|
||||
actix-web = { version = "2.0.0", features = ["rustls"] }
|
||||
```
|
||||
|
||||
* Feature `ssl` renamed to `openssl`
|
||||
|
||||
instead of
|
||||
|
||||
```rust
|
||||
actix-web = { version = "2.0.0", features = ["ssl"] }
|
||||
```
|
||||
|
||||
use
|
||||
|
||||
```rust
|
||||
actix-web = { version = "2.0.0", features = ["openssl"] }
|
||||
```
|
||||
|
||||
|
||||
## 1.0.1
|
||||
|
@ -53,7 +53,7 @@ async fn index(info: web::Path<(u32, String)>) -> impl Responder {
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| App::new().service(index))
|
||||
.bind("127.0.0.1:8080")?
|
||||
.start()
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
```
|
||||
@ -68,7 +68,8 @@ async fn main() -> std::io::Result<()> {
|
||||
[Askama](https://github.com/actix/examples/tree/master/template_askama/) templates
|
||||
* [Diesel integration](https://github.com/actix/examples/tree/master/diesel/)
|
||||
* [r2d2](https://github.com/actix/examples/tree/master/r2d2/)
|
||||
* [SSL / HTTP/2.0](https://github.com/actix/examples/tree/master/tls/)
|
||||
* [OpenSSL](https://github.com/actix/examples/tree/master/openssl/)
|
||||
* [Rustls](https://github.com/actix/examples/tree/master/rustls/)
|
||||
* [Tcp/Websocket chat](https://github.com/actix/examples/tree/master/websocket-chat/)
|
||||
* [Json](https://github.com/actix/examples/tree/master/json/)
|
||||
|
||||
|
@ -18,7 +18,7 @@ path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "2.0.0-rc"
|
||||
actix-service = "1.0.0"
|
||||
actix-service = "1.0.1"
|
||||
derive_more = "0.99.2"
|
||||
futures = "0.3.1"
|
||||
|
||||
|
@ -814,7 +814,7 @@ where
|
||||
res
|
||||
}
|
||||
}
|
||||
.boxed_local(),
|
||||
.boxed_local(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ path = "src/lib.rs"
|
||||
[dependencies]
|
||||
actix-web = { version = "2.0.0-rc", default-features = false }
|
||||
actix-http = "1.0.1"
|
||||
actix-service = "1.0.0"
|
||||
actix-service = "1.0.1"
|
||||
bitflags = "1"
|
||||
bytes = "0.5.3"
|
||||
futures = "0.3.1"
|
||||
|
@ -178,7 +178,9 @@ 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,
|
||||
};
|
||||
|
@ -13,7 +13,6 @@ categories = ["network-programming", "asynchronous",
|
||||
"web-programming::websocket"]
|
||||
license = "MIT/Apache-2.0"
|
||||
edition = "2018"
|
||||
workspace =".."
|
||||
|
||||
[lib]
|
||||
name = "actix_framed"
|
||||
@ -21,10 +20,10 @@ path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
actix-codec = "0.2.0"
|
||||
actix-service = "1.0.0"
|
||||
actix-router = "0.2.0"
|
||||
actix-service = "1.0.1"
|
||||
actix-router = "0.2.1"
|
||||
actix-rt = "1.0.0"
|
||||
actix-http = "1.0.0"
|
||||
actix-http = "1.0.1"
|
||||
|
||||
bytes = "0.5.3"
|
||||
futures = "0.3.1"
|
||||
|
@ -1,5 +1,9 @@
|
||||
# Changes
|
||||
|
||||
## [0.3.0] - 2019-12-25
|
||||
|
||||
* Migrate to actix-http 1.0
|
||||
|
||||
## [0.2.1] - 2019-07-20
|
||||
|
||||
* Remove unneeded actix-utils dependency
|
||||
|
@ -66,7 +66,7 @@ where
|
||||
service
|
||||
})
|
||||
}
|
||||
.boxed_local()
|
||||
.boxed_local()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,6 +154,6 @@ where
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
.boxed_local()
|
||||
.boxed_local()
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ failure = ["fail-ure"]
|
||||
secure-cookies = ["ring"]
|
||||
|
||||
[dependencies]
|
||||
actix-service = "1.0.0"
|
||||
actix-service = "1.0.1"
|
||||
actix-codec = "0.2.0"
|
||||
actix-connect = "1.0.1"
|
||||
actix-utils = "1.0.3"
|
||||
|
@ -7,7 +7,8 @@ use futures::StreamExt;
|
||||
use http::header::HeaderValue;
|
||||
use log::info;
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
#[actix_rt::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
env::set_var("RUST_LOG", "echo=info");
|
||||
env_logger::init();
|
||||
|
||||
@ -37,4 +38,5 @@ fn main() -> io::Result<()> {
|
||||
.tcp()
|
||||
})?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
@ -19,7 +19,8 @@ async fn handle_request(mut req: Request) -> Result<Response, Error> {
|
||||
.body(body))
|
||||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
#[actix_rt::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
env::set_var("RUST_LOG", "echo=info");
|
||||
env_logger::init();
|
||||
|
||||
@ -28,4 +29,5 @@ fn main() -> io::Result<()> {
|
||||
HttpService::build().finish(handle_request).tcp()
|
||||
})?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
@ -6,7 +6,8 @@ use futures::future;
|
||||
use http::header::HeaderValue;
|
||||
use log::info;
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
#[actix_rt::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
env::set_var("RUST_LOG", "hello_world=info");
|
||||
env_logger::init();
|
||||
|
||||
@ -24,4 +25,5 @@ fn main() -> io::Result<()> {
|
||||
.tcp()
|
||||
})?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
# Changes
|
||||
|
||||
## [0.2.1] - 2020-01-10
|
||||
|
||||
* Fix panic with already borrowed: BorrowMutError #1263
|
||||
|
||||
## [0.2.0] - 2019-12-20
|
||||
|
||||
* Use actix-web 2.0
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-identity"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "Identity service for actix web framework."
|
||||
readme = "README.md"
|
||||
@ -10,15 +10,14 @@ repository = "https://github.com/actix/actix-web.git"
|
||||
documentation = "https://docs.rs/actix-identity/"
|
||||
license = "MIT/Apache-2.0"
|
||||
edition = "2018"
|
||||
workspace = ".."
|
||||
|
||||
[lib]
|
||||
name = "actix_identity"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
actix-web = { version = "2.0.0-rc", default-features = false, features = ["secure-cookies"] }
|
||||
actix-service = "1.0.0"
|
||||
actix-web = { version = "2.0.0", default-features = false, features = ["secure-cookies"] }
|
||||
actix-service = "1.0.2"
|
||||
futures = "0.3.1"
|
||||
serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
|
@ -251,6 +251,15 @@ pub struct IdentityServiceMiddleware<S, T> {
|
||||
service: Rc<RefCell<S>>,
|
||||
}
|
||||
|
||||
impl<S, T> Clone for IdentityServiceMiddleware<S, T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
backend: self.backend.clone(),
|
||||
service: self.service.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, T, B> Service for IdentityServiceMiddleware<S, T>
|
||||
where
|
||||
B: 'static,
|
||||
@ -279,7 +288,9 @@ where
|
||||
req.extensions_mut()
|
||||
.insert(IdentityItem { id, changed: false });
|
||||
|
||||
let mut res = srv.borrow_mut().call(req).await?;
|
||||
// https://github.com/actix/actix-web/issues/1263
|
||||
let fut = { srv.borrow_mut().call(req) };
|
||||
let mut res = fut.await?;
|
||||
let id = res.request().extensions_mut().remove::<IdentityItem>();
|
||||
|
||||
if let Some(id) = id {
|
||||
@ -294,7 +305,7 @@ where
|
||||
Err(err) => Ok(req.error_response(err)),
|
||||
}
|
||||
}
|
||||
.boxed_local()
|
||||
.boxed_local()
|
||||
}
|
||||
}
|
||||
|
||||
@ -606,9 +617,10 @@ mod tests {
|
||||
use std::borrow::Borrow;
|
||||
|
||||
use super::*;
|
||||
use actix_service::into_service;
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::test::{self, TestRequest};
|
||||
use actix_web::{web, App, Error, HttpResponse};
|
||||
use actix_web::{error, web, App, Error, HttpResponse};
|
||||
|
||||
const COOKIE_KEY_MASTER: [u8; 32] = [0; 32];
|
||||
const COOKIE_NAME: &'static str = "actix_auth";
|
||||
@ -1045,6 +1057,7 @@ mod tests {
|
||||
assert_logged_in(resp, Some(COOKIE_LOGIN)).await;
|
||||
}
|
||||
|
||||
// https://github.com/actix/actix-web/issues/1263
|
||||
#[actix_rt::test]
|
||||
async fn test_identity_cookie_updated_on_visit_deadline() {
|
||||
let mut srv = create_identity_server(|c| {
|
||||
@ -1069,4 +1082,47 @@ mod tests {
|
||||
);
|
||||
assert_logged_in(resp, Some(COOKIE_LOGIN)).await;
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_borrowed_mut_error() {
|
||||
use futures::future::{lazy, ok, Ready};
|
||||
|
||||
struct Ident;
|
||||
impl IdentityPolicy for Ident {
|
||||
type Future = Ready<Result<Option<String>, Error>>;
|
||||
type ResponseFuture = Ready<Result<(), Error>>;
|
||||
|
||||
fn from_request(&self, _: &mut ServiceRequest) -> Self::Future {
|
||||
ok(Some("test".to_string()))
|
||||
}
|
||||
|
||||
fn to_response<B>(
|
||||
&self,
|
||||
_: Option<String>,
|
||||
_: bool,
|
||||
_: &mut ServiceResponse<B>,
|
||||
) -> Self::ResponseFuture {
|
||||
ok(())
|
||||
}
|
||||
}
|
||||
|
||||
let mut srv = IdentityServiceMiddleware {
|
||||
backend: Rc::new(Ident),
|
||||
service: Rc::new(RefCell::new(into_service(|_: ServiceRequest| {
|
||||
async move {
|
||||
actix_rt::time::delay_for(std::time::Duration::from_secs(100)).await;
|
||||
Err::<ServiceResponse, _>(error::ErrorBadRequest("error"))
|
||||
}
|
||||
}))),
|
||||
};
|
||||
|
||||
let mut srv2 = srv.clone();
|
||||
let req = TestRequest::default().to_srv_request();
|
||||
actix_rt::spawn(async move {
|
||||
let _ = srv2.call(req).await;
|
||||
});
|
||||
actix_rt::time::delay_for(std::time::Duration::from_millis(50)).await;
|
||||
|
||||
let _ = lazy(|cx| srv.poll_ready(cx)).await;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
actix-web = { version = "2.0.0-rc", default-features = false }
|
||||
actix-service = "1.0.0"
|
||||
actix-service = "1.0.1"
|
||||
actix-utils = "1.0.3"
|
||||
bytes = "0.5.3"
|
||||
derive_more = "0.99.2"
|
||||
|
@ -23,7 +23,7 @@ cookie-session = ["actix-web/secure-cookies"]
|
||||
|
||||
[dependencies]
|
||||
actix-web = "2.0.0-rc"
|
||||
actix-service = "1.0.0"
|
||||
actix-service = "1.0.1"
|
||||
bytes = "0.5.3"
|
||||
derive_more = "0.99.2"
|
||||
futures = "0.3.1"
|
||||
|
@ -354,7 +354,7 @@ where
|
||||
}
|
||||
})
|
||||
}
|
||||
.boxed_local()
|
||||
.boxed_local()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
||||
//! )
|
||||
//! .service(web::resource("/").to(|| HttpResponse::Ok())))
|
||||
//! .bind("127.0.0.1:59880")?
|
||||
//! .start()
|
||||
//! .run()
|
||||
//! .await
|
||||
//! }
|
||||
//! ```
|
||||
|
@ -35,7 +35,7 @@ compress = ["actix-http/compress"]
|
||||
|
||||
[dependencies]
|
||||
actix-codec = "0.2.0"
|
||||
actix-service = "1.0.0"
|
||||
actix-service = "1.0.1"
|
||||
actix-http = "1.0.0"
|
||||
actix-rt = "1.0.0"
|
||||
|
||||
|
@ -14,7 +14,7 @@ use rand::Rng;
|
||||
|
||||
use actix_http::HttpService;
|
||||
use actix_http_test::test_server;
|
||||
use actix_service::{map_config, pipeline_factory, IntoServiceFactory};
|
||||
use actix_service::{map_config, pipeline_factory};
|
||||
use actix_web::dev::{AppConfig, BodyEncoding};
|
||||
use actix_web::http::Cookie;
|
||||
use actix_web::middleware::Compress;
|
||||
@ -172,8 +172,7 @@ async fn test_connection_reuse() {
|
||||
.and_then(
|
||||
HttpService::new(map_config(
|
||||
App::new()
|
||||
.service(web::resource("/").route(web::to(|| HttpResponse::Ok())))
|
||||
.into_factory(),
|
||||
.service(web::resource("/").route(web::to(|| HttpResponse::Ok()))),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
.tcp(),
|
||||
@ -210,8 +209,7 @@ async fn test_connection_force_close() {
|
||||
.and_then(
|
||||
HttpService::new(map_config(
|
||||
App::new()
|
||||
.service(web::resource("/").route(web::to(|| HttpResponse::Ok())))
|
||||
.into_factory(),
|
||||
.service(web::resource("/").route(web::to(|| HttpResponse::Ok()))),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
.tcp(),
|
||||
@ -239,25 +237,23 @@ async fn test_connection_server_close() {
|
||||
let num = Arc::new(AtomicUsize::new(0));
|
||||
let num2 = num.clone();
|
||||
|
||||
let srv =
|
||||
test_server(move || {
|
||||
let num2 = num2.clone();
|
||||
pipeline_factory(move |io| {
|
||||
num2.fetch_add(1, Ordering::Relaxed);
|
||||
ok(io)
|
||||
})
|
||||
.and_then(
|
||||
HttpService::new(map_config(
|
||||
App::new()
|
||||
.service(web::resource("/").route(web::to(|| {
|
||||
HttpResponse::Ok().force_close().finish()
|
||||
})))
|
||||
.into_factory(),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
.tcp(),
|
||||
)
|
||||
});
|
||||
let srv = test_server(move || {
|
||||
let num2 = num2.clone();
|
||||
pipeline_factory(move |io| {
|
||||
num2.fetch_add(1, Ordering::Relaxed);
|
||||
ok(io)
|
||||
})
|
||||
.and_then(
|
||||
HttpService::new(map_config(
|
||||
App::new().service(
|
||||
web::resource("/")
|
||||
.route(web::to(|| HttpResponse::Ok().force_close().finish())),
|
||||
),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
.tcp(),
|
||||
)
|
||||
});
|
||||
|
||||
let client = awc::Client::default();
|
||||
|
||||
@ -288,12 +284,9 @@ async fn test_connection_wait_queue() {
|
||||
})
|
||||
.and_then(
|
||||
HttpService::new(map_config(
|
||||
App::new()
|
||||
.service(
|
||||
web::resource("/")
|
||||
.route(web::to(|| HttpResponse::Ok().body(STR))),
|
||||
)
|
||||
.into_factory(),
|
||||
App::new().service(
|
||||
web::resource("/").route(web::to(|| HttpResponse::Ok().body(STR))),
|
||||
),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
.tcp(),
|
||||
@ -330,25 +323,23 @@ async fn test_connection_wait_queue_force_close() {
|
||||
let num = Arc::new(AtomicUsize::new(0));
|
||||
let num2 = num.clone();
|
||||
|
||||
let srv =
|
||||
test_server(move || {
|
||||
let num2 = num2.clone();
|
||||
pipeline_factory(move |io| {
|
||||
num2.fetch_add(1, Ordering::Relaxed);
|
||||
ok(io)
|
||||
})
|
||||
.and_then(
|
||||
HttpService::new(map_config(
|
||||
App::new()
|
||||
.service(web::resource("/").route(web::to(|| {
|
||||
HttpResponse::Ok().force_close().body(STR)
|
||||
})))
|
||||
.into_factory(),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
.tcp(),
|
||||
)
|
||||
});
|
||||
let srv = test_server(move || {
|
||||
let num2 = num2.clone();
|
||||
pipeline_factory(move |io| {
|
||||
num2.fetch_add(1, Ordering::Relaxed);
|
||||
ok(io)
|
||||
})
|
||||
.and_then(
|
||||
HttpService::new(map_config(
|
||||
App::new().service(
|
||||
web::resource("/")
|
||||
.route(web::to(|| HttpResponse::Ok().force_close().body(STR))),
|
||||
),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
.tcp(),
|
||||
)
|
||||
});
|
||||
|
||||
let client = awc::Client::build()
|
||||
.connector(awc::Connector::new().limit(1).finish())
|
||||
|
@ -4,7 +4,7 @@ use std::sync::Arc;
|
||||
|
||||
use actix_http::HttpService;
|
||||
use actix_http_test::test_server;
|
||||
use actix_service::{map_config, pipeline_factory, IntoServiceFactory, ServiceFactory};
|
||||
use actix_service::{map_config, pipeline_factory, ServiceFactory};
|
||||
use actix_web::http::Version;
|
||||
use actix_web::{dev::AppConfig, web, App, HttpResponse};
|
||||
use futures::future::ok;
|
||||
@ -63,11 +63,9 @@ async fn _test_connection_reuse_h2() {
|
||||
.and_then(
|
||||
HttpService::build()
|
||||
.h2(map_config(
|
||||
App::new()
|
||||
.service(
|
||||
web::resource("/").route(web::to(|| HttpResponse::Ok())),
|
||||
)
|
||||
.into_factory(),
|
||||
App::new().service(
|
||||
web::resource("/").route(web::to(|| HttpResponse::Ok())),
|
||||
),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
.openssl(ssl_acceptor())
|
||||
|
@ -4,7 +4,7 @@ use std::sync::Arc;
|
||||
|
||||
use actix_http::HttpService;
|
||||
use actix_http_test::test_server;
|
||||
use actix_service::{map_config, pipeline_factory, IntoServiceFactory, ServiceFactory};
|
||||
use actix_service::{map_config, pipeline_factory, ServiceFactory};
|
||||
use actix_web::http::Version;
|
||||
use actix_web::{dev::AppConfig, web, App, HttpResponse};
|
||||
use futures::future::ok;
|
||||
@ -45,11 +45,9 @@ async fn test_connection_reuse_h2() {
|
||||
.and_then(
|
||||
HttpService::build()
|
||||
.h2(map_config(
|
||||
App::new()
|
||||
.service(
|
||||
web::resource("/").route(web::to(|| HttpResponse::Ok())),
|
||||
)
|
||||
.into_factory(),
|
||||
App::new().service(
|
||||
web::resource("/").route(web::to(|| HttpResponse::Ok())),
|
||||
),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
.openssl(ssl_acceptor())
|
||||
|
@ -42,6 +42,6 @@ async fn main() -> std::io::Result<()> {
|
||||
})
|
||||
.bind("127.0.0.1:8080")?
|
||||
.workers(1)
|
||||
.start()
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ async fn main() -> std::io::Result<()> {
|
||||
})
|
||||
.bind_uds("/Users/fafhrd91/uds-test")?
|
||||
.workers(1)
|
||||
.start()
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
||||
|
46
src/data.rs
46
src/data.rs
@ -136,10 +136,11 @@ impl<T: 'static> DataFactory for Data<T> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_service::Service;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use super::*;
|
||||
use crate::http::StatusCode;
|
||||
use crate::test::{init_service, TestRequest};
|
||||
use crate::test::{self, init_service, TestRequest};
|
||||
use crate::{web, App, HttpResponse};
|
||||
|
||||
#[actix_rt::test]
|
||||
@ -234,4 +235,47 @@ mod tests {
|
||||
let resp = srv.call(req).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_data_drop() {
|
||||
struct TestData(Arc<AtomicUsize>);
|
||||
|
||||
impl TestData {
|
||||
fn new(inner: Arc<AtomicUsize>) -> Self {
|
||||
let _ = inner.fetch_add(1, Ordering::SeqCst);
|
||||
Self(inner)
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for TestData {
|
||||
fn clone(&self) -> Self {
|
||||
let inner = self.0.clone();
|
||||
let _ = inner.fetch_add(1, Ordering::SeqCst);
|
||||
Self(inner)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TestData {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.0.fetch_sub(1, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
let num = Arc::new(AtomicUsize::new(0));
|
||||
let data = TestData::new(num.clone());
|
||||
assert_eq!(num.load(Ordering::SeqCst), 1);
|
||||
|
||||
let srv = test::start(move || {
|
||||
let data = data.clone();
|
||||
|
||||
App::new()
|
||||
.data(data)
|
||||
.service(web::resource("/").to(|_data: Data<TestData>| async { "ok" }))
|
||||
});
|
||||
|
||||
assert!(srv.get("/").send().await.unwrap().status().is_success());
|
||||
srv.stop().await;
|
||||
|
||||
assert_eq!(num.load(Ordering::SeqCst), 0);
|
||||
}
|
||||
}
|
||||
|
17
src/lib.rs
17
src/lib.rs
@ -20,7 +20,7 @@
|
||||
//! web::resource("/{name}/{id}/index.html").to(index))
|
||||
//! )
|
||||
//! .bind("127.0.0.1:8080")?
|
||||
//! .start()
|
||||
//! .run()
|
||||
//! .await
|
||||
//! }
|
||||
//! ```
|
||||
@ -47,7 +47,7 @@
|
||||
//! configure servers.
|
||||
//!
|
||||
//! * [web](web/index.html): This module
|
||||
//! provide essentials helper functions and types for application registration.
|
||||
//! provides essential helper functions and types for application registration.
|
||||
//!
|
||||
//! * [HttpRequest](struct.HttpRequest.html) and
|
||||
//! [HttpResponse](struct.HttpResponse.html): These structs
|
||||
@ -151,12 +151,13 @@ pub mod dev {
|
||||
pub use actix_server::Server;
|
||||
pub use actix_service::{Service, Transform};
|
||||
|
||||
pub(crate) fn insert_slash(path: &str) -> String {
|
||||
let mut path = path.to_owned();
|
||||
if !path.is_empty() && !path.starts_with('/') {
|
||||
path.insert(0, '/');
|
||||
};
|
||||
path
|
||||
pub(crate) fn insert_slash(mut patterns: Vec<String>) -> Vec<String> {
|
||||
for path in &mut patterns {
|
||||
if !path.is_empty() && !path.starts_with('/') {
|
||||
path.insert(0, '/');
|
||||
};
|
||||
}
|
||||
patterns
|
||||
}
|
||||
|
||||
use crate::http::header::ContentEncoding;
|
||||
|
@ -150,7 +150,7 @@ where
|
||||
}
|
||||
Ok(res)
|
||||
}
|
||||
.boxed_local()
|
||||
.boxed_local()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ where
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
.boxed_local()
|
||||
.boxed_local()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ use std::rc::Rc;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
use actix_http::{Error, Extensions, Response};
|
||||
use actix_router::IntoPattern;
|
||||
use actix_service::boxed::{self, BoxService, BoxServiceFactory};
|
||||
use actix_service::{
|
||||
apply, apply_fn_factory, IntoServiceFactory, Service, ServiceFactory, Transform,
|
||||
@ -48,7 +49,7 @@ type HttpNewService = BoxServiceFactory<(), ServiceRequest, ServiceResponse, Err
|
||||
/// Default behavior could be overriden with `default_resource()` method.
|
||||
pub struct Resource<T = ResourceEndpoint> {
|
||||
endpoint: T,
|
||||
rdef: String,
|
||||
rdef: Vec<String>,
|
||||
name: Option<String>,
|
||||
routes: Vec<Route>,
|
||||
data: Option<Extensions>,
|
||||
@ -58,12 +59,12 @@ pub struct Resource<T = ResourceEndpoint> {
|
||||
}
|
||||
|
||||
impl Resource {
|
||||
pub fn new(path: &str) -> Resource {
|
||||
pub fn new<T: IntoPattern>(path: T) -> Resource {
|
||||
let fref = Rc::new(RefCell::new(None));
|
||||
|
||||
Resource {
|
||||
routes: Vec::new(),
|
||||
rdef: path.to_string(),
|
||||
rdef: path.patterns(),
|
||||
name: None,
|
||||
endpoint: ResourceEndpoint::new(fref.clone()),
|
||||
factory_ref: fref,
|
||||
@ -381,9 +382,9 @@ where
|
||||
Some(std::mem::replace(&mut self.guards, Vec::new()))
|
||||
};
|
||||
let mut rdef = if config.is_root() || !self.rdef.is_empty() {
|
||||
ResourceDef::new(&insert_slash(&self.rdef))
|
||||
ResourceDef::new(insert_slash(self.rdef.clone()))
|
||||
} else {
|
||||
ResourceDef::new(&self.rdef)
|
||||
ResourceDef::new(self.rdef.clone())
|
||||
};
|
||||
if let Some(ref name) = self.name {
|
||||
*rdef.name_mut() = name.clone();
|
||||
@ -660,6 +661,23 @@ mod tests {
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_pattern() {
|
||||
let mut srv = init_service(
|
||||
App::new().service(
|
||||
web::resource(["/test", "/test2"])
|
||||
.to(|| async { Ok::<_, Error>(HttpResponse::Ok()) }),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
let req = TestRequest::with_uri("/test").to_request();
|
||||
let resp = call_service(&mut srv, req).await;
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
let req = TestRequest::with_uri("/test2").to_request();
|
||||
let resp = call_service(&mut srv, req).await;
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_default_resource() {
|
||||
let mut srv = init_service(
|
||||
|
@ -2,13 +2,9 @@ use std::marker::PhantomData;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::{fmt, io, net};
|
||||
|
||||
use actix_http::{
|
||||
body::MessageBody, Error, HttpService, KeepAlive, Request, Response,
|
||||
};
|
||||
use actix_http::{body::MessageBody, Error, HttpService, KeepAlive, Request, Response};
|
||||
use actix_server::{Server, ServerBuilder};
|
||||
use actix_service::{
|
||||
map_config, IntoServiceFactory, Service, ServiceFactory,
|
||||
};
|
||||
use actix_service::{map_config, IntoServiceFactory, Service, ServiceFactory};
|
||||
|
||||
use net2::TcpBuilder;
|
||||
|
||||
@ -42,21 +38,17 @@ struct Config {
|
||||
///
|
||||
/// Create new http server with application factory.
|
||||
///
|
||||
/// ```rust
|
||||
/// use std::io;
|
||||
/// ```rust,no_run
|
||||
/// use actix_web::{web, App, HttpResponse, HttpServer};
|
||||
///
|
||||
/// fn main() -> io::Result<()> {
|
||||
/// let sys = actix_rt::System::new("example"); // <- create Actix runtime
|
||||
///
|
||||
/// #[actix_rt::main]
|
||||
/// async fn main() -> std::io::Result<()> {
|
||||
/// HttpServer::new(
|
||||
/// || App::new()
|
||||
/// .service(web::resource("/").to(|| HttpResponse::Ok())))
|
||||
/// .bind("127.0.0.1:59090")?
|
||||
/// .start();
|
||||
///
|
||||
/// # actix_rt::System::current().stop();
|
||||
/// sys.run()
|
||||
/// .run()
|
||||
/// .await
|
||||
/// }
|
||||
/// ```
|
||||
pub struct HttpServer<F, I, S, B>
|
||||
@ -266,7 +258,7 @@ where
|
||||
.keep_alive(c.keep_alive)
|
||||
.client_timeout(c.client_timeout)
|
||||
.local_addr(addr)
|
||||
.finish(map_config(factory().into_factory(), move |_| cfg.clone()))
|
||||
.finish(map_config(factory(), move |_| cfg.clone()))
|
||||
.tcp()
|
||||
},
|
||||
)?;
|
||||
@ -313,7 +305,7 @@ where
|
||||
.keep_alive(c.keep_alive)
|
||||
.client_timeout(c.client_timeout)
|
||||
.client_disconnect(c.client_shutdown)
|
||||
.finish(map_config(factory().into_factory(), move |_| cfg.clone()))
|
||||
.finish(map_config(factory(), move |_| cfg.clone()))
|
||||
.openssl(acceptor.clone())
|
||||
},
|
||||
)?;
|
||||
@ -360,7 +352,7 @@ where
|
||||
.keep_alive(c.keep_alive)
|
||||
.client_timeout(c.client_timeout)
|
||||
.client_disconnect(c.client_shutdown)
|
||||
.finish(map_config(factory().into_factory(), move |_| cfg.clone()))
|
||||
.finish(map_config(factory(), move |_| cfg.clone()))
|
||||
.rustls(config.clone())
|
||||
},
|
||||
)?;
|
||||
@ -483,9 +475,7 @@ where
|
||||
HttpService::build()
|
||||
.keep_alive(c.keep_alive)
|
||||
.client_timeout(c.client_timeout)
|
||||
.finish(map_config(factory().into_factory(), move |_| {
|
||||
config.clone()
|
||||
})),
|
||||
.finish(map_config(factory(), move |_| config.clone())),
|
||||
)
|
||||
})?;
|
||||
Ok(self)
|
||||
@ -527,9 +517,7 @@ where
|
||||
HttpService::build()
|
||||
.keep_alive(c.keep_alive)
|
||||
.client_timeout(c.client_timeout)
|
||||
.finish(map_config(factory().into_factory(), move |_| {
|
||||
config.clone()
|
||||
})),
|
||||
.finish(map_config(factory(), move |_| config.clone())),
|
||||
)
|
||||
},
|
||||
)?;
|
||||
@ -565,11 +553,11 @@ where
|
||||
/// async fn main() -> io::Result<()> {
|
||||
/// HttpServer::new(|| App::new().service(web::resource("/").to(|| HttpResponse::Ok())))
|
||||
/// .bind("127.0.0.1:0")?
|
||||
/// .start()
|
||||
/// .run()
|
||||
/// .await
|
||||
/// }
|
||||
/// ```
|
||||
pub fn start(self) -> Server {
|
||||
pub fn run(self) -> Server {
|
||||
self.builder.start()
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ use actix_http::{
|
||||
Error, Extensions, HttpMessage, Payload, PayloadStream, RequestHead, Response,
|
||||
ResponseHead,
|
||||
};
|
||||
use actix_router::{Path, Resource, ResourceDef, Url};
|
||||
use actix_router::{IntoPattern, Path, Resource, ResourceDef, Url};
|
||||
use actix_service::{IntoServiceFactory, ServiceFactory};
|
||||
|
||||
use crate::config::{AppConfig, AppService};
|
||||
@ -422,16 +422,16 @@ impl<B: MessageBody> fmt::Debug for ServiceResponse<B> {
|
||||
}
|
||||
|
||||
pub struct WebService {
|
||||
rdef: String,
|
||||
rdef: Vec<String>,
|
||||
name: Option<String>,
|
||||
guards: Vec<Box<dyn Guard>>,
|
||||
}
|
||||
|
||||
impl WebService {
|
||||
/// Create new `WebService` instance.
|
||||
pub fn new(path: &str) -> Self {
|
||||
pub fn new<T: IntoPattern>(path: T) -> Self {
|
||||
WebService {
|
||||
rdef: path.to_string(),
|
||||
rdef: path.patterns(),
|
||||
name: None,
|
||||
guards: Vec::new(),
|
||||
}
|
||||
@ -491,7 +491,7 @@ impl WebService {
|
||||
|
||||
struct WebServiceImpl<T> {
|
||||
srv: T,
|
||||
rdef: String,
|
||||
rdef: Vec<String>,
|
||||
name: Option<String>,
|
||||
guards: Vec<Box<dyn Guard>>,
|
||||
}
|
||||
@ -514,9 +514,9 @@ where
|
||||
};
|
||||
|
||||
let mut rdef = if config.is_root() || !self.rdef.is_empty() {
|
||||
ResourceDef::new(&insert_slash(&self.rdef))
|
||||
ResourceDef::new(insert_slash(self.rdef))
|
||||
} else {
|
||||
ResourceDef::new(&self.rdef)
|
||||
ResourceDef::new(self.rdef)
|
||||
};
|
||||
if let Some(ref name) = self.name {
|
||||
*rdef.name_mut() = name.clone();
|
||||
|
49
src/test.rs
49
src/test.rs
@ -11,8 +11,7 @@ use actix_http::http::{Error as HttpError, Method, StatusCode, Uri, Version};
|
||||
use actix_http::test::TestRequest as HttpTestRequest;
|
||||
use actix_http::{cookie::Cookie, ws, Extensions, HttpService, Request};
|
||||
use actix_router::{Path, ResourceDef, Url};
|
||||
use actix_rt::System;
|
||||
use actix_server::Server;
|
||||
use actix_rt::{time::delay_for, System};
|
||||
use actix_service::{
|
||||
map_config, IntoService, IntoServiceFactory, Service, ServiceFactory,
|
||||
};
|
||||
@ -30,7 +29,7 @@ pub use actix_http::test::TestBuffer;
|
||||
|
||||
use crate::config::AppConfig;
|
||||
use crate::data::Data;
|
||||
use crate::dev::{Body, MessageBody, Payload};
|
||||
use crate::dev::{Body, MessageBody, Payload, Server};
|
||||
use crate::request::HttpRequestPool;
|
||||
use crate::rmap::ResourceMap;
|
||||
use crate::service::{ServiceRequest, ServiceResponse};
|
||||
@ -627,14 +626,14 @@ where
|
||||
let ctimeout = cfg.client_timeout;
|
||||
let builder = Server::build().workers(1).disable_signals();
|
||||
|
||||
match cfg.stream {
|
||||
let srv = match cfg.stream {
|
||||
StreamType::Tcp => match cfg.tp {
|
||||
HttpVer::Http1 => builder.listen("test", tcp, move || {
|
||||
let cfg =
|
||||
AppConfig::new(false, local_addr, format!("{}", local_addr));
|
||||
HttpService::build()
|
||||
.client_timeout(ctimeout)
|
||||
.h1(map_config(factory().into_factory(), move |_| cfg.clone()))
|
||||
.h1(map_config(factory(), move |_| cfg.clone()))
|
||||
.tcp()
|
||||
}),
|
||||
HttpVer::Http2 => builder.listen("test", tcp, move || {
|
||||
@ -642,7 +641,7 @@ where
|
||||
AppConfig::new(false, local_addr, format!("{}", local_addr));
|
||||
HttpService::build()
|
||||
.client_timeout(ctimeout)
|
||||
.h2(map_config(factory().into_factory(), move |_| cfg.clone()))
|
||||
.h2(map_config(factory(), move |_| cfg.clone()))
|
||||
.tcp()
|
||||
}),
|
||||
HttpVer::Both => builder.listen("test", tcp, move || {
|
||||
@ -650,9 +649,7 @@ where
|
||||
AppConfig::new(false, local_addr, format!("{}", local_addr));
|
||||
HttpService::build()
|
||||
.client_timeout(ctimeout)
|
||||
.finish(map_config(factory().into_factory(), move |_| {
|
||||
cfg.clone()
|
||||
}))
|
||||
.finish(map_config(factory(), move |_| cfg.clone()))
|
||||
.tcp()
|
||||
}),
|
||||
},
|
||||
@ -663,7 +660,7 @@ where
|
||||
AppConfig::new(true, local_addr, format!("{}", local_addr));
|
||||
HttpService::build()
|
||||
.client_timeout(ctimeout)
|
||||
.h1(map_config(factory().into_factory(), move |_| cfg.clone()))
|
||||
.h1(map_config(factory(), move |_| cfg.clone()))
|
||||
.openssl(acceptor.clone())
|
||||
}),
|
||||
HttpVer::Http2 => builder.listen("test", tcp, move || {
|
||||
@ -671,7 +668,7 @@ where
|
||||
AppConfig::new(true, local_addr, format!("{}", local_addr));
|
||||
HttpService::build()
|
||||
.client_timeout(ctimeout)
|
||||
.h2(map_config(factory().into_factory(), move |_| cfg.clone()))
|
||||
.h2(map_config(factory(), move |_| cfg.clone()))
|
||||
.openssl(acceptor.clone())
|
||||
}),
|
||||
HttpVer::Both => builder.listen("test", tcp, move || {
|
||||
@ -679,9 +676,7 @@ where
|
||||
AppConfig::new(true, local_addr, format!("{}", local_addr));
|
||||
HttpService::build()
|
||||
.client_timeout(ctimeout)
|
||||
.finish(map_config(factory().into_factory(), move |_| {
|
||||
cfg.clone()
|
||||
}))
|
||||
.finish(map_config(factory(), move |_| cfg.clone()))
|
||||
.openssl(acceptor.clone())
|
||||
}),
|
||||
},
|
||||
@ -692,7 +687,7 @@ where
|
||||
AppConfig::new(true, local_addr, format!("{}", local_addr));
|
||||
HttpService::build()
|
||||
.client_timeout(ctimeout)
|
||||
.h1(map_config(factory().into_factory(), move |_| cfg.clone()))
|
||||
.h1(map_config(factory(), move |_| cfg.clone()))
|
||||
.rustls(config.clone())
|
||||
}),
|
||||
HttpVer::Http2 => builder.listen("test", tcp, move || {
|
||||
@ -700,7 +695,7 @@ where
|
||||
AppConfig::new(true, local_addr, format!("{}", local_addr));
|
||||
HttpService::build()
|
||||
.client_timeout(ctimeout)
|
||||
.h2(map_config(factory().into_factory(), move |_| cfg.clone()))
|
||||
.h2(map_config(factory(), move |_| cfg.clone()))
|
||||
.rustls(config.clone())
|
||||
}),
|
||||
HttpVer::Both => builder.listen("test", tcp, move || {
|
||||
@ -708,9 +703,7 @@ where
|
||||
AppConfig::new(true, local_addr, format!("{}", local_addr));
|
||||
HttpService::build()
|
||||
.client_timeout(ctimeout)
|
||||
.finish(map_config(factory().into_factory(), move |_| {
|
||||
cfg.clone()
|
||||
}))
|
||||
.finish(map_config(factory(), move |_| cfg.clone()))
|
||||
.rustls(config.clone())
|
||||
}),
|
||||
},
|
||||
@ -718,11 +711,11 @@ where
|
||||
.unwrap()
|
||||
.start();
|
||||
|
||||
tx.send((System::current(), local_addr)).unwrap();
|
||||
tx.send((System::current(), srv, local_addr)).unwrap();
|
||||
sys.run()
|
||||
});
|
||||
|
||||
let (system, addr) = rx.recv().unwrap();
|
||||
let (system, server, addr) = rx.recv().unwrap();
|
||||
|
||||
let client = {
|
||||
let connector = {
|
||||
@ -737,7 +730,7 @@ where
|
||||
.map_err(|e| log::error!("Can not set alpn protocol: {:?}", e));
|
||||
Connector::new()
|
||||
.conn_lifetime(time::Duration::from_secs(0))
|
||||
.timeout(time::Duration::from_millis(3000))
|
||||
.timeout(time::Duration::from_millis(30000))
|
||||
.ssl(builder.build())
|
||||
.finish()
|
||||
}
|
||||
@ -745,7 +738,7 @@ where
|
||||
{
|
||||
Connector::new()
|
||||
.conn_lifetime(time::Duration::from_secs(0))
|
||||
.timeout(time::Duration::from_millis(3000))
|
||||
.timeout(time::Duration::from_millis(30000))
|
||||
.finish()
|
||||
}
|
||||
};
|
||||
@ -758,6 +751,7 @@ where
|
||||
addr,
|
||||
client,
|
||||
system,
|
||||
server,
|
||||
}
|
||||
}
|
||||
|
||||
@ -854,6 +848,7 @@ pub struct TestServer {
|
||||
client: awc::Client,
|
||||
system: actix_rt::System,
|
||||
ssl: bool,
|
||||
server: Server,
|
||||
}
|
||||
|
||||
impl TestServer {
|
||||
@ -942,15 +937,17 @@ impl TestServer {
|
||||
self.ws_at("/").await
|
||||
}
|
||||
|
||||
/// Stop http server
|
||||
fn stop(&mut self) {
|
||||
/// Gracefully stop http server
|
||||
pub async fn stop(self) {
|
||||
self.server.stop(true).await;
|
||||
self.system.stop();
|
||||
delay_for(time::Duration::from_millis(100)).await;
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TestServer {
|
||||
fn drop(&mut self) {
|
||||
self.stop()
|
||||
self.system.stop()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -365,7 +365,7 @@ where
|
||||
.map_err(|_| UrlencodedError::Parse)
|
||||
}
|
||||
}
|
||||
.boxed_local(),
|
||||
.boxed_local(),
|
||||
);
|
||||
self.poll(cx)
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ where
|
||||
}
|
||||
Ok(serde_json::from_slice::<U>(&body)?)
|
||||
}
|
||||
.boxed_local(),
|
||||
.boxed_local(),
|
||||
);
|
||||
|
||||
self.poll(cx)
|
||||
|
@ -229,7 +229,7 @@ impl FromRequest for String {
|
||||
.ok_or_else(|| ErrorBadRequest("Can not decode body"))?)
|
||||
}
|
||||
}
|
||||
.boxed_local(),
|
||||
.boxed_local(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -391,7 +391,7 @@ impl Future for HttpMessageBody {
|
||||
}
|
||||
Ok(body.freeze())
|
||||
}
|
||||
.boxed_local(),
|
||||
.boxed_local(),
|
||||
);
|
||||
self.poll(cx)
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
//! Essentials helper functions and types for application registration.
|
||||
use actix_http::http::Method;
|
||||
use actix_router::IntoPattern;
|
||||
use futures::Future;
|
||||
|
||||
pub use actix_http::Response as HttpResponse;
|
||||
@ -50,7 +51,7 @@ pub use crate::types::*;
|
||||
/// .route(web::head().to(|| HttpResponse::MethodNotAllowed()))
|
||||
/// );
|
||||
/// ```
|
||||
pub fn resource(path: &str) -> Resource {
|
||||
pub fn resource<T: IntoPattern>(path: T) -> Resource {
|
||||
Resource::new(path)
|
||||
}
|
||||
|
||||
@ -249,7 +250,7 @@ where
|
||||
/// .finish(my_service)
|
||||
/// );
|
||||
/// ```
|
||||
pub fn service(path: &str) -> WebService {
|
||||
pub fn service<T: IntoPattern>(path: T) -> WebService {
|
||||
WebService::new(path)
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ default = []
|
||||
openssl = ["open-ssl", "awc/openssl"]
|
||||
|
||||
[dependencies]
|
||||
actix-service = "1.0.0"
|
||||
actix-service = "1.0.1"
|
||||
actix-codec = "0.2.0"
|
||||
actix-connect = "1.0.0"
|
||||
actix-utils = "1.0.3"
|
||||
|
@ -77,7 +77,7 @@ pub fn test_server<F: ServiceFactory<TcpStream>>(factory: F) -> TestServer {
|
||||
.map_err(|e| log::error!("Can not set alpn protocol: {:?}", e));
|
||||
Connector::new()
|
||||
.conn_lifetime(time::Duration::from_secs(0))
|
||||
.timeout(time::Duration::from_millis(3000))
|
||||
.timeout(time::Duration::from_millis(30000))
|
||||
.ssl(builder.build())
|
||||
.finish()
|
||||
}
|
||||
@ -85,7 +85,7 @@ pub fn test_server<F: ServiceFactory<TcpStream>>(factory: F) -> TestServer {
|
||||
{
|
||||
Connector::new()
|
||||
.conn_lifetime(time::Duration::from_secs(0))
|
||||
.timeout(time::Duration::from_millis(3000))
|
||||
.timeout(time::Duration::from_millis(30000))
|
||||
.finish()
|
||||
}
|
||||
};
|
||||
|
@ -42,7 +42,7 @@ async fn test_start() {
|
||||
.disable_signals()
|
||||
.bind(format!("{}", addr))
|
||||
.unwrap()
|
||||
.start();
|
||||
.run();
|
||||
|
||||
let _ = tx.send((srv, actix_rt::System::current()));
|
||||
let _ = sys.run();
|
||||
@ -111,7 +111,7 @@ async fn test_start_ssl() {
|
||||
.disable_signals()
|
||||
.bind_openssl(format!("{}", addr), builder)
|
||||
.unwrap()
|
||||
.start();
|
||||
.run();
|
||||
|
||||
let _ = tx.send((srv, actix_rt::System::current()));
|
||||
let _ = sys.run();
|
||||
|
Reference in New Issue
Block a user