parseContentLength checks that the header is valid and then trims whitespace. It returns -1 if no value is set otherwise the value if it's >= 0.
(clHeaders []string)
| 949 | // whitespace. It returns -1 if no value is set otherwise the value |
| 950 | // if it's >= 0. |
| 951 | func parseContentLength(clHeaders []string) (int64, error) { |
| 952 | if len(clHeaders) == 0 { |
| 953 | return -1, nil |
| 954 | } |
| 955 | cl := textproto.TrimString(clHeaders[0]) |
| 956 | |
| 957 | // The Content-Length must be a valid numeric value. |
| 958 | // See: https://datatracker.ietf.org/doc/html/rfc2616/#section-14.13 |
| 959 | if cl == "" { |
| 960 | if httplaxContentLength.Value() == "1" { |
| 961 | httplaxContentLength.IncNonDefault() |
| 962 | return -1, nil |
| 963 | } |
| 964 | return 0, badStringError("invalid empty Content-Length", cl) |
| 965 | } |
| 966 | n, err := strconv.ParseUint(cl, 10, 63) |
| 967 | if err != nil { |
| 968 | return 0, badStringError("bad Content-Length", cl) |
| 969 | } |
| 970 | return int64(n), nil |
| 971 | } |
| 972 | |
| 973 | // finishAsyncByteRead finishes reading the 1-byte sniff |
| 974 | // from the ContentLength==0, Body!=nil case. |
no test coverage detected
searching dependent graphs…