-
Notifications
You must be signed in to change notification settings - Fork 25
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
expose all HTTP headers #60
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -20,6 +20,8 @@ use bytes::BytesMut; | |
use futures::prelude::*; | ||
use std::{mem, str}; | ||
|
||
pub use httparse::Header; | ||
|
||
// Most HTTP servers default to 8KB limit on headers | ||
const MAX_HEADERS_SIZE: usize = 8 * 1024; | ||
const BLOCK_SIZE: usize = 8 * 1024; | ||
|
@@ -142,24 +144,13 @@ impl<'a, T: AsyncRead + AsyncWrite + Unpin> Server<'a, T> { | |
return Err(Error::UnsupportedHttpVersion); | ||
} | ||
|
||
let host = with_first_header(&request.headers, "Host", Ok)?; | ||
// do we need to this when all headers are exposed?!. | ||
let _host = with_first_header(&request.headers, "Host", Ok)?; | ||
|
||
expect_ascii_header(request.headers, "Upgrade", "websocket")?; | ||
expect_ascii_header(request.headers, "Connection", "upgrade")?; | ||
expect_ascii_header(request.headers, "Sec-WebSocket-Version", "13")?; | ||
|
||
let origin = | ||
request.headers.iter().find_map( | ||
|h| { | ||
if h.name.eq_ignore_ascii_case("Origin") { | ||
Some(h.value) | ||
} else { | ||
None | ||
} | ||
}, | ||
); | ||
let headers = RequestHeaders { host, origin }; | ||
|
||
let ws_key = with_first_header(&request.headers, "Sec-WebSocket-Key", |k| { | ||
WebSocketKey::try_from(k).map_err(|_| Error::SecWebSocketKeyInvalidLength(k.len())) | ||
})?; | ||
|
@@ -177,7 +168,7 @@ impl<'a, T: AsyncRead + AsyncWrite + Unpin> Server<'a, T> { | |
|
||
let path = request.path.unwrap_or("/"); | ||
|
||
Ok(ClientRequest { ws_key, protocols, path, headers }) | ||
Ok(ClientRequest { ws_key, protocols, path, headers: request.headers.to_vec() }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so, the headers is parsed from an array which is |
||
} | ||
|
||
// Encode server handshake response. | ||
|
@@ -224,16 +215,7 @@ pub struct ClientRequest<'a> { | |
ws_key: WebSocketKey, | ||
protocols: Vec<&'a str>, | ||
path: &'a str, | ||
headers: RequestHeaders<'a>, | ||
} | ||
|
||
/// Select HTTP headers sent by the client. | ||
#[derive(Debug, Copy, Clone)] | ||
pub struct RequestHeaders<'a> { | ||
/// The [`Host`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host) header. | ||
pub host: &'a [u8], | ||
/// The [`Origin`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin) header, if provided. | ||
pub origin: Option<&'a [u8]>, | ||
headers: Vec<Header<'a>>, | ||
} | ||
|
||
impl<'a> ClientRequest<'a> { | ||
|
@@ -252,9 +234,13 @@ impl<'a> ClientRequest<'a> { | |
self.path | ||
} | ||
|
||
/// Select HTTP headers sent by the client. | ||
pub fn headers(&self) -> RequestHeaders { | ||
self.headers | ||
/// HTTP headers sent by the client. | ||
pub fn headers(&self) -> &'a [Header] { | ||
&self.headers | ||
} | ||
|
||
pub fn into_parts(self) -> (WebSocketKey, Vec<&'a str>, &'a str, Vec<Header<'a>>) { | ||
(self.ws_key, self.protocols, self.path, self.headers) | ||
} | ||
} | ||
|
||
|
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.
it doesn't makes sense to use
httparse::Header
to construct new headers, the type is used for parsed headers and doesn't check whether the header is valid or not.however, it still possible to enter some conflicting headers such as
host
,websocket upgrade
and similar as these are configured separately.