Skip to content

Conversation

@unbyte
Copy link
Contributor

@unbyte unbyte commented Aug 22, 2020

What it solves

Currently if enable RedirectTrailingSlash or RedirectFixedPath, gin will skip any global middlewares and redirect directly. It leads to some problems. For example, recording the path that caused the redirection (logger), adding some external headers to response (handler), or even rewrite target path.

Feature

  • call global middlewares before auto redirection

  • add AutoRedirect API on engine to set handlers used before auto redirection. It's like NoMethod and NoRoute, and will be called just before redirect.

may related: #1004 , #2458
close #2458

@codecov
Copy link

codecov bot commented Aug 22, 2020

Codecov Report

Merging #2477 (51ef7a6) into master (d062a6a) will increase coverage by 0.13%.
The diff coverage is 100.00%.

❗ Current head 51ef7a6 differs from pull request most recent head 5f94d6f. Consider uploading reports for the commit 5f94d6f to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2477      +/-   ##
==========================================
+ Coverage   98.60%   98.73%   +0.13%     
==========================================
  Files          41       41              
  Lines        3084     3088       +4     
==========================================
+ Hits         3041     3049       +8     
+ Misses         30       27       -3     
+ Partials       13       12       -1     
Flag Coverage Δ
go-1.13 98.73% <100.00%> (∅)
go-1.14 98.57% <100.00%> (∅)
go-1.15 98.57% <100.00%> (∅)
go-1.16 98.57% <100.00%> (-0.04%) ⬇️
go-1.17 98.47% <100.00%> (-0.04%) ⬇️
macos-latest 98.73% <100.00%> (+0.13%) ⬆️
nomsgpack 98.71% <100.00%> (+0.13%) ⬆️
ubuntu-latest 98.73% <100.00%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
gin.go 99.13% <100.00%> (-0.04%) ⬇️
context.go 97.81% <0.00%> (-0.09%) ⬇️
tree.go 100.00% <0.00%> (ø)
debug.go 100.00% <0.00%> (+8.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d062a6a...5f94d6f. Read the comment docs.

@unbyte
Copy link
Contributor Author

unbyte commented Aug 22, 2020

@thinkerou PTAL, I think this feature will be very helpful, but I don't know if there is still something to consider when adding such feature ❤

@knusbaum
Copy link

👍
I'm hitting this problem too.
I'm not able to attach headers to outgoing redirects since the middleware does handle those at the moment.

@betabandido
Copy link

betabandido commented Feb 18, 2021

Right now gin-contrib/cors middleware fails to work when a redirect occurs (due to RedirectTrailingSlash). But, it seems to me that being a same-domain redirect, gin (together with the CORS middleware) should support this use case. Is there any reason not to?

@giancarlosisasi
Copy link

👀

@thinkerou thinkerou requested review from appleboy and thinkerou April 15, 2021 01:50
@appleboy appleboy added this to the v1.8 milestone Apr 21, 2021
daheige
daheige previously approved these changes May 1, 2021
@unbyte
Copy link
Contributor Author

unbyte commented Nov 2, 2021

@appleboy Hi, I have updated this PR to adapt to the latest master branch.

Sadly we have encountered the problem this PR solved again recently😥. When could it be merged?

schmitzdenis
schmitzdenis previously approved these changes Dec 15, 2021
@Arekusei
Copy link

any updates?

@appleboy
Copy link
Member

@unbyte Please fix the conflicts.

@unbyte
Copy link
Contributor Author

unbyte commented Dec 28, 2021

@appleboy fixed.

@dungmv
Copy link

dungmv commented May 11, 2022

any updates

@thinkerou thinkerou modified the milestones: v1.8, v1.9 May 28, 2022
@thinkerou thinkerou modified the milestones: v1.9, v1.10 Jan 17, 2023
@appleboy appleboy modified the milestones: v1.10, v1.11 Mar 21, 2024
@WhaleFell
Copy link

any updates?

@userwerk
Copy link

userwerk commented May 6, 2025

We are running into the same issue. Any chance this will make it into the next release @appleboy?

@appleboy appleboy modified the milestones: v1.11, v1.12 Jun 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

307 Temporary Redirect - CORS header ‘Access-Control-Allow-Origin’ missing