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 Response::redirect #435

Merged
merged 1 commit into from
Apr 22, 2020
Merged

Conversation

jbr
Copy link
Member

@jbr jbr commented Apr 17, 2020

The Redirect endpoint is a special case ("always redirect") of the broader need to conditionally redirect based on some logic within a route handler. This PR moves the creation of a temporary redirect into Response and uses that in the Redirect endpoint. Accidentally, this also eliminates a string clone, since set_header only needs a &str.

@prabirshrestha
Copy link

Might be better to have redirect_permanent and redirect_temporary to be explicit?

@jbr
Copy link
Member Author

jbr commented Apr 18, 2020

Agreed, and that also seems like a distinction the Redirect endpoint will want to make eventually. I tried to keep the changes small and focused in this PR, but will happily add a second fn. Also considered a second argument with an enum or boolean, but that seems ungainly

@@ -53,6 +53,12 @@ impl Response {
}
}

/// Creates a response that represents a temporary redirect to `location`.
Copy link
Member

Choose a reason for hiding this comment

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

Could we add an example here?

@yoshuawuyts
Copy link
Member

@jbr I like what you're going for with this PR. I think following @prabirshrestha's suggestion to implement both versions might just be easiest; Tide is still in a place where we can issue breaking changes frequently so if we know which API we want, we can implement it.

So my understanding is this would be:

fn redirect_permanent;
fn redirect_temporary;

impl Response {
    fn redirect_permanent;
    fn redirect_temporary;
}

I wonder if it would make sense to shorten the suffix here:

fn redirect_perm;
fn redirect_temp;

impl Response {
    fn redirect_perm;
    fn redirect_temp;
}

@jbr jbr force-pushed the add_response_redirect branch 2 times, most recently from 3bb1910 to 869be5b Compare April 20, 2020 19:45
and use it in the Redirect endpoint
@jbr
Copy link
Member Author

jbr commented Apr 21, 2020

Addressed:

  • Added redirect_perm
  • Renamed redirect to redirect_temp
  • Added [hopefully] relatively realistic examples for each

Not [yet] addressed in this PR: Making the same change to the Redirect endpoint / adding a permanent redirect endpoint

Copy link
Member

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

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

This is great; thanks heaps!

@yoshuawuyts yoshuawuyts merged commit dd596a8 into http-rs:master Apr 22, 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.

None yet

3 participants