| 186 | } |
| 187 | |
| 188 | func decodeTimeout(s string) (time.Duration, error) { |
| 189 | size := len(s) |
| 190 | if size < 2 { |
| 191 | return 0, fmt.Errorf("transport: timeout string is too short: %q", s) |
| 192 | } |
| 193 | if size > 9 { |
| 194 | // Spec allows for 8 digits plus the unit. |
| 195 | return 0, fmt.Errorf("transport: timeout string is too long: %q", s) |
| 196 | } |
| 197 | unit := timeoutUnit(s[size-1]) |
| 198 | d, ok := timeoutUnitToDuration(unit) |
| 199 | if !ok { |
| 200 | return 0, fmt.Errorf("transport: timeout unit is not recognized: %q", s) |
| 201 | } |
| 202 | t, err := strconv.ParseUint(s[:size-1], 10, 64) |
| 203 | if err != nil { |
| 204 | return 0, err |
| 205 | } |
| 206 | const maxHours = math.MaxInt64 / uint64(time.Hour) |
| 207 | if d == time.Hour && t > maxHours { |
| 208 | // This timeout would overflow math.MaxInt64; clamp it. |
| 209 | return time.Duration(math.MaxInt64), nil |
| 210 | } |
| 211 | return d * time.Duration(t), nil |
| 212 | } |
| 213 | |
| 214 | const ( |
| 215 | spaceByte = ' ' |