parseContentLength trims whitespace from s and returns -1 if no value is set, or the value if it's >= 0. This a modified version of same function found in net/http/transfer.go. This one just ignores an invalid header.
(cl string)
| 263 | // This a modified version of same function found in net/http/transfer.go. This |
| 264 | // one just ignores an invalid header. |
| 265 | func parseContentLength(cl string) int64 { |
| 266 | cl = textproto.TrimString(cl) |
| 267 | if cl == "" { |
| 268 | return -1 |
| 269 | } |
| 270 | n, err := strconv.ParseUint(cl, 10, 63) |
| 271 | if err != nil { |
| 272 | return -1 |
| 273 | } |
| 274 | return int64(n) |
| 275 | } |