From f45db1f909d9247e5cba5bef1d897f17e3fd9241 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 22 Dec 2019 16:43:41 +0900 Subject: [PATCH] Enable GitHub Actions and fix file URL behavior (#1232) * Use GitHub Actions * Fix unused imports on Windows * Fix test for Windows * Stop to run CI for i686-pc-windows-msvc for now * Use `/` instead of `\` on Windows * Add entry to changelog * Prepare actix-files release --- .github/workflows/main.yml | 67 ++++++++++++++++++++++++++++++++++++++ actix-files/CHANGES.md | 4 +++ actix-files/Cargo.toml | 2 +- actix-files/src/lib.rs | 5 +-- src/server.rs | 12 +++++-- 5 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..693291fd3 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,67 @@ +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 diff --git a/actix-files/CHANGES.md b/actix-files/CHANGES.md index 5712c9243..c4918b56d 100644 --- a/actix-files/CHANGES.md +++ b/actix-files/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [0.2.1] - 2019-12-22 + +* Use the same format for file URLs regardless of platforms + ## [0.2.0] - 2019-12-20 * Fix BodyEncoding trait import #1220 diff --git a/actix-files/Cargo.toml b/actix-files/Cargo.toml index 7f11605a1..6920a3090 100644 --- a/actix-files/Cargo.toml +++ b/actix-files/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-files" -version = "0.2.0" +version = "0.2.1" authors = ["Nikolay Kim "] description = "Static files support for actix web." readme = "README.md" diff --git a/actix-files/src/lib.rs b/actix-files/src/lib.rs index c45caf375..ac26f70cc 100644 --- a/actix-files/src/lib.rs +++ b/actix-files/src/lib.rs @@ -155,7 +155,7 @@ impl Directory { // show file url as relative to static path macro_rules! encode_file_url { ($path:ident) => { - utf8_percent_encode(&$path.to_string_lossy(), CONTROLS) + utf8_percent_encode(&$path, CONTROLS) }; } @@ -178,7 +178,8 @@ fn directory_listing( if dir.is_visible(&entry) { let entry = entry.unwrap(); let p = match entry.path().strip_prefix(&dir.path) { - Ok(p) => base.join(p), + Ok(p) if cfg!(windows) => base.join(p).to_string_lossy().replace("\\", "/"), + Ok(p) => base.join(p).to_string_lossy().into_owned(), Err(_) => continue, }; diff --git a/src/server.rs b/src/server.rs index 72ef7255b..2830f8743 100644 --- a/src/server.rs +++ b/src/server.rs @@ -3,16 +3,22 @@ use std::sync::{Arc, Mutex}; use std::{fmt, io, net}; use actix_http::{ - body::MessageBody, Error, HttpService, KeepAlive, Protocol, Request, Response, + body::MessageBody, Error, HttpService, KeepAlive, Request, Response, }; use actix_server::{Server, ServerBuilder}; use actix_service::{ - map_config, pipeline_factory, IntoServiceFactory, Service, ServiceFactory, + map_config, IntoServiceFactory, Service, ServiceFactory, }; -use futures::future::ok; use net2::TcpBuilder; +#[cfg(unix)] +use actix_http::Protocol; +#[cfg(unix)] +use actix_service::pipeline_factory; +#[cfg(unix)] +use futures::future::ok; + #[cfg(feature = "openssl")] use actix_tls::openssl::{AlpnError, SslAcceptor, SslAcceptorBuilder}; #[cfg(feature = "rustls")]