mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Introduce go chi web framework as frontend of macaron, so that we can move routes from macaron to chi step by step (#7420)
* When route cannot be found on chi, go to macaron * Stick chi version to 1.5.0 * Follow router log setting
This commit is contained in:
		
							
								
								
									
										51
									
								
								vendor/github.com/go-chi/chi/middleware/content_charset.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								vendor/github.com/go-chi/chi/middleware/content_charset.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,51 @@ | ||||
| package middleware | ||||
|  | ||||
| import ( | ||||
| 	"net/http" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| // ContentCharset generates a handler that writes a 415 Unsupported Media Type response if none of the charsets match. | ||||
| // An empty charset will allow requests with no Content-Type header or no specified charset. | ||||
| func ContentCharset(charsets ...string) func(next http.Handler) http.Handler { | ||||
| 	for i, c := range charsets { | ||||
| 		charsets[i] = strings.ToLower(c) | ||||
| 	} | ||||
|  | ||||
| 	return func(next http.Handler) http.Handler { | ||||
| 		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||||
| 			if !contentEncoding(r.Header.Get("Content-Type"), charsets...) { | ||||
| 				w.WriteHeader(http.StatusUnsupportedMediaType) | ||||
| 				return | ||||
| 			} | ||||
|  | ||||
| 			next.ServeHTTP(w, r) | ||||
| 		}) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // Check the content encoding against a list of acceptable values. | ||||
| func contentEncoding(ce string, charsets ...string) bool { | ||||
| 	_, ce = split(strings.ToLower(ce), ";") | ||||
| 	_, ce = split(ce, "charset=") | ||||
| 	ce, _ = split(ce, ";") | ||||
| 	for _, c := range charsets { | ||||
| 		if ce == c { | ||||
| 			return true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| // Split a string in two parts, cleaning any whitespace. | ||||
| func split(str, sep string) (string, string) { | ||||
| 	var a, b string | ||||
| 	var parts = strings.SplitN(str, sep, 2) | ||||
| 	a = strings.TrimSpace(parts[0]) | ||||
| 	if len(parts) == 2 { | ||||
| 		b = strings.TrimSpace(parts[1]) | ||||
| 	} | ||||
|  | ||||
| 	return a, b | ||||
| } | ||||
		Reference in New Issue
	
	Block a user