-
Notifications
You must be signed in to change notification settings - Fork 35
Handle Hyper 0.11's Headers implementation #90
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
Merged
Merged
Conversation
This file contains hidden or 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
In Hyper 0.11, the following code will panic:
use hyper::header::{Authorization, Basic, Bearer, Headers};
fn main() {
let mut headers = Headers::default();
let basic = Basic { username: "richard".to_string(), password: None };
headers.set::<Authorization<Basic>>(Authorization(basic));
println!("Auth: {:?}", headers.get::<Authorization<Bearer>>());
}
This is because `std::any::TypeId::of<Authorization<Basic>>` and
`std::any::TypeId::of<Authorization<Bearer>>` don't match, but the header
name, `Authorization` does.
We provide a `.safe_get::<Authorization<Bearer>>` to workaround this issue.
Signed-off-by: Richard Whitehouse <[email protected]>
Signed-off-by: Richard Whitehouse <[email protected]>
a878980 to
6cc9881
Compare
mthebridge
reviewed
Dec 12, 2019
mthebridge
approved these changes
Dec 12, 2019
Contributor
mthebridge
left a comment
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.
One very minor inline comment to prove Iw as paying attention... Looks good otherwise.
Signed-off-by: Richard Whitehouse <[email protected]>
Signed-off-by: Richard Whitehouse <[email protected]>
a6d08c0 to
ed5b6a9
Compare
Contributor
Author
|
bors r+ |
bors bot
added a commit
that referenced
this pull request
Dec 12, 2019
90: Handle Hyper 0.11's Headers implementation r=richardwhiuk a=richardwhiuk
In Hyper 0.11, the following code will panic:
use hyper::header::{Authorization, Basic, Bearer, Headers};
fn main() {
let mut headers = Headers::default();
let basic = Basic { username: "richard".to_string(), password: None };
headers.set::<Authorization<Basic>>(Authorization(basic));
println!("Auth: {:?}", headers.get::<Authorization<Bearer>>());
}
This is because `std::any::TypeId::of<Authorization<Basic>>` and
`std::any::TypeId::of<Authorization<Bearer>>` don't match, but the header
name, `Authorization` does.
We provide a `.safe_get::<Authorization<Bearer>>` to workaround this issue.
Co-authored-by: Richard Whitehouse <[email protected]>
Contributor
Author
|
bors r+ |
bors bot
added a commit
that referenced
this pull request
Dec 12, 2019
90: Handle Hyper 0.11's Headers implementation r=richardwhiuk a=richardwhiuk
In Hyper 0.11, the following code will panic:
use hyper::header::{Authorization, Basic, Bearer, Headers};
fn main() {
let mut headers = Headers::default();
let basic = Basic { username: "richard".to_string(), password: None };
headers.set::<Authorization<Basic>>(Authorization(basic));
println!("Auth: {:?}", headers.get::<Authorization<Bearer>>());
}
This is because `std::any::TypeId::of<Authorization<Basic>>` and
`std::any::TypeId::of<Authorization<Bearer>>` don't match, but the header
name, `Authorization` does.
We provide a `.safe_get::<Authorization<Bearer>>` to workaround this issue.
Co-authored-by: Richard Whitehouse <[email protected]>
Contributor
Build succeeded |
5 tasks
richardwhiuk
added a commit
to OpenAPITools/openapi-generator
that referenced
this pull request
Jan 5, 2020
[Rust Server] Fix panic handling headers
If we have an API which has multiple auth types, we may panic. This is because
in Hyper 0.11, the following code will panic:
```
use hyper::header::{Authorization, Basic, Bearer, Headers};
fn main() {
let mut headers = Headers::default();
let basic = Basic { username: "richard".to_string(), password: None };
headers.set::<Authorization<Basic>>(Authorization(basic));
println!("Auth: {:?}", headers.get::<Authorization<Bearer>>());
}
```
as it mixes up an `Authorization<Basic>` and `Authorization<Bearer>` as both
have `Authorization:` as the header name.
This is fixed by using `swagger::SafeHeaders` added in
Metaswitch/swagger-rs#90
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In Hyper 0.11, the following code will panic:
This is because
std::any::TypeId::of<Authorization<Basic>>andstd::any::TypeId::of<Authorization<Bearer>>don't match, but the headername,
Authorizationdoes.We provide a
.safe_get::<Authorization<Bearer>>to workaround this issue.