Uh oh!
There was an error while loading. Please reload this page.
Handle Hyper 0.11's Headers implementation - #90
Merged
Merged
Conversation
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 <richard.whitehouse@metaswitch.com>Signed-off-by: Richard Whitehouse <richard.whitehouse@metaswitch.com>
richardwhiukforce-pushed
the
safe_headers
branch
from
December 12, 2019 13:36
a878980 to
6cc9881CompareUh oh!
There was an error while loading. Please reload this page.
mthebridge
approved these changes
Dec 12, 2019
mthebridge
left a comment
Contributor
There was a problem hiding this comment.
One very minor inline comment to prove Iw as paying attention... Looks good otherwise.
Signed-off-by: Richard Whitehouse <richard.whitehouse@metaswitch.com>
Signed-off-by: Richard Whitehouse <richard.whitehouse@metaswitch.com>
richardwhiukforce-pushed
the
safe_headers
branch
from
December 12, 2019 14:23
a6d08c0 to
ed5b6a9Comparerichardwhiuk
commented
Dec 12, 2019
ContributorAuthor
bors r+ |
borsBot
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 <richard.whitehouse@metaswitch.com>richardwhiuk
commented
Dec 12, 2019
ContributorAuthor
bors r+ |
borsBot
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 <richard.whitehouse@metaswitch.com>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
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
Sign up for freeto 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.