| 58 | } |
| 59 | |
| 60 | int64_t |
| 61 | contentLengthFrom(HttpHeader const &header) |
| 62 | { |
| 63 | int64_t bytes = 0; |
| 64 | |
| 65 | char constr[1024]; |
| 66 | int conlen = sizeof(constr); |
| 67 | |
| 68 | // look for expected Content-Length field |
| 69 | bool const hasContentLength(header.valueForKey(TS_MIME_FIELD_CONTENT_LENGTH, TS_MIME_LEN_CONTENT_LENGTH, constr, &conlen)); |
| 70 | |
| 71 | if (!hasContentLength) { |
| 72 | DEBUG_LOG("invalid response header, no Content-Length"); |
| 73 | bytes = INT64_MAX; |
| 74 | } else { |
| 75 | // ensure null termination |
| 76 | constr[conlen] = '\0'; |
| 77 | char *endptr = nullptr; |
| 78 | bytes = std::max(static_cast<int64_t>(0), static_cast<int64_t>(strtoll(constr, &endptr, 10))); |
| 79 | } |
| 80 | |
| 81 | return bytes; |
| 82 | } |
| 83 | |
| 84 | // Also reference server header |
| 85 | enum HeaderState { |
no test coverage detected