mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-03 19:17:29 -05:00 
			
		
		
		
	caddyhttp: Default to error status if found in context
This is just a convenience if using a static_response handler in an error route, by setting the default status code to the same one as the error status.
This commit is contained in:
		
							parent
							
								
									2d1f7b9da8
								
							
						
					
					
						commit
						7b0962ba4d
					
				@ -121,8 +121,16 @@ func (s StaticResponse) ServeHTTP(w http.ResponseWriter, r *http.Request, _ Hand
 | 
				
			|||||||
		w.Header()["Content-Type"] = nil
 | 
							w.Header()["Content-Type"] = nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// get the status code
 | 
						// get the status code; if this handler exists in an error route,
 | 
				
			||||||
 | 
						// use the recommended status code as the default; otherwise 200
 | 
				
			||||||
	statusCode := http.StatusOK
 | 
						statusCode := http.StatusOK
 | 
				
			||||||
 | 
						if reqErr, ok := r.Context().Value(ErrorCtxKey).(error); ok {
 | 
				
			||||||
 | 
							if handlerErr, ok := reqErr.(HandlerError); ok {
 | 
				
			||||||
 | 
								if handlerErr.StatusCode > 0 {
 | 
				
			||||||
 | 
									statusCode = handlerErr.StatusCode
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if codeStr := s.StatusCode.String(); codeStr != "" {
 | 
						if codeStr := s.StatusCode.String(); codeStr != "" {
 | 
				
			||||||
		intVal, err := strconv.Atoi(repl.ReplaceAll(codeStr, ""))
 | 
							intVal, err := strconv.Atoi(repl.ReplaceAll(codeStr, ""))
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user