зеркало из https://github.com/Azure/ARO-RP.git
Коммит
6919874cee
|
@ -13,14 +13,16 @@ func Body(h http.Handler) http.Handler {
|
|||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodPatch, http.MethodPost, http.MethodPut:
|
||||
if strings.SplitN(r.Header.Get("Content-Type"), ";", 2)[0] != "application/json" {
|
||||
api.WriteError(w, http.StatusUnsupportedMediaType, api.CloudErrorCodeUnsupportedMediaType, "", "The content media type '%s' is not supported. Only 'application/json' is supported.", r.Header.Get("Content-Type"))
|
||||
body, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, 1048576))
|
||||
if err != nil {
|
||||
api.WriteError(w, http.StatusBadRequest, api.CloudErrorCodeInvalidResource, "", "The resource definition is invalid.")
|
||||
return
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, 1048576))
|
||||
if err != nil {
|
||||
api.WriteError(w, http.StatusUnsupportedMediaType, api.CloudErrorCodeInvalidResource, "", "The resource definition is invalid.")
|
||||
contentType := strings.SplitN(r.Header.Get("Content-Type"), ";", 2)[0]
|
||||
|
||||
if contentType != "application/json" && !(len(body) == 0 && contentType == "") {
|
||||
api.WriteError(w, http.StatusUnsupportedMediaType, api.CloudErrorCodeUnsupportedMediaType, "", "The content media type '%s' is not supported. Only 'application/json' is supported.", r.Header.Get("Content-Type"))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ func (f *frontend) postOpenShiftClusterCredentials(w http.ResponseWriter, r *htt
|
|||
vars := mux.Vars(r)
|
||||
|
||||
body := r.Context().Value(middleware.ContextKeyBody).([]byte)
|
||||
if !json.Valid(body) {
|
||||
if len(body) > 0 && !json.Valid(body) {
|
||||
api.WriteError(w, http.StatusBadRequest, api.CloudErrorCodeInvalidRequestContent, "", "The request content was invalid and could not be deserialized.")
|
||||
return
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче