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 redirectStatus function #402

Merged
merged 1 commit into from
Jul 19, 2024
Merged

Conversation

hackeryarn
Copy link
Contributor

This addresses issue #401.

I decided to go with a new function redirectStatus. Doing this makes the addition a non breaking change.

@ocramz
Copy link
Collaborator

ocramz commented Jun 11, 2024

Thank you @hackeryarn , much appreciate the non breaking change. Will look at this asap.

Copy link
Collaborator

@ocramz ocramz left a comment

Choose a reason for hiding this comment

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

I think letting users redirect with an arbitrary status code is too powerful overall.

-- OR
--
-- > redirectStatus status303 "/foo/bar"
redirectStatus :: (Monad m) => Status -> T.Text -> ActionT m a
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not constrained enough: one could redirect with a 200 or whatever, which would not make much sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that running a check here and throwing the exception would create a bad user experience. It might be nicer to have a specific ‘redirectX’ functions for each status code, with the bare ‘redirect’ remaining as the 302 version. But that would require quite a few new functions.

@ocramz what are your thoughts on a path forward?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@hackeryarn The error codes for redirect are not even that many: 300-307, 307, 308 https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages

I think overall providing them as individual functions would make for more solid API design (e.g redirect301, redirect302 etc.). WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That’s the direction I was leaning to, just wanted to make sure it wouldn’t clutter the API too much.

I’ll get this updated with the new functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ocramz This should do it. I skipped codes 305 and 306 since they are both deprecated. I also moved all the redirects to their own docs section, that way it's easier for users to find everything they are looking for.

@hackeryarn hackeryarn requested a review from ocramz June 16, 2024 20:05
Copy link
Collaborator

@ocramz ocramz left a comment

Choose a reason for hiding this comment

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

I like it! Thank you :)

redirect = E.throw . AERedirect
redirect = redirect302

-- | Redirect to given URL with status 300. Like throwing
Copy link
Collaborator

@ocramz ocramz Jun 25, 2024

Choose a reason for hiding this comment

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

Perhaps you could add the description string to the status codes in the docstring? e.g. 300 (Multiple choices), 301 (Moved permanently) etc? For those who don't know all status codes by heart.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea @ocramz! Updated all the doc strings.

@hackeryarn hackeryarn requested a review from ocramz June 28, 2024 21:44
Copy link
Collaborator

@ocramz ocramz left a comment

Choose a reason for hiding this comment

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

Very good, thank you!

Last thing, could you please add a Changelog entry describing your changes?

@hackeryarn
Copy link
Contributor Author

Thanks for all the reviews @ocramz. Changelog is updated and this is ready.

@hackeryarn hackeryarn requested a review from ocramz July 17, 2024 23:41
Copy link
Collaborator

@ocramz ocramz left a comment

Choose a reason for hiding this comment

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

👍

@ocramz ocramz merged commit 68009a0 into scotty-web:master Jul 19, 2024
7 checks passed
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.

2 participants