|
@ -7,6 +7,7 @@ import ( |
|
|
"fmt" |
|
|
"fmt" |
|
|
"net/http" |
|
|
"net/http" |
|
|
"net/url" |
|
|
"net/url" |
|
|
|
|
|
"strconv" |
|
|
"time" |
|
|
"time" |
|
|
|
|
|
|
|
|
"google.golang.org/grpc" |
|
|
"google.golang.org/grpc" |
|
@ -76,13 +77,19 @@ func getRESTErrorResponse(err APIError, resource string) RESTErrorResponse { |
|
|
|
|
|
|
|
|
func writeResponse(w http.ResponseWriter, statusCode int, response []byte, mType mimeType) { |
|
|
func writeResponse(w http.ResponseWriter, statusCode int, response []byte, mType mimeType) { |
|
|
setCommonHeaders(w) |
|
|
setCommonHeaders(w) |
|
|
|
|
|
if response != nil { |
|
|
|
|
|
w.Header().Set("Content-Length", strconv.Itoa(len(response))) |
|
|
|
|
|
} |
|
|
if mType != mimeNone { |
|
|
if mType != mimeNone { |
|
|
w.Header().Set("Content-Type", string(mType)) |
|
|
w.Header().Set("Content-Type", string(mType)) |
|
|
} |
|
|
} |
|
|
w.WriteHeader(statusCode) |
|
|
w.WriteHeader(statusCode) |
|
|
if response != nil { |
|
|
if response != nil { |
|
|
glog.V(4).Infof("status %d %s: %s", statusCode, mType, string(response)) |
|
|
glog.V(4).Infof("status %d %s: %s", statusCode, mType, string(response)) |
|
|
w.Write(response) |
|
|
|
|
|
|
|
|
_, err := w.Write(response) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
glog.V(0).Infof("write err: %v", err) |
|
|
|
|
|
} |
|
|
w.(http.Flusher).Flush() |
|
|
w.(http.Flusher).Flush() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|