| OLD | NEW |
| 1 package httputils | 1 package httputils |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "bytes" | 4 "bytes" |
| 5 "fmt" | 5 "fmt" |
| 6 "io" | 6 "io" |
| 7 "io/ioutil" | 7 "io/ioutil" |
| 8 "net" | 8 "net" |
| 9 "net/http" | 9 "net/http" |
| 10 "net/url" | 10 "net/url" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 if err := backoff.RetryNotify(roundTripOp, backOffClient, notifyFunc); e
rr != nil { | 161 if err := backoff.RetryNotify(roundTripOp, backOffClient, notifyFunc); e
rr != nil { |
| 162 return nil, fmt.Errorf("HTTP request failed inspite of exponenti
al backoff: %s", err) | 162 return nil, fmt.Errorf("HTTP request failed inspite of exponenti
al backoff: %s", err) |
| 163 } | 163 } |
| 164 return resp, nil | 164 return resp, nil |
| 165 } | 165 } |
| 166 | 166 |
| 167 // TODO(stephana): Remove 'r' from the argument list since it's not used. It wou
ld | 167 // TODO(stephana): Remove 'r' from the argument list since it's not used. It wou
ld |
| 168 // be also useful if we could specify a return status explicitly. | 168 // be also useful if we could specify a return status explicitly. |
| 169 | 169 |
| 170 // ReportError formats an HTTP error response and also logs the detailed error m
essage. | 170 // ReportError formats an HTTP error response and also logs the detailed error m
essage. |
| 171 // The message parameter is returned in the HTTP response. If it is not provided
then |
| 172 // "Unknown error" will be returned instead. |
| 171 func ReportError(w http.ResponseWriter, r *http.Request, err error, message stri
ng) { | 173 func ReportError(w http.ResponseWriter, r *http.Request, err error, message stri
ng) { |
| 172 glog.Errorln(message, err) | 174 glog.Errorln(message, err) |
| 173 if err != io.ErrClosedPipe { | 175 if err != io.ErrClosedPipe { |
| 174 » » http.Error(w, message, 500) | 176 » » httpErrMsg := message |
| 177 » » if message == "" { |
| 178 » » » httpErrMsg = "Unknown error" |
| 179 » » } |
| 180 » » http.Error(w, httpErrMsg, 500) |
| 175 } | 181 } |
| 176 } | 182 } |
| 177 | 183 |
| 178 // responseProxy implements http.ResponseWriter and records the status codes. | 184 // responseProxy implements http.ResponseWriter and records the status codes. |
| 179 type responseProxy struct { | 185 type responseProxy struct { |
| 180 http.ResponseWriter | 186 http.ResponseWriter |
| 181 wroteHeader bool | 187 wroteHeader bool |
| 182 } | 188 } |
| 183 | 189 |
| 184 func (rp *responseProxy) WriteHeader(code int) { | 190 func (rp *responseProxy) WriteHeader(code int) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 val, err = strconv.Atoi(valStr) | 273 val, err = strconv.Atoi(valStr) |
| 268 if err != nil { | 274 if err != nil { |
| 269 return 0, fmt.Errorf("Not a valid integer value.") | 275 return 0, fmt.Errorf("Not a valid integer value.") |
| 270 } | 276 } |
| 271 } | 277 } |
| 272 if val < 0 { | 278 if val < 0 { |
| 273 return defaultVal, nil | 279 return defaultVal, nil |
| 274 } | 280 } |
| 275 return val, nil | 281 return val, nil |
| 276 } | 282 } |
| OLD | NEW |