| 972 | } |
| 973 | |
| 974 | bool SC::HttpClientResponse::getNextHeader(HttpClientResponseHeaderIterator& iterator, HttpClientHeader& header) const |
| 975 | { |
| 976 | const size_t readableHeaders = headersLength <= headers.sizeInBytes() ? headersLength : headers.sizeInBytes(); |
| 977 | const Span<const char> allHeaders = {headers.data(), readableHeaders}; |
| 978 | |
| 979 | header = {}; |
| 980 | |
| 981 | while (iterator.offset < allHeaders.sizeInBytes()) |
| 982 | { |
| 983 | size_t lineEnd = iterator.offset; |
| 984 | while (lineEnd < allHeaders.sizeInBytes()) |
| 985 | { |
| 986 | if (allHeaders[lineEnd] == '\r' and (lineEnd + 1) < allHeaders.sizeInBytes() and |
| 987 | allHeaders[lineEnd + 1] == '\n') |
| 988 | { |
| 989 | break; |
| 990 | } |
| 991 | lineEnd += 1; |
| 992 | } |
| 993 | |
| 994 | const Span<const char> line = {allHeaders.data() + iterator.offset, lineEnd - iterator.offset}; |
| 995 | iterator.offset = lineEnd; |
| 996 | if ((iterator.offset + 1) < allHeaders.sizeInBytes() and allHeaders[iterator.offset] == '\r' and |
| 997 | allHeaders[iterator.offset + 1] == '\n') |
| 998 | { |
| 999 | iterator.offset += 2; |
| 1000 | } |
| 1001 | |
| 1002 | if (line.sizeInBytes() == 0) |
| 1003 | { |
| 1004 | continue; |
| 1005 | } |
| 1006 | |
| 1007 | size_t separator = 0; |
| 1008 | while (separator < line.sizeInBytes() and line[separator] != ':') |
| 1009 | { |
| 1010 | separator += 1; |
| 1011 | } |
| 1012 | if (separator < line.sizeInBytes()) |
| 1013 | { |
| 1014 | const StringSpan headerName = trimAsciiWhiteSpace({line.data(), separator}); |
| 1015 | const StringSpan headerValue = |
| 1016 | trimAsciiWhiteSpace({line.data() + separator + 1, line.sizeInBytes() - separator - 1}); |
| 1017 | if (headerName.sizeInBytes() > 0) |
| 1018 | { |
| 1019 | header.name = headerName; |
| 1020 | header.value = headerValue; |
| 1021 | return true; |
| 1022 | } |
| 1023 | } |
| 1024 | } |
| 1025 | return false; |
| 1026 | } |
| 1027 | |
| 1028 | bool SC::HttpClientResponse::getContentLength(uint64_t& value) const |
| 1029 | { |