Skip to content
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

Merged
merged 1 commit into from Feb 19, 2020

Conversation

johnchildren
Copy link
Contributor

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.

Resolves #440

@johnchildren johnchildren force-pushed the reject-name-method branch 2 times, most recently from 3315d41 to 9d06cd2 Compare February 17, 2020 09:43
Copy link
Collaborator

@jxs jxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Owner

@seanmonstar seanmonstar left a 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 {
Copy link
Owner

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.

Copy link
Contributor Author

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!

Copy link
Owner

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 {.

Copy link
Contributor Author

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.
Copy link
Owner

@seanmonstar seanmonstar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!

@seanmonstar seanmonstar merged commit c58f12b into seanmonstar:master Feb 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose private fields on standard rejects
3 participants