Merge branch 'develop'
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
commit
1eaf6cc454
@ -3,7 +3,7 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@ -55,9 +55,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func decodeRequestData(r *http.Request, v interface{}) error {
|
func decodeRequestData(r *http.Request, v interface{}) error {
|
||||||
buf, _ := ioutil.ReadAll(r.Body)
|
buf, _ := io.ReadAll(r.Body)
|
||||||
rdr := ioutil.NopCloser(bytes.NewReader(buf))
|
rdr := io.NopCloser(bytes.NewReader(buf))
|
||||||
r.Body = ioutil.NopCloser(bytes.NewReader(buf))
|
r.Body = io.NopCloser(bytes.NewReader(buf))
|
||||||
|
|
||||||
json.NewDecoder(rdr).Decode(&v)
|
json.NewDecoder(rdr).Decode(&v)
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package app
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -63,8 +63,8 @@ func PrepareHeadersMiddleware(next http.Handler) http.Handler {
|
|||||||
|
|
||||||
func ValidateJsonBodyMiddleware(next http.Handler) http.Handler {
|
func ValidateJsonBodyMiddleware(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
buf, _ := ioutil.ReadAll(r.Body)
|
buf, _ := io.ReadAll(r.Body)
|
||||||
r.Body = ioutil.NopCloser(bytes.NewReader(buf)) // rollack *Request to original state
|
r.Body = io.NopCloser(bytes.NewReader(buf)) // rollack *Request to original state
|
||||||
|
|
||||||
if len(buf) > 0 && !json.Valid(buf) {
|
if len(buf) > 0 && !json.Valid(buf) {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
Loading…
Reference in New Issue
Block a user