Merge pull request #41 from mjudeikis/fix.content

Fix.content
This commit is contained in:
Jim Minter 2019-12-09 14:23:36 -06:00 коммит произвёл GitHub
Родитель 725a2cbc93 0cf85aa3e5
Коммит 6919874cee
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 8 добавлений и 6 удалений

Просмотреть файл

@ -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
}