Merge pull request #65788 from tallclair/errors
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Cleanup apiserver errors - delete unused methods (is this safe, or might they be used in another project outside kubernetes/kubernetes?) - use the standard library `http.Error` function (functional change adds a newline) ```release-note NONE ``` /sig api-machinery /kind cleanup Kubernetes-commit: 30e4f528ed30a70bdb0c14b5cfe49d00a78194c2
This commit is contained in:
		
						commit
						3465165a50
					
				|  | @ -32,14 +32,6 @@ import ( | |||
| // Avoid emitting errors that look like valid HTML. Quotes are okay.
 | ||||
| var sanitizer = strings.NewReplacer(`&`, "&", `<`, "<", `>`, ">") | ||||
| 
 | ||||
| // BadGatewayError renders a simple bad gateway error.
 | ||||
| func BadGatewayError(w http.ResponseWriter, req *http.Request) { | ||||
| 	w.Header().Set("Content-Type", "text/plain") | ||||
| 	w.Header().Set("X-Content-Type-Options", "nosniff") | ||||
| 	w.WriteHeader(http.StatusBadGateway) | ||||
| 	fmt.Fprintf(w, "Bad Gateway: %q", sanitizer.Replace(req.RequestURI)) | ||||
| } | ||||
| 
 | ||||
| // Forbidden renders a simple forbidden error
 | ||||
| func Forbidden(ctx context.Context, attributes authorizer.Attributes, w http.ResponseWriter, req *http.Request, reason string, s runtime.NegotiatedSerializer) { | ||||
| 	msg := sanitizer.Replace(forbiddenMessage(attributes)) | ||||
|  | @ -80,15 +72,7 @@ func forbiddenMessage(attributes authorizer.Attributes) string { | |||
| 
 | ||||
| // InternalError renders a simple internal error
 | ||||
| func InternalError(w http.ResponseWriter, req *http.Request, err error) { | ||||
| 	w.Header().Set("Content-Type", "text/plain") | ||||
| 	w.Header().Set("X-Content-Type-Options", "nosniff") | ||||
| 	w.WriteHeader(http.StatusInternalServerError) | ||||
| 	fmt.Fprintf(w, "Internal Server Error: %q: %v", sanitizer.Replace(req.RequestURI), err) | ||||
| 	http.Error(w, sanitizer.Replace(fmt.Sprintf("Internal Server Error: %q: %v", req.RequestURI, err)), | ||||
| 		http.StatusInternalServerError) | ||||
| 	utilruntime.HandleError(err) | ||||
| } | ||||
| 
 | ||||
| // NotFound renders a simple not found error.
 | ||||
| func NotFound(w http.ResponseWriter, req *http.Request) { | ||||
| 	w.WriteHeader(http.StatusNotFound) | ||||
| 	fmt.Fprintf(w, "Not Found: %q", sanitizer.Replace(req.RequestURI)) | ||||
| } | ||||
|  |  | |||
|  | @ -32,8 +32,6 @@ import ( | |||
| func TestErrors(t *testing.T) { | ||||
| 	internalError := errors.New("ARGH") | ||||
| 	fns := map[string]func(http.ResponseWriter, *http.Request){ | ||||
| 		"BadGatewayError": BadGatewayError, | ||||
| 		"NotFound":        NotFound, | ||||
| 		"InternalError": func(w http.ResponseWriter, req *http.Request) { | ||||
| 			InternalError(w, req, internalError) | ||||
| 		}, | ||||
|  | @ -43,12 +41,8 @@ func TestErrors(t *testing.T) { | |||
| 		uri      string | ||||
| 		expected string | ||||
| 	}{ | ||||
| 		{"BadGatewayError", "/get", `Bad Gateway: "/get"`}, | ||||
| 		{"BadGatewayError", "/<script>", `Bad Gateway: "/<script>"`}, | ||||
| 		{"NotFound", "/get", `Not Found: "/get"`}, | ||||
| 		{"NotFound", "/<script&>", `Not Found: "/<script&>"`}, | ||||
| 		{"InternalError", "/get", `Internal Server Error: "/get": ARGH`}, | ||||
| 		{"InternalError", "/<script>", `Internal Server Error: "/<script>": ARGH`}, | ||||
| 		{"InternalError", "/get", "Internal Server Error: \"/get\": ARGH\n"}, | ||||
| 		{"InternalError", "/<script>", "Internal Server Error: \"/<script>\": ARGH\n"}, | ||||
| 	} | ||||
| 	for _, test := range cases { | ||||
| 		observer := httptest.NewRecorder() | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue