Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,15 @@ inline int get_header_value_int(const Headers &headers, const char *key,
return def;
}

inline unsigned long long get_header_value_uint64(const Headers &headers, const char *key,
int def = 0) {
auto it = headers.find(key);
if (it != headers.end()) {
return std::strtoull(it->second.data(), nullptr, 10);
}
return def;
}

inline bool read_headers(Stream &strm, Headers &headers) {
static std::regex re(R"((.+?):\s*(.+?)\s*\r\n)");

Expand Down Expand Up @@ -881,7 +890,7 @@ inline bool read_content_chunked(Stream &strm, std::string &out) {
template <typename T>
bool read_content(Stream &strm, T &x, Progress progress = Progress()) {
if (has_header(x.headers, "Content-Length")) {
auto len = get_header_value_int(x.headers, "Content-Length", 0);
auto len = get_header_value_uint64(x.headers, "Content-Length", 0);
if (len == 0) {
const auto &encoding =
get_header_value(x.headers, "Transfer-Encoding", 0, "");
Expand Down