-
Notifications
You must be signed in to change notification settings - Fork 321
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
059a8f8
add tide-compression crate
fairingrey 250c2b9
Merge remote-tracking branch 'upstream/master' into compression
fairingrey 80f0af6
use run instead of serve
fairingrey 962fddc
Update tide-compression/README.md
fairingrey 29cdf99
Merge remote-tracking branch 'upstream/master' into compression
fairingrey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[workspace] | ||
members = [ | ||
"tide", | ||
"tide-compression", | ||
"examples", | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } | ||
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 @- | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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!