MCPcopy Index your code
hub / github.com/imroc/req / parseContentLength

Function parseContentLength

transfer.go:951–971  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

949// whitespace. It returns -1 if no value is set otherwise the value
950// if it's >= 0.
951func 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.

Callers 2

readTransferFunction · 0.85
fixLengthFunction · 0.85

Calls 3

badStringErrorFunction · 0.85
IncNonDefaultMethod · 0.80
ValueMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…