381 if (m_recv_all_headers) {
382 m_recv_all_headers =
false;
383 m_recv_status_line =
false;
386 if (!m_recv_status_line) {
387 m_recv_status_line =
true;
389 std::stringstream ss(header_line);
392 m_resp_protocol = item;
395 m_status_code = std::stol(item);
399 if (m_status_code < 100 || m_status_code >= 600) {
403 auto cr_loc = item.find(
'\r');
404 if (cr_loc != std::string::npos) {
405 m_resp_message = item.substr(0, cr_loc);
407 m_resp_message = item;
412 if (header_line.empty() || header_line ==
"\n" || header_line ==
"\r\n") {
413 m_recv_all_headers =
true;
417 auto found = header_line.find(
":");
418 if (found == std::string::npos) {
422 std::string header_name = header_line.substr(0, found);
428 while (found < header_line.size()) {
429 if (header_line[found] !=
' ') {
break;}
432 std::string header_value = header_line.substr(found);
435 header_value.erase(header_value.find_last_not_of(
" \r\n\t") + 1);
439 auto iter = m_headers.find(header_name);
440 if (iter == m_headers.end()) {
441 m_headers.insert(iter, {header_name, {header_value}});
443 iter->second.push_back(header_value);
446 if (header_name ==
"Allow") {
447 std::string_view val(header_value);
448 while (!val.empty()) {
449 auto found = val.find(
',');
450 auto method = val.substr(0, found);
451 if (method ==
"PROPFIND") {
455 if (found == std::string_view::npos)
break;
456 val = val.substr(found + 1);
461 }
else if (header_name ==
"Last-Modified") {
463 if (strptime(header_value.c_str(),
"%a, %d %b %Y %H:%M:%S", &tm) !=
nullptr) {
464 m_modtime = timegm(&tm);
466 }
else if (header_name ==
"Content-Length") {
468 m_content_length = std::stoll(header_value);
473 else if (header_name ==
"Content-Type") {
474 std::string_view val(header_value);
475 auto found = val.find(
";");
476 auto first_type = val.substr(0, found);
477 m_multipart_byteranges = first_type ==
"multipart/byteranges";
478 if (m_multipart_byteranges) {
479 auto remainder = val.substr(found + 1);
480 found = remainder.find(
"boundary=");
481 if (found != std::string_view::npos) {
486 else if (header_name ==
"Content-Range") {
487 auto found = header_value.find(
" ");
488 if (found == std::string::npos) {
491 std::string range_unit = header_value.substr(0, found);
492 if (range_unit !=
"bytes") {
495 auto range_resp = header_value.substr(found + 1);
496 found = range_resp.find(
"/");
497 if (found == std::string::npos) {
500 auto incl_range = range_resp.substr(0, found);
501 found = incl_range.find(
"-");
502 if (found == std::string::npos) {
505 auto first_pos = incl_range.substr(0, found);
507 m_response_offset = std::stoll(first_pos);
511 auto last_pos = incl_range.substr(found + 1);
514 last_byte = std::stoll(last_pos);
518 m_content_length = last_byte - m_response_offset + 1;
520 else if (header_name ==
"Location") {
521 m_location = header_value;
522 }
else if (header_name ==
"Digest") {
525 else if (header_name ==
"Etag")
529 m_etag = header_value;
530 m_etag.erase(remove(m_etag.begin(), m_etag.end(),
'\"'), m_etag.end());
532 else if (header_name ==
"Cache-Control")
534 m_cache_control = header_value;
void getline(uchar *buff, int blen)