mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
api/server/httputils: move WriteJSON() together with ReadJSON()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
0c9ff0b45a
commit
ff5f70e55f
2 changed files with 9 additions and 15 deletions
|
@ -86,6 +86,15 @@ func ReadJSON(r *http.Request, out interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteJSON writes the value v to the http response stream as json with standard json encoding.
|
||||||
|
func WriteJSON(w http.ResponseWriter, code int, v interface{}) error {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(code)
|
||||||
|
enc := json.NewEncoder(w)
|
||||||
|
enc.SetEscapeHTML(false)
|
||||||
|
return enc.Encode(v)
|
||||||
|
}
|
||||||
|
|
||||||
// ParseForm ensures the request form is parsed even with invalid content types.
|
// ParseForm ensures the request form is parsed even with invalid content types.
|
||||||
// If we don't do this, POST method without Content-type (even with empty body) will fail.
|
// If we don't do this, POST method without Content-type (even with empty body) will fail.
|
||||||
func ParseForm(r *http.Request) error {
|
func ParseForm(r *http.Request) error {
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
package httputils // import "github.com/docker/docker/api/server/httputils"
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
// WriteJSON writes the value v to the http response stream as json with standard json encoding.
|
|
||||||
func WriteJSON(w http.ResponseWriter, code int, v interface{}) error {
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(code)
|
|
||||||
enc := json.NewEncoder(w)
|
|
||||||
enc.SetEscapeHTML(false)
|
|
||||||
return enc.Encode(v)
|
|
||||||
}
|
|
Loading…
Reference in a new issue