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
Add method to expose missing/invalid reject names #447
Add method to expose missing/invalid reject names #447
Conversation
3315d41
to
9d06cd2
Compare
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.
LGTM 👍
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.
Looks like a good idea, just one comment!
src/reject.rs
Outdated
@@ -506,6 +506,13 @@ pub struct MissingHeader { | |||
name: &'static str, | |||
} | |||
|
|||
impl MissingHeader { | |||
/// Retrieve the name of the header that was missing | |||
pub fn name(self) -> &'static str { |
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.
I'd suggest this should just return &str
, in case we ever needed to store a dynamic String
in some cases.
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.
Thanks, I was a bit unsure about this lifetime, but I have changed it as suggested to live as long as the rejection itself (I think). Hope this works!
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.
Oh, I didn't notice that these methods take self
by value instead of by reference (&self
). That should be changed, otherwise you can't call these methods from a &MissingHeader
etc.
With that change, you don't need to specify any specific lifetime. They'll just look like pub fn name(&self) -> &str {
.
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.
Oh sorry again, I actually didn't know you could do that for some reason. Anyway have hopefully fixed it now and have squashed my commits.
Add a name method to `MissingHeader`, `InvalidHeader` and `MissingCookie` that allow access to their internal name field. This is useful when recovering from rejections and down-casting to return specific replies for cases where additional information should be sent to the client.
29c717a
to
e664ebd
Compare
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.
Perfect!
Add a name method to
MissingHeader
,InvalidHeader
andMissingCookie
that allow access to their internal name field. This isuseful when recovering from rejections and down-casting to return
specific replies for cases where additional information should be sent
to the client.
Resolves #440