mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-04 03:27:23 -05:00 
			
		
		
		
	Refactored rewrite middleware to return errors
This commit is contained in:
		
							parent
							
								
									c657948824
								
							
						
					
					
						commit
						878ae7ea89
					
				@ -28,15 +28,16 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
 | 
				
			|||||||
		rewrites = append(rewrites, rule)
 | 
							rewrites = append(rewrites, rule)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return func(next http.HandlerFunc) http.HandlerFunc {
 | 
						// TODO: Why can't we just return an http.Handler here instead?
 | 
				
			||||||
		return func(w http.ResponseWriter, r *http.Request) {
 | 
						return func(next middleware.HandlerFunc) middleware.HandlerFunc {
 | 
				
			||||||
 | 
							return func(w http.ResponseWriter, r *http.Request) (int, error) {
 | 
				
			||||||
			for _, rule := range rewrites {
 | 
								for _, rule := range rewrites {
 | 
				
			||||||
				if r.URL.Path == rule.From {
 | 
									if r.URL.Path == rule.From {
 | 
				
			||||||
					r.URL.Path = rule.To
 | 
										r.URL.Path = rule.To
 | 
				
			||||||
					break
 | 
										break
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			next(w, r)
 | 
								return next(w, r)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}, nil
 | 
						}, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user