Skip to content

Commit

Permalink
Merge branch 'seanmonstar:master' into local-socketaddr
Browse files Browse the repository at this point in the history
  • Loading branch information
daviessm committed Apr 22, 2023
2 parents 7e1dff3 + e2f4501 commit a6cf59a
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 85 deletions.
43 changes: 10 additions & 33 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v3

- name: Install rust
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: rustfmt
profile: minimal
override: true

- name: cargo fmt -- --check
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- run: cargo fmt --all --check

test:
name: Test
Expand All @@ -50,48 +43,32 @@ jobs:
- build: compression
features: "--features compression"


steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v3

- name: Install rust
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust || 'stable' }}
profile: minimal
override: true

- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: ${{ matrix.features }}
run: cargo test ${{ matrix.features }}

- name: Test all benches
if: matrix.benches
uses: actions-rs/cargo@v1
with:
command: test
args: --benches ${{ matrix.features }}
run: cargo test --benches ${{ matrix.features }}

doc:
name: Build docs
needs: [style, test]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v3

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
uses: dtolnay/rust-toolchain@nightly

- name: cargo doc
uses: actions-rs/cargo@v1
with:
command: rustdoc
args: -- -D broken_intra_doc_links
run: cargo rustdoc -- -D broken_intra_doc_links
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### v0.3.4 (March 31, 2023)

- **Fixes**:
- `multipart::Part` data is now streamed instead of buffered.
- Update dependency used for `multipart` filters.

### v0.3.3 (September 27, 2022)

- **Fixes**:
Expand Down
18 changes: 12 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "warp"
version = "0.3.3" # don't forget to update html_root_url
version = "0.3.4" # don't forget to update html_root_url
description = "serve the web at warp speeds"
authors = ["Sean McArthur <sean@seanmonstar.com>"]
license = "MIT"
Expand All @@ -27,7 +27,7 @@ hyper = { version = "0.14.19", features = ["stream", "server", "http1", "http2",
log = "0.4"
mime = "0.3"
mime_guess = "2.0.0"
multipart = { version = "0.18", default-features = false, features = ["server"], optional = true }
multer = { version = "2.1.0", optional = true }
scoped-tls = "1.0"
serde = "1.0"
serde_json = "1.0"
Expand All @@ -37,24 +37,25 @@ tokio-stream = "0.1.1"
tokio-util = { version = "0.7", features = ["io"] }
tracing = { version = "0.1.21", default-features = false, features = ["log", "std"] }
tower-service = "0.3"
tokio-tungstenite = { version = "0.17", optional = true }
tokio-tungstenite = { version = "0.18", optional = true }
percent-encoding = "2.1"
pin-project = "1.0"
tokio-rustls = { version = "0.23", optional = true }
rustls-pemfile = "0.2"
rustls-pemfile = "1.0"

[dev-dependencies]
pretty_env_logger = "0.4"
tracing-subscriber = "0.2.7"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-log = "0.1"
serde_derive = "1.0"
handlebars = "4.0"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
tokio-stream = { version = "0.1.1", features = ["net"] }
listenfd = "0.3"
listenfd = "1.0"

[features]
default = ["multipart", "websocket"]
multipart = ["multer"]
websocket = ["tokio-tungstenite"]
tls = ["tokio-rustls"]

Expand Down Expand Up @@ -96,3 +97,8 @@ required-features = ["websocket"]

[[example]]
name = "query_string"


[[example]]
name = "multipart"
required-features = ["multipart"]
28 changes: 28 additions & 0 deletions examples/multipart.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use futures_util::TryStreamExt;
use warp::multipart::FormData;
use warp::Buf;
use warp::Filter;

#[tokio::main]
async fn main() {
// Running curl -F file=@.gitignore 'localhost:3030/' should print [("file", ".gitignore", "\n/target\n**/*.rs.bk\nCargo.lock\n.idea/\nwarp.iml\n")]
let route = warp::multipart::form().and_then(|form: FormData| async move {
let field_names: Vec<_> = form
.and_then(|mut field| async move {
let contents =
String::from_utf8_lossy(field.data().await.unwrap().unwrap().chunk())
.to_string();
Ok((
field.name().to_string(),
field.filename().unwrap().to_string(),
contents,
))
})
.try_collect()
.await
.unwrap();

Ok::<_, warp::Rejection>(format!("{:?}", field_names))
});
warp::serve(route).run(([127, 0, 0, 1], 3030)).await;
}
10 changes: 5 additions & 5 deletions examples/todos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod filters {
/// The 4 TODOs filters combined.
pub fn todos(
db: Db,
) -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
todos_list(db.clone())
.or(todos_create(db.clone()))
.or(todos_update(db.clone()))
Expand All @@ -48,7 +48,7 @@ mod filters {
/// GET /todos?offset=3&limit=5
pub fn todos_list(
db: Db,
) -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
warp::path!("todos")
.and(warp::get())
.and(warp::query::<ListOptions>())
Expand All @@ -59,7 +59,7 @@ mod filters {
/// POST /todos with JSON body
pub fn todos_create(
db: Db,
) -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
warp::path!("todos")
.and(warp::post())
.and(json_body())
Expand All @@ -70,7 +70,7 @@ mod filters {
/// PUT /todos/:id with JSON body
pub fn todos_update(
db: Db,
) -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
warp::path!("todos" / u64)
.and(warp::put())
.and(json_body())
Expand All @@ -81,7 +81,7 @@ mod filters {
/// DELETE /todos/:id
pub fn todos_delete(
db: Db,
) -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
// We'll make one of our endpoints admin-only to show how authentication filters are used
let admin_only = warp::header::exact("authorization", "Bearer admin");

Expand Down
Loading

0 comments on commit a6cf59a

Please sign in to comment.