-
-
Notifications
You must be signed in to change notification settings - Fork 723
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into add-wrap-fn
- Loading branch information
Showing
16 changed files
with
286 additions
and
25 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: '' | ||
labels: bug | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Version** | ||
List the versions of all `warp` crates you are using. The easiest way to get | ||
this information is using `cargo-tree`. | ||
|
||
`cargo install cargo-tree` | ||
(see install here: https://github.com/sfackler/cargo-tree) | ||
|
||
Then: | ||
|
||
`cargo tree | grep warp` | ||
|
||
**Platform** | ||
The output of `uname -a` (UNIX), or version and 32 or 64-bit (Windows) | ||
|
||
**Description** | ||
Enter your issue details here. | ||
One way to structure the description: | ||
|
||
[short summary of the bug] | ||
|
||
I tried this code: | ||
|
||
[code sample that causes the bug] | ||
|
||
I expected to see this happen: [explanation] | ||
|
||
Instead, this happened: [explanation] |
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,20 @@ | ||
--- | ||
name: Feature request | ||
about: Suggest an idea for this project | ||
title: '' | ||
labels: feature | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Is your feature request related to a problem? Please describe.** | ||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] | ||
|
||
**Describe the solution you'd like** | ||
A clear and concise description of what you want to happen. | ||
|
||
**Describe alternatives you've considered** | ||
A clear and concise description of any alternative solutions or features you've considered. | ||
|
||
**Additional context** | ||
Add any other context or screenshots about the feature request here. |
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,14 @@ | ||
--- | ||
name: Question | ||
about: Please use Discord channel for questions | ||
title: '' | ||
labels: '' | ||
assignees: '' | ||
|
||
--- | ||
|
||
Please post your question the warp Discord channel: | ||
using the #warp channel on https://discord.gg/tokio. | ||
|
||
You may also be able to find help here: | ||
https://users.rust-lang.org/ |
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,6 @@ | ||
[package] | ||
name = "warp" | ||
version = "0.2.3" # don't forget to update html_root_url | ||
version = "0.2.4" # don't forget to update html_root_url | ||
description = "serve the web at warp speeds" | ||
authors = ["Sean McArthur <[email protected]>"] | ||
license = "MIT" | ||
|
@@ -26,7 +26,7 @@ hyper = { version = "0.13", features = ["stream"] } | |
log = "0.4" | ||
mime = "0.3" | ||
mime_guess = "2.0.0" | ||
multipart = { version = "0.16", default-features = false, features = ["server"], optional = true } | ||
multipart = { version = "0.17", default-features = false, features = ["server"], optional = true } | ||
scoped-tls = "1.0" | ||
serde = "1.0" | ||
serde_json = "1.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
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
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,96 @@ | ||
//! Host ("authority") filter | ||
//! | ||
use crate::filter::{filter_fn_one, Filter, One}; | ||
use crate::reject::{self, Rejection}; | ||
use futures::future; | ||
pub use http::uri::Authority; | ||
use std::str::FromStr; | ||
|
||
/// Creates a `Filter` that requires a specific authority (target server's | ||
/// host and port) in the request. | ||
/// | ||
/// Authority is specified either in the `Host` header or in the target URI. | ||
/// | ||
/// # Example | ||
/// | ||
/// ``` | ||
/// use warp::Filter; | ||
/// | ||
/// let multihost = | ||
/// warp::host::exact("foo.com").map(|| "you've reached foo.com") | ||
/// .or(warp::host::exact("bar.com").map(|| "you've reached bar.com")); | ||
/// ``` | ||
pub fn exact(expected: &str) -> impl Filter<Extract = (), Error = Rejection> + Clone { | ||
let expected = Authority::from_str(expected).expect("invalid host/authority"); | ||
optional() | ||
.and_then(move |option: Option<Authority>| match option { | ||
Some(authority) if authority == expected => future::ok(()), | ||
_ => future::err(reject::not_found()), | ||
}) | ||
.untuple_one() | ||
} | ||
|
||
/// Creates a `Filter` that looks for an authority (target server's host | ||
/// and port) in the request. | ||
/// | ||
/// Authority is specified either in the `Host` header or in the target URI. | ||
/// | ||
/// If found, extracts the `Authority`, otherwise continues the request, | ||
/// extracting `None`. | ||
/// | ||
/// Rejects with `400 Bad Request` if the `Host` header is malformed or if there | ||
/// is a mismatch between the `Host` header and the target URI. | ||
/// | ||
/// # Example | ||
/// | ||
/// ``` | ||
/// use warp::{Filter, host::Authority}; | ||
/// | ||
/// let host = warp::host::optional() | ||
/// .map(|authority: Option<Authority>| { | ||
/// if let Some(a) = authority { | ||
/// format!("{} is currently not at home", a.host()) | ||
/// } else { | ||
/// "please state who you're trying to reach".to_owned() | ||
/// } | ||
/// }); | ||
/// ``` | ||
pub fn optional() -> impl Filter<Extract = One<Option<Authority>>, Error = Rejection> + Copy { | ||
filter_fn_one(move |route| { | ||
// The authority can be sent by clients in various ways: | ||
// | ||
// 1) in the "target URI" | ||
// a) serialized in the start line (HTTP/1.1 proxy requests) | ||
// b) serialized in `:authority` pseudo-header (HTTP/2 generated - "SHOULD") | ||
// 2) in the `Host` header (HTTP/1.1 origin requests, HTTP/2 converted) | ||
// | ||
// Hyper transparently handles 1a/1b, but not 2, so we must look at both. | ||
|
||
let from_uri = route.uri().authority(); | ||
|
||
let name = "host"; | ||
let from_header = route.headers() | ||
.get(name) | ||
.map(|value| | ||
// Header present, parse it | ||
value.to_str().map_err(|_| reject::invalid_header(name)) | ||
.and_then(|value| Authority::from_str(value).map_err(|_| reject::invalid_header(name))) | ||
); | ||
|
||
future::ready(match (from_uri, from_header) { | ||
// no authority in the request (HTTP/1.0 or non-conforming) | ||
(None, None) => Ok(None), | ||
|
||
// authority specified in either or both matching | ||
(Some(a), None) => Ok(Some(a.clone())), | ||
(None, Some(Ok(a))) => Ok(Some(a)), | ||
(Some(a), Some(Ok(b))) if *a == b => Ok(Some(b)), | ||
|
||
// mismatch | ||
(Some(_), Some(Ok(_))) => Err(reject::invalid_header(name)), | ||
|
||
// parse error | ||
(_, Some(Err(r))) => Err(r), | ||
}) | ||
}) | ||
} |
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
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
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
Oops, something went wrong.