Commit 7573da7e authored by Jeromy's avatar Jeromy

some commenting

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent 13bf48e4
...@@ -242,6 +242,8 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error ...@@ -242,6 +242,8 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
return res, nil return res, nil
} }
// read json objects off of the given stream, and write the objects out to
// the 'out' channel
func readStreamedJson(req cmds.Request, httpRes *http.Response, out chan<- interface{}) { func readStreamedJson(req cmds.Request, httpRes *http.Response, out chan<- interface{}) {
defer close(out) defer close(out)
dec := json.NewDecoder(&httpResponseReader{httpRes}) dec := json.NewDecoder(&httpResponseReader{httpRes})
...@@ -270,6 +272,8 @@ func readStreamedJson(req cmds.Request, httpRes *http.Response, out chan<- inter ...@@ -270,6 +272,8 @@ func readStreamedJson(req cmds.Request, httpRes *http.Response, out chan<- inter
} }
} }
// decode a value of the given type, if the type is nil, attempt to decode into
// an interface{} anyways
func decodeTypedVal(t reflect.Type, dec *json.Decoder) (interface{}, error) { func decodeTypedVal(t reflect.Type, dec *json.Decoder) (interface{}, error) {
var v interface{} var v interface{}
var err error var err error
...@@ -283,6 +287,9 @@ func decodeTypedVal(t reflect.Type, dec *json.Decoder) (interface{}, error) { ...@@ -283,6 +287,9 @@ func decodeTypedVal(t reflect.Type, dec *json.Decoder) (interface{}, error) {
return v, err return v, err
} }
// httpResponseReader reads from the response body, and checks for an error
// in the http trailer upon EOF, this error if present is returned instead
// of the EOF.
type httpResponseReader struct { type httpResponseReader struct {
resp *http.Response resp *http.Response
} }
......
...@@ -193,6 +193,7 @@ func sendResponse(w http.ResponseWriter, req cmds.Request, res cmds.Response) { ...@@ -193,6 +193,7 @@ func sendResponse(w http.ResponseWriter, req cmds.Request, res cmds.Response) {
mime = applicationJson mime = applicationJson
} }
} }
if mime != "" { if mime != "" {
h.Set(contentTypeHeader, mime) h.Set(contentTypeHeader, mime)
} }
...@@ -207,6 +208,7 @@ func sendResponse(w http.ResponseWriter, req cmds.Request, res cmds.Response) { ...@@ -207,6 +208,7 @@ func sendResponse(w http.ResponseWriter, req cmds.Request, res cmds.Response) {
// Copies from an io.Reader to a http.ResponseWriter. // Copies from an io.Reader to a http.ResponseWriter.
// Flushes chunks over HTTP stream as they are read (if supported by transport). // Flushes chunks over HTTP stream as they are read (if supported by transport).
func copyChunks(status int, w http.ResponseWriter, out io.Reader) error { func copyChunks(status int, w http.ResponseWriter, out io.Reader) error {
// hijack the connection so we can write our own chunked output and trailers
hijacker, ok := w.(http.Hijacker) hijacker, ok := w.(http.Hijacker)
if !ok { if !ok {
log.Error("Failed to create hijacker! cannot continue!") log.Error("Failed to create hijacker! cannot continue!")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment