mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-04 09:56:22 +02:00
Compare commits
21 Commits
files-v0.6
...
files-v0.2
Author | SHA1 | Date | |
---|---|---|---|
d92d53a4f5 | |||
55d79cc1b2 | |||
a8117183bb | |||
60dcfd1aff | |||
7870165da2 | |||
6560a2285f | |||
12eccf40e1 | |||
7a9c0f632d | |||
7baa35a897 | |||
ea0d748a5e | |||
bc4f98321a | |||
2ddbe2b15c | |||
87378a7410 | |||
ad0d809af6 | |||
7b00c16d44 | |||
155a6db4cd | |||
228e886986 | |||
4aa4b5f928 | |||
54ff97470e | |||
f02ad2913f | |||
96b0dfeac3 |
@ -1,41 +0,0 @@
|
|||||||
environment:
|
|
||||||
global:
|
|
||||||
PROJECT_NAME: actix-web
|
|
||||||
matrix:
|
|
||||||
# Stable channel
|
|
||||||
- TARGET: i686-pc-windows-msvc
|
|
||||||
CHANNEL: stable
|
|
||||||
- TARGET: x86_64-pc-windows-gnu
|
|
||||||
CHANNEL: stable
|
|
||||||
- TARGET: x86_64-pc-windows-msvc
|
|
||||||
CHANNEL: stable
|
|
||||||
# Nightly channel
|
|
||||||
- TARGET: i686-pc-windows-msvc
|
|
||||||
CHANNEL: nightly
|
|
||||||
- TARGET: x86_64-pc-windows-gnu
|
|
||||||
CHANNEL: nightly
|
|
||||||
- TARGET: x86_64-pc-windows-msvc
|
|
||||||
CHANNEL: nightly
|
|
||||||
|
|
||||||
# Install Rust and Cargo
|
|
||||||
# (Based on from https://github.com/rust-lang/libc/blob/master/appveyor.yml)
|
|
||||||
install:
|
|
||||||
- ps: >-
|
|
||||||
If ($Env:TARGET -eq 'x86_64-pc-windows-gnu') {
|
|
||||||
$Env:PATH += ';C:\msys64\mingw64\bin'
|
|
||||||
} ElseIf ($Env:TARGET -eq 'i686-pc-windows-gnu') {
|
|
||||||
$Env:PATH += ';C:\MinGW\bin'
|
|
||||||
}
|
|
||||||
- curl -sSf -o rustup-init.exe https://win.rustup.rs
|
|
||||||
- rustup-init.exe --default-host %TARGET% --default-toolchain %CHANNEL% -y
|
|
||||||
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
|
|
||||||
- rustc -Vv
|
|
||||||
- cargo -V
|
|
||||||
|
|
||||||
# 'cargo test' takes care of building for us, so disable Appveyor's build stage.
|
|
||||||
build: false
|
|
||||||
|
|
||||||
# Equivalent to Travis' `script` phase
|
|
||||||
test_script:
|
|
||||||
- cargo clean
|
|
||||||
- cargo test --no-default-features --features="flate2-rust"
|
|
37
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
37
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
---
|
||||||
|
name: bug report
|
||||||
|
about: create a bug report
|
||||||
|
---
|
||||||
|
|
||||||
|
Your issue may already be reported!
|
||||||
|
Please search on the [Actix Web issue tracker](https://github.com/actix/actix-web/issues) before creating one.
|
||||||
|
|
||||||
|
## Expected Behavior
|
||||||
|
<!--- If you're describing a bug, tell us what should happen -->
|
||||||
|
<!--- If you're suggesting a change/improvement, tell us how it should work -->
|
||||||
|
|
||||||
|
## Current Behavior
|
||||||
|
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
|
||||||
|
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
|
||||||
|
|
||||||
|
## Possible Solution
|
||||||
|
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
|
||||||
|
<!--- or ideas how to implement the addition or change -->
|
||||||
|
|
||||||
|
## Steps to Reproduce (for bugs)
|
||||||
|
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
|
||||||
|
<!--- reproduce this bug. Include code to reproduce, if relevant -->
|
||||||
|
1.
|
||||||
|
2.
|
||||||
|
3.
|
||||||
|
4.
|
||||||
|
|
||||||
|
## Context
|
||||||
|
<!--- How has this issue affected you? What are you trying to accomplish? -->
|
||||||
|
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
|
||||||
|
|
||||||
|
## Your Environment
|
||||||
|
<!--- Include as many relevant details about the environment you experienced the bug in -->
|
||||||
|
|
||||||
|
* Rust Version (I.e, output of `rustc -V`):
|
||||||
|
* Actix Web Version:
|
53
.github/workflows/linux.yml
vendored
Normal file
53
.github/workflows/linux.yml
vendored
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
name: CI (Linux)
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build_and_test:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
version:
|
||||||
|
- 1.39.0 # MSRV
|
||||||
|
- stable
|
||||||
|
- nightly
|
||||||
|
|
||||||
|
name: ${{ matrix.version }} - x86_64-unknown-linux-gnu
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@master
|
||||||
|
|
||||||
|
- name: Install ${{ matrix.version }}
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: ${{ matrix.version }}-x86_64-unknown-linux-gnu
|
||||||
|
profile: minimal
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: check build
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: check
|
||||||
|
args: --all --bins --examples --tests
|
||||||
|
|
||||||
|
- name: tests
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
timeout-minutes: 40
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
args: --all --all-features --no-fail-fast -- --nocapture
|
||||||
|
|
||||||
|
- name: tests (actix-http)
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
timeout-minutes: 40
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
args: --package=actix-http --no-default-features --features=rustls -- --nocapture
|
||||||
|
|
||||||
|
- name: tests (awc)
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
timeout-minutes: 40
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
args: --package=awc --no-default-features --features=rustls -- --nocapture
|
20
.github/workflows/macos.yml
vendored
20
.github/workflows/macos.yml
vendored
@ -24,26 +24,6 @@ jobs:
|
|||||||
profile: minimal
|
profile: minimal
|
||||||
override: true
|
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
|
- name: check build
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
|
37
.github/workflows/windows.yml
vendored
37
.github/workflows/windows.yml
vendored
@ -27,38 +27,14 @@ jobs:
|
|||||||
profile: minimal
|
profile: minimal
|
||||||
override: true
|
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
|
- name: Install OpenSSL
|
||||||
if: steps.cache-vcpkg.outputs.cache-hit != 'true'
|
|
||||||
run: |
|
run: |
|
||||||
vcpkg integrate install
|
vcpkg integrate install
|
||||||
vcpkg install openssl:x64-windows
|
vcpkg install openssl:x64-windows
|
||||||
|
Copy-Item C:\vcpkg\installed\x64-windows\bin\libcrypto-1_1-x64.dll C:\vcpkg\installed\x64-windows\bin\libcrypto.dll
|
||||||
|
Copy-Item C:\vcpkg\installed\x64-windows\bin\libssl-1_1-x64.dll C:\vcpkg\installed\x64-windows\bin\libssl.dll
|
||||||
|
Get-ChildItem C:\vcpkg\installed\x64-windows\bin
|
||||||
|
Get-ChildItem C:\vcpkg\installed\x64-windows\lib
|
||||||
- name: check build
|
- name: check build
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
@ -76,4 +52,7 @@ jobs:
|
|||||||
--skip=test_simple
|
--skip=test_simple
|
||||||
--skip=test_expect_continue
|
--skip=test_expect_continue
|
||||||
--skip=test_http10_keepalive
|
--skip=test_http10_keepalive
|
||||||
--skip=test_slow_request
|
--skip=test_slow_request
|
||||||
|
--skip=test_connection_force_close
|
||||||
|
--skip=test_connection_server_close
|
||||||
|
--skip=test_connection_wait_queue_force_close
|
||||||
|
61
.travis.yml
61
.travis.yml
@ -1,61 +0,0 @@
|
|||||||
language: rust
|
|
||||||
sudo: required
|
|
||||||
dist: trusty
|
|
||||||
|
|
||||||
cache:
|
|
||||||
# cargo: true
|
|
||||||
apt: true
|
|
||||||
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- rust: stable
|
|
||||||
- rust: beta
|
|
||||||
- rust: nightly-2019-11-20
|
|
||||||
allow_failures:
|
|
||||||
- rust: nightly-2019-11-20
|
|
||||||
|
|
||||||
env:
|
|
||||||
global:
|
|
||||||
# - RUSTFLAGS="-C link-dead-code"
|
|
||||||
- OPENSSL_VERSION=openssl-1.0.2
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- sudo add-apt-repository -y ppa:0k53d-karl-f830m/openssl
|
|
||||||
- sudo apt-get update -qq
|
|
||||||
- sudo apt-get install -y openssl libssl-dev libelf-dev libdw-dev cmake gcc binutils-dev libiberty-dev
|
|
||||||
|
|
||||||
before_cache: |
|
|
||||||
if [[ "$TRAVIS_RUST_VERSION" == "nightly-2019-11-20" ]]; then
|
|
||||||
RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install --version 0.6.11 cargo-tarpaulin
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Add clippy
|
|
||||||
before_script:
|
|
||||||
- export PATH=$PATH:~/.cargo/bin
|
|
||||||
|
|
||||||
script:
|
|
||||||
- cargo update
|
|
||||||
- cargo check --all --no-default-features
|
|
||||||
- |
|
|
||||||
if [[ "$TRAVIS_RUST_VERSION" == "stable" || "$TRAVIS_RUST_VERSION" == "beta" ]]; then
|
|
||||||
cargo test --all-features --all -- --nocapture
|
|
||||||
cd actix-http; cargo test --no-default-features --features="rustls" -- --nocapture; cd ..
|
|
||||||
cd awc; cargo test --no-default-features --features="rustls" -- --nocapture; cd ..
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Upload docs
|
|
||||||
after_success:
|
|
||||||
- |
|
|
||||||
if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_RUST_VERSION" == "stable" ]]; then
|
|
||||||
cargo doc --no-deps --all-features &&
|
|
||||||
echo "<meta http-equiv=refresh content=0;url=os_balloon/index.html>" > target/doc/index.html &&
|
|
||||||
git clone https://github.com/davisp/ghp-import.git &&
|
|
||||||
./ghp-import/ghp_import.py -n -p -f -m "Documentation upload" -r https://"$GH_TOKEN"@github.com/"$TRAVIS_REPO_SLUG.git" target/doc &&
|
|
||||||
echo "Uploaded documentation"
|
|
||||||
fi
|
|
||||||
- |
|
|
||||||
if [[ "$TRAVIS_RUST_VERSION" == "nightly-2019-11-20" ]]; then
|
|
||||||
taskset -c 0 cargo tarpaulin --out Xml --all --all-features
|
|
||||||
bash <(curl -s https://codecov.io/bash)
|
|
||||||
echo "Uploaded code coverage"
|
|
||||||
fi
|
|
@ -1,5 +1,13 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.2.2] - 2020-05-26
|
||||||
|
|
||||||
|
* Minimize `futures` dependency
|
||||||
|
* Support sending Content-Length when Content-Range is specified [#1496]
|
||||||
|
* Update `actix-web` to 2.0.0
|
||||||
|
|
||||||
|
[#1496]: https://github.com/actix/actix-web/issues/1496
|
||||||
|
|
||||||
## [0.2.1] - 2019-12-22
|
## [0.2.1] - 2019-12-22
|
||||||
|
|
||||||
* Use the same format for file URLs regardless of platforms
|
* Use the same format for file URLs regardless of platforms
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-files"
|
name = "actix-files"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Static files support for actix web."
|
description = "Static files support for actix web."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
@ -18,12 +18,13 @@ name = "actix_files"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = { version = "2.0.0-rc", default-features = false }
|
actix-web = { version = "2.0.0", default-features = false }
|
||||||
actix-http = "1.0.1"
|
actix-http = "1.0.1"
|
||||||
actix-service = "1.0.1"
|
actix-service = "1.0.1"
|
||||||
bitflags = "1"
|
bitflags = "1"
|
||||||
bytes = "0.5.3"
|
bytes = "0.5.3"
|
||||||
futures = "0.3.1"
|
futures-core = { version = "0.3.5", default-features = false }
|
||||||
|
futures-util = { version = "0.3.5", default-features = false }
|
||||||
derive_more = "0.99.2"
|
derive_more = "0.99.2"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
mime = "0.3"
|
mime = "0.3"
|
||||||
@ -33,4 +34,4 @@ v_htmlescape = "0.4"
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-rt = "1.0.0"
|
actix-rt = "1.0.0"
|
||||||
actix-web = { version = "2.0.0-rc", features=["openssl"] }
|
actix-web = { version = "2.0.0", features = ["openssl"] }
|
||||||
|
@ -5,6 +5,7 @@ use derive_more::Display;
|
|||||||
#[derive(Display, Debug, PartialEq)]
|
#[derive(Display, Debug, PartialEq)]
|
||||||
pub enum FilesError {
|
pub enum FilesError {
|
||||||
/// Path is not a directory
|
/// Path is not a directory
|
||||||
|
#[allow(dead_code)]
|
||||||
#[display(fmt = "Path is not a directory. Unable to serve static files")]
|
#[display(fmt = "Path is not a directory. Unable to serve static files")]
|
||||||
IsNotDirectory,
|
IsNotDirectory,
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ use actix_web::http::header::{self, DispositionType};
|
|||||||
use actix_web::http::Method;
|
use actix_web::http::Method;
|
||||||
use actix_web::{web, FromRequest, HttpRequest, HttpResponse};
|
use actix_web::{web, FromRequest, HttpRequest, HttpResponse};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::future::{ok, ready, Either, FutureExt, LocalBoxFuture, Ready};
|
use futures_core::Stream;
|
||||||
use futures::Stream;
|
use futures_util::future::{ok, ready, Either, FutureExt, LocalBoxFuture, Ready};
|
||||||
use mime;
|
use mime;
|
||||||
use mime_guess::from_ext;
|
use mime_guess::from_ext;
|
||||||
use percent_encoding::{utf8_percent_encode, CONTROLS};
|
use percent_encoding::{utf8_percent_encode, CONTROLS};
|
||||||
@ -521,7 +521,7 @@ impl Service for FilesService {
|
|||||||
Err(e) => return Either::Left(ok(req.error_response(e))),
|
Err(e) => return Either::Left(ok(req.error_response(e))),
|
||||||
};
|
};
|
||||||
|
|
||||||
// full filepath
|
// full file path
|
||||||
let path = match self.directory.join(&real_path.0).canonicalize() {
|
let path = match self.directory.join(&real_path.0).canonicalize() {
|
||||||
Ok(path) => path,
|
Ok(path) => path,
|
||||||
Err(e) => return self.handle_err(e, req),
|
Err(e) => return self.handle_err(e, req),
|
||||||
@ -952,135 +952,92 @@ mod tests {
|
|||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_named_file_content_range_headers() {
|
async fn test_named_file_content_range_headers() {
|
||||||
let mut srv = test::init_service(
|
let srv = test::start(|| {
|
||||||
App::new().service(Files::new("/test", ".").index_file("tests/test.binary")),
|
App::new().service(Files::new("/", "."))
|
||||||
)
|
});
|
||||||
.await;
|
|
||||||
|
|
||||||
// Valid range header
|
// Valid range header
|
||||||
let request = TestRequest::get()
|
let response = srv
|
||||||
.uri("/t%65st/tests/test.binary")
|
.get("/tests/test.binary")
|
||||||
.header(header::RANGE, "bytes=10-20")
|
.header(header::RANGE, "bytes=10-20")
|
||||||
.to_request();
|
.send()
|
||||||
|
.await
|
||||||
let response = test::call_service(&mut srv, request).await;
|
|
||||||
let contentrange = response
|
|
||||||
.headers()
|
|
||||||
.get(header::CONTENT_RANGE)
|
|
||||||
.unwrap()
|
|
||||||
.to_str()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
let content_range = response.headers().get(header::CONTENT_RANGE).unwrap();
|
||||||
assert_eq!(contentrange, "bytes 10-20/100");
|
assert_eq!(content_range.to_str().unwrap(), "bytes 10-20/100");
|
||||||
|
|
||||||
// Invalid range header
|
// Invalid range header
|
||||||
let request = TestRequest::get()
|
let response = srv
|
||||||
.uri("/t%65st/tests/test.binary")
|
.get("/tests/test.binary")
|
||||||
.header(header::RANGE, "bytes=10-5")
|
.header(header::RANGE, "bytes=10-5")
|
||||||
.to_request();
|
.send()
|
||||||
let response = test::call_service(&mut srv, request).await;
|
.await
|
||||||
|
|
||||||
let contentrange = response
|
|
||||||
.headers()
|
|
||||||
.get(header::CONTENT_RANGE)
|
|
||||||
.unwrap()
|
|
||||||
.to_str()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
let content_range = response.headers().get(header::CONTENT_RANGE).unwrap();
|
||||||
assert_eq!(contentrange, "bytes */100");
|
assert_eq!(content_range.to_str().unwrap(), "bytes */100");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_named_file_content_length_headers() {
|
async fn test_named_file_content_length_headers() {
|
||||||
// use actix_web::body::{MessageBody, ResponseBody};
|
let srv = test::start(|| {
|
||||||
|
App::new().service(Files::new("/", "."))
|
||||||
let mut srv = test::init_service(
|
});
|
||||||
App::new().service(Files::new("test", ".").index_file("tests/test.binary")),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// Valid range header
|
// Valid range header
|
||||||
let request = TestRequest::get()
|
let response = srv
|
||||||
.uri("/t%65st/tests/test.binary")
|
.get("/tests/test.binary")
|
||||||
.header(header::RANGE, "bytes=10-20")
|
.header(header::RANGE, "bytes=10-20")
|
||||||
.to_request();
|
.send()
|
||||||
let _response = test::call_service(&mut srv, request).await;
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let content_length = response.headers().get(header::CONTENT_LENGTH).unwrap();
|
||||||
|
assert_eq!(content_length.to_str().unwrap(), "11");
|
||||||
|
|
||||||
// let contentlength = response
|
// Valid range header, starting from 0
|
||||||
// .headers()
|
let response = srv
|
||||||
// .get(header::CONTENT_LENGTH)
|
.get("/tests/test.binary")
|
||||||
// .unwrap()
|
.header(header::RANGE, "bytes=0-20")
|
||||||
// .to_str()
|
.send()
|
||||||
// .unwrap();
|
.await
|
||||||
// assert_eq!(contentlength, "11");
|
.unwrap();
|
||||||
|
let content_length = response.headers().get(header::CONTENT_LENGTH).unwrap();
|
||||||
// Invalid range header
|
assert_eq!(content_length.to_str().unwrap(), "21");
|
||||||
let request = TestRequest::get()
|
|
||||||
.uri("/t%65st/tests/test.binary")
|
|
||||||
.header(header::RANGE, "bytes=10-8")
|
|
||||||
.to_request();
|
|
||||||
let response = test::call_service(&mut srv, request).await;
|
|
||||||
assert_eq!(response.status(), StatusCode::RANGE_NOT_SATISFIABLE);
|
|
||||||
|
|
||||||
// Without range header
|
// Without range header
|
||||||
let request = TestRequest::get()
|
let mut response = srv.get("/tests/test.binary").send().await.unwrap();
|
||||||
.uri("/t%65st/tests/test.binary")
|
let content_length = response.headers().get(header::CONTENT_LENGTH).unwrap();
|
||||||
// .no_default_headers()
|
assert_eq!(content_length.to_str().unwrap(), "100");
|
||||||
.to_request();
|
|
||||||
let _response = test::call_service(&mut srv, request).await;
|
|
||||||
|
|
||||||
// let contentlength = response
|
// Should be no transfer-encoding
|
||||||
// .headers()
|
let transfer_encoding = response.headers().get(header::TRANSFER_ENCODING);
|
||||||
// .get(header::CONTENT_LENGTH)
|
assert!(transfer_encoding.is_none());
|
||||||
// .unwrap()
|
|
||||||
// .to_str()
|
|
||||||
// .unwrap();
|
|
||||||
// assert_eq!(contentlength, "100");
|
|
||||||
|
|
||||||
// chunked
|
// Check file contents
|
||||||
let request = TestRequest::get()
|
let bytes = response.body().await.unwrap();
|
||||||
.uri("/t%65st/tests/test.binary")
|
|
||||||
.to_request();
|
|
||||||
let response = test::call_service(&mut srv, request).await;
|
|
||||||
|
|
||||||
// with enabled compression
|
|
||||||
// {
|
|
||||||
// let te = response
|
|
||||||
// .headers()
|
|
||||||
// .get(header::TRANSFER_ENCODING)
|
|
||||||
// .unwrap()
|
|
||||||
// .to_str()
|
|
||||||
// .unwrap();
|
|
||||||
// assert_eq!(te, "chunked");
|
|
||||||
// }
|
|
||||||
|
|
||||||
let bytes = test::read_body(response).await;
|
|
||||||
let data = Bytes::from(fs::read("tests/test.binary").unwrap());
|
let data = Bytes::from(fs::read("tests/test.binary").unwrap());
|
||||||
assert_eq!(bytes, data);
|
assert_eq!(bytes, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_head_content_length_headers() {
|
async fn test_head_content_length_headers() {
|
||||||
let mut srv = test::init_service(
|
let srv = test::start(|| {
|
||||||
App::new().service(Files::new("test", ".").index_file("tests/test.binary")),
|
App::new().service(Files::new("/", "."))
|
||||||
)
|
});
|
||||||
.await;
|
|
||||||
|
|
||||||
// Valid range header
|
let response = srv
|
||||||
let request = TestRequest::default()
|
.head("/tests/test.binary")
|
||||||
.method(Method::HEAD)
|
.send()
|
||||||
.uri("/t%65st/tests/test.binary")
|
.await
|
||||||
.to_request();
|
.unwrap();
|
||||||
let _response = test::call_service(&mut srv, request).await;
|
|
||||||
|
|
||||||
// TODO: fix check
|
let content_length = response
|
||||||
// let contentlength = response
|
.headers()
|
||||||
// .headers()
|
.get(header::CONTENT_LENGTH)
|
||||||
// .get(header::CONTENT_LENGTH)
|
.unwrap()
|
||||||
// .unwrap()
|
.to_str()
|
||||||
// .to_str()
|
.unwrap();
|
||||||
// .unwrap();
|
|
||||||
// assert_eq!(contentlength, "100");
|
assert_eq!(content_length, "100");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
|
@ -18,7 +18,7 @@ use actix_web::http::header::{
|
|||||||
};
|
};
|
||||||
use actix_web::http::{ContentEncoding, StatusCode};
|
use actix_web::http::{ContentEncoding, StatusCode};
|
||||||
use actix_web::{Error, HttpMessage, HttpRequest, HttpResponse, Responder};
|
use actix_web::{Error, HttpMessage, HttpRequest, HttpResponse, Responder};
|
||||||
use futures::future::{ready, Ready};
|
use futures_util::future::{ready, Ready};
|
||||||
|
|
||||||
use crate::range::HttpRange;
|
use crate::range::HttpRange;
|
||||||
use crate::ChunkedReadFile;
|
use crate::ChunkedReadFile;
|
||||||
@ -388,11 +388,12 @@ impl NamedFile {
|
|||||||
fut: None,
|
fut: None,
|
||||||
counter: 0,
|
counter: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
if offset != 0 || length != self.md.len() {
|
if offset != 0 || length != self.md.len() {
|
||||||
Ok(resp.status(StatusCode::PARTIAL_CONTENT).streaming(reader))
|
resp.status(StatusCode::PARTIAL_CONTENT);
|
||||||
} else {
|
|
||||||
Ok(resp.body(SizedStream::new(length, reader)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(resp.body(SizedStream::new(length, reader)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-framed"
|
name = "actix-framed"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix framed app server"
|
description = "Actix framed app server"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
# Framed app for actix web [](https://travis-ci.org/actix/actix-web) [](https://codecov.io/gh/actix/actix-web) [](https://crates.io/crates/actix-framed) [](https://gitter.im/actix/actix?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
# Framed app for actix web [](https://travis-ci.org/actix/actix-web) [](https://codecov.io/gh/actix/actix-web) [](https://crates.io/crates/actix-framed) [](https://gitter.im/actix/actix?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
|
|
||||||
|
**Notice**: `actix-framed` is deprecated since we don't use it anymore.
|
||||||
|
|
||||||
## Documentation & community resources
|
## Documentation & community resources
|
||||||
|
|
||||||
* [API Documentation](https://docs.rs/actix-framed/)
|
* [API Documentation](https://docs.rs/actix-framed/)
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.3.1] - 2020-05-25
|
||||||
|
|
||||||
|
* Deprecate this crate
|
||||||
|
|
||||||
## [0.3.0] - 2019-12-25
|
## [0.3.0] - 2019-12-25
|
||||||
|
|
||||||
* Migrate to actix-http 1.0
|
* Migrate to actix-http 1.0
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/cookie/0.11")]
|
#![doc(html_root_url = "https://docs.rs/cookie/0.11")]
|
||||||
#![deny(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
mod builder;
|
mod builder;
|
||||||
mod delta;
|
mod delta;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
//! Basic http primitives for actix-net framework.
|
//! Basic http primitives for actix-net framework.
|
||||||
#![deny(rust_2018_idioms, warnings)]
|
#![warn(rust_2018_idioms, warnings)]
|
||||||
#![allow(
|
#![allow(
|
||||||
clippy::type_complexity,
|
clippy::type_complexity,
|
||||||
clippy::too_many_arguments,
|
clippy::too_many_arguments,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#![deny(rust_2018_idioms, warnings)]
|
#![warn(rust_2018_idioms, warnings)]
|
||||||
#![allow(
|
#![allow(
|
||||||
clippy::type_complexity,
|
clippy::type_complexity,
|
||||||
clippy::borrow_interior_mutable_const,
|
clippy::borrow_interior_mutable_const,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#![deny(rust_2018_idioms, warnings)]
|
#![warn(rust_2018_idioms, warnings)]
|
||||||
#![allow(
|
#![allow(
|
||||||
clippy::needless_doctest_main,
|
clippy::needless_doctest_main,
|
||||||
clippy::type_complexity,
|
clippy::type_complexity,
|
||||||
|
Reference in New Issue
Block a user