| OLD | NEW |
| 1 package util | 1 package util |
| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 return resp, nil | 157 return resp, nil |
| 158 } | 158 } |
| 159 | 159 |
| 160 // TODO(stephana): Remove 'r' from the argument list since it's not used. It wou
ld | 160 // TODO(stephana): Remove 'r' from the argument list since it's not used. It wou
ld |
| 161 // be also useful if we could specify a return status explicitly. | 161 // be also useful if we could specify a return status explicitly. |
| 162 | 162 |
| 163 // ReportError formats an HTTP error response and also logs the detailed error m
essage. | 163 // ReportError formats an HTTP error response and also logs the detailed error m
essage. |
| 164 func ReportError(w http.ResponseWriter, r *http.Request, err error, message stri
ng) { | 164 func ReportError(w http.ResponseWriter, r *http.Request, err error, message stri
ng) { |
| 165 glog.Errorln(message, err) | 165 glog.Errorln(message, err) |
| 166 if err != io.ErrClosedPipe { | 166 if err != io.ErrClosedPipe { |
| 167 » » http.Error(w, fmt.Sprintf("%s %s", message, err), 500) | 167 » » http.Error(w, message, 500) |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 // responseProxy implements http.ResponseWriter and records the status codes. | 171 // responseProxy implements http.ResponseWriter and records the status codes. |
| 172 type responseProxy struct { | 172 type responseProxy struct { |
| 173 http.ResponseWriter | 173 http.ResponseWriter |
| 174 wroteHeader bool | 174 wroteHeader bool |
| 175 } | 175 } |
| 176 | 176 |
| 177 func (rp *responseProxy) WriteHeader(code int) { | 177 func (rp *responseProxy) WriteHeader(code int) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 val, err = strconv.Atoi(valStr) | 260 val, err = strconv.Atoi(valStr) |
| 261 if err != nil { | 261 if err != nil { |
| 262 return 0, fmt.Errorf("Not a valid integer value.") | 262 return 0, fmt.Errorf("Not a valid integer value.") |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 if val < 0 { | 265 if val < 0 { |
| 266 return defaultVal, nil | 266 return defaultVal, nil |
| 267 } | 267 } |
| 268 return val, nil | 268 return val, nil |
| 269 } | 269 } |
| OLD | NEW |