server/http: Use Response as Reader instead of manually getting output data
Matt Bell committed
Oct 22, 2014 at 17:48 UTC
12b0ebff7dbd32497916c669fa1f90e40baa28d4
1 file changed
+4
-21
server/http/http.go
+4
-21
@@ -112,27 +112,10 @@ func (i *apiHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
112
}
113
}
114
115
- val := res.Value()
116
-
117
- // if the output value is a io.Reader, stream its output in the request body
118
- if stream, ok := val.(io.Reader); ok {
119
- io.Copy(w, stream)
120
- return
121
- }
122
-
123
- // otherwise, marshall and output the response value or error
124
- if val != nil || res.Error() != nil {
125
- output, err := res.Marshal()
126
-
127
- if err != nil {
128
- w.WriteHeader(http.StatusInternalServerError)
129
- fmt.Println(err)
130
- return
131
- }
132
-
133
- if output != nil {
134
- w.Write(output)
135
- }
115
+ _, err = io.Copy(w, res)
116
+ if err != nil {
117
+ w.WriteHeader(http.StatusInternalServerError)
118
+ w.Write([]byte(err.Error()))
119
}
120
}
121