- 
                Notifications
    
You must be signed in to change notification settings  - Fork 8.5k
 
make middlewares work before auto redirection #2477
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
base: master
Are you sure you want to change the base?
Conversation
          Codecov Report
 
 @@            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     
 Flags with carried forward coverage won't be shown. Click here to find out more. 
 Continue to review full report at Codecov. 
  | 
    
| 
           @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 ❤  | 
    
| 
           👍  | 
    
| 
           Right now gin-contrib/cors middleware fails to work when a redirect occurs (due to   | 
    
| 
           👀  | 
    
| 
           @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?  | 
    
| 
           any updates?  | 
    
| 
           @unbyte Please fix the conflicts.  | 
    
| 
           @appleboy fixed.  | 
    
| 
           any updates  | 
    
| 
           any updates?  | 
    
| 
           We are running into the same issue. Any chance this will make it into the next release @appleboy?  | 
    
What it solves
Currently if enable
RedirectTrailingSlashorRedirectFixedPath, 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
AutoRedirectAPI on engine to set handlers used before auto redirection. It's likeNoMethodandNoRoute, and will be called just before redirect.may related: #1004 , #2458
close #2458