Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware-based compression and decompression #194

Merged
merged 5 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ before_script: |
rustup component add rustfmt clippy
script: |
cargo fmt --all -- --check &&
cargo clippy --all -- -D clippy::all &&
cargo clippy --all --all-features -- -D clippy::all &&
cargo build --no-default-features --verbose &&
cargo build --all --verbose &&
cargo test --all --verbose
cargo build --all --all-features --verbose &&
cargo test --all --all-features --verbose
cache: cargo
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"tide",
"tide-compression",
"examples",
]

Expand Down
30 changes: 30 additions & 0 deletions tide-compression/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
authors = [
"Tide Developers",
]
description = "Compression-related middleware for Tide"
documentation = "https://docs.rs/tide-compression"
keywords = ["tide", "web", "async", "middleware", "compression"]
categories = ["network-programming", "compression", "asynchronous"]
edition = "2018"
license = "MIT OR Apache-2.0"
name = "tide-compression"
readme = "README.md"
repository = "https://github.com/rustasync/tide"
version = "0.1.0"

[dependencies]
tide = { path = "../tide" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a version field in order to publish this crate. Let's do this after structure revamp!

accept-encoding = "0.2.0-alpha.2"
bytes = "0.4.12"
futures-preview = "0.3.0-alpha.16"
http = "0.1"
http-service = "0.2.0"

[dependencies.async-compression]
default-features = false
features = ["stream", "gzip", "zlib", "brotli", "zstd"]
version = "0.1.0-alpha.1"

[dev-dependencies]
http-service-mock = "0.2.0"
16 changes: 16 additions & 0 deletions tide-compression/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# tide-compression

This crate provides compression-related middleware for Tide.

## Examples

Examples are in the `/examples` folder of this crate.

__Simple Example__

You can test the simple example by running `cargo run --example simple` while in this crate's directory, and then running either of the following commands:

```console
$ curl http://127.0.0.1:8000/ -v
$ echo 'why hello there' | gzip | curl -v --compressed -H 'Content-Encoding: gzip' 'http://127.0.0.1:8000/echo' --data-binary @-
```
22 changes: 22 additions & 0 deletions tide-compression/examples/simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![feature(async_await)]
use tide::{App, Context};
use tide_compression::{Compression, Decompression, Encoding};

// Returns a portion of the lorem ipsum text.
async fn lorem_ipsum(_cx: Context<()>) -> String {
String::from("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
}

// Echoes the request body in bytes.
async fn echo_bytes(mut cx: Context<()>) -> Vec<u8> {
cx.body_bytes().await.unwrap()
}

pub fn main() {
let mut app = App::new();
app.at("/").get(lorem_ipsum);
app.at("/echo").post(echo_bytes);
app.middleware(Compression::with_default(Encoding::Brotli));
app.middleware(Decompression::new());
app.run("127.0.0.1:8000").unwrap();
}
Loading