Skip to content

Commit

Permalink
fixing undetected content type with charset
Browse files Browse the repository at this point in the history
  • Loading branch information
Dodi Triwibowo committed Jun 29, 2020
1 parent d26a665 commit a0a6e9a
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ func PlugRequest(r *http.Request, w http.ResponseWriter) *Request {
case http.MethodGet,http.MethodPut,http.MethodPost,http.MethodDelete,http.MethodPatch:{
contentType := req.header.Get("Content-Type")
if strings.Contains(contentType, "multipart/form-data") {
contentType = "multipart/form-data"
}
switch contentType {
case "multipart/form-data":{
if r.Method == http.MethodGet {
return req
}
Expand All @@ -68,9 +64,7 @@ func PlugRequest(r *http.Request, w http.ResponseWriter) *Request {
for k, v := range r.MultipartForm.File {
req.files[k] = scanFiles(v)
}
break
}
case "application/x-www-form-urlencoded":{
}else if strings.Contains(contentType, "application/x-www-form-urlencoded"){
if r.Method == http.MethodGet {
return req
}
Expand All @@ -82,18 +76,14 @@ func PlugRequest(r *http.Request, w http.ResponseWriter) *Request {
for k, v := range r.PostForm {
req.params[k] = scan(v)
}
break
}
case "application/json":{
}else if strings.Contains(contentType, "application/json") {
dec := json.NewDecoder(r.Body)

err := dec.Decode(&req.params)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return req
}
break
}
}
break
}
Expand Down Expand Up @@ -121,9 +111,6 @@ func TouchRequest(r *http.Request, w http.ResponseWriter) *Request {
switch r.Method {
case http.MethodGet,http.MethodPut,http.MethodPost,http.MethodDelete,http.MethodPatch:{
contentType := req.header.Get("Content-Type")
if strings.Contains(contentType, "multipart/form-data") {
contentType = "multipart/form-data"
}
if strings.Contains(contentType, "multipart/form-data"){
if r.Method == http.MethodGet {
return req
Expand Down

0 comments on commit a0a6e9a

Please sign in to comment.