-
Notifications
You must be signed in to change notification settings - Fork 73
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 permanent-redirect and permanent-redirect-code annotations #165
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #165 +/- ##
==========================================
+ Coverage 42.19% 43.68% +1.49%
==========================================
Files 12 17 +5
Lines 365 515 +150
==========================================
+ Hits 154 225 +71
- Misses 210 289 +79
Partials 1 1 ☔ View full report in Codecov by Sentry. |
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.
Hey @Xinayder, thanks for your contribution!
I added some comments, let me know if you agree and eventually if I can help 😄
@Xinayder what do you think to change a bit approach here? I made a few research and having a
|
PS: test are failing, I think tests do not reflect the code changes made in 660815b |
@mavimo I was actually thinking of submitting a new PR including the temporal redirect but now I think it should be included in this one. Regarding the behavior, how do we want to proceed? Keep Caddy compatibility or try to make it compatible with Nginx? In Nginx they check if the custom code falls between the 300-308 range, if it doesn't, the code is set to the default, which is the 301 : https://github.com/kubernetes/ingress-nginx/blob/7f723c59855e82614582ff7b2efd1783b1afc2ee/internal/ingress/annotations/redirect/redirect.go#L129 EDIT: I think our approach is fine. According to MDN, status codes 300-399 are redirection messages. |
I've added the Other things I wanted to ask:
|
@Xinayder you're doing an amazing job! IMHO we can avoid to create a custom error and to do domain validation (people may decide to use internal domain as redirect and is very hard to predict what is going to be allowed or not). Eventually can be iterated in the future, WDYT? |
I think it's idiomatic to have custom error types in this case (correct me if I'm wrong). wrt validating URLs, you're right, validation would be a pain to setup to consider every possible case. |
Agree, but as part of internals we can add them later as they are not BC. BTW, when you think can be reviewed plz mark the PR as "Ready for review" and I'll try to take a look ASAP. |
@Xinayder thanks for your contribution! 🙌 |
This PR adds 2 new annotations:
permanent-redirect
permanent-redirect-code
permanent-redirect
will build astatic_response
handler for Caddy, redirecting requests to the value of the annotation field.permanent-redirect-code
can be used to set custom HTTP codes for the redirect. It supports Caddy's values likepermanent
ortemporary
. If this annotation is not set, it defaults to 301.Test results
Without
permanent-redirect-code
With
permanent-redirect-code
set to 308