_ZN6YaHTTP5ErrorC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE:
    9|  2.84k|    Error(const std::string& reason_): reason(reason_) {};
_ZN6YaHTTP5ErrorD2Ev:
   10|  2.84k|    virtual ~Error() throw() {};
_ZN6YaHTTP10ParseErrorC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE:
   22|  2.84k|    ParseError(const std::string& reason_): Error(reason_) {};

_ZN6YaHTTP7isspaceEc:
   11|  1.95M|  bool isspace(char c) {
   12|  1.95M|    return std::isspace(c) != 0;
   13|  1.95M|  }
_ZN6YaHTTP7isspaceEcRKNSt3__16localeE:
   15|  25.3k|  bool isspace(char c, const std::locale& loc) {
   16|  25.3k|    return std::isspace(c, loc);
   17|  25.3k|  }
_ZN6YaHTTP11AsyncLoaderINS_8ResponseEE4feedERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEE:
   45|  3.66k|  {
   46|  3.66k|    if (state < 2) {
  ------------------
  |  Branch (46:9): [True: 3.66k, False: 0]
  ------------------
   47|  3.66k|      headersize += somedata.length(); // maybe include some body data, we don't know yet...
   48|  3.66k|      if (headersize > target->max_header_size) {
  ------------------
  |  Branch (48:11): [True: 45, False: 3.61k]
  ------------------
   49|     45|        if (target->kind == YAHTTP_TYPE_REQUEST) {
  ------------------
  |  |   39|     45|#define YAHTTP_TYPE_REQUEST 1
  ------------------
  |  Branch (49:13): [True: 0, False: 45]
  ------------------
   50|      0|          throw ParseError("Request header too large");
   51|      0|        }
   52|     45|        else {
   53|     45|          throw ParseError("Response header too large");
   54|     45|        }
   55|     45|      }
   56|  3.66k|    }
   57|  3.61k|    buffer.append(somedata);
   58|  3.61k|    size_t cursor = 0;
   59|  25.7k|    while(state < 2) {
  ------------------
  |  Branch (59:11): [True: 25.7k, False: 0]
  ------------------
   60|  25.7k|      int cr=0;
   61|  25.7k|      size_t pos = buffer.find_first_of("\n", cursor); // NOLINT(performance-faster-string-find)
   62|       |      // need to find CRLF in buffer
   63|  25.7k|      if (pos == std::string::npos) {
  ------------------
  |  Branch (63:11): [True: 838, False: 24.9k]
  ------------------
   64|       |        // Remove all the data which has been consumed as header.
   65|    838|        if (cursor != 0) {
  ------------------
  |  Branch (65:13): [True: 820, False: 18]
  ------------------
   66|    820|          buffer.erase(buffer.begin(), buffer.begin() + cursor); // NOLINT(bugprone-narrowing-conversions, cppcoreguidelines-narrowing-conversions)
   67|    820|        }
   68|    838|        return false;
   69|    838|      }
   70|  24.9k|      if (pos>0 && buffer[pos-1]=='\r') {
  ------------------
  |  Branch (70:11): [True: 23.1k, False: 1.75k]
  |  Branch (70:20): [True: 212, False: 22.9k]
  ------------------
   71|    212|        cr=1;
   72|    212|      }
   73|  24.9k|      std::string_view line(buffer.data() + cursor, (pos - cr) - cursor); // exclude CRLF // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
   74|  24.9k|      cursor = pos + 1; // skip line, including CRLF
   75|  24.9k|      if (state == 0) { // startup line
  ------------------
  |  Branch (75:11): [True: 3.59k, False: 21.3k]
  ------------------
   76|  3.59k|        if (target->kind == YAHTTP_TYPE_REQUEST) {
  ------------------
  |  |   39|  3.59k|#define YAHTTP_TYPE_REQUEST 1
  ------------------
  |  Branch (76:13): [True: 0, False: 3.59k]
  ------------------
   77|      0|          std::string ver;
   78|      0|          std::string tmpurl;
   79|      0|          std::istringstream iss{std::string(line)};
   80|      0|          iss >> target->method >> tmpurl >> ver;
   81|      0|          if (ver.size() == 0)
  ------------------
  |  Branch (81:15): [True: 0, False: 0]
  ------------------
   82|      0|            target->version = 9;
   83|      0|          else if (ver.find("HTTP/0.9") == 0)
  ------------------
  |  Branch (83:20): [True: 0, False: 0]
  ------------------
   84|      0|            target->version = 9;
   85|      0|          else if (ver.find("HTTP/1.0") == 0)
  ------------------
  |  Branch (85:20): [True: 0, False: 0]
  ------------------
   86|      0|            target->version = 10;
   87|      0|          else if (ver.find("HTTP/1.1") == 0)
  ------------------
  |  Branch (87:20): [True: 0, False: 0]
  ------------------
   88|      0|            target->version = 11;
   89|      0|          else
   90|      0|            throw ParseError("HTTP version not supported");
   91|       |          // uppercase the target method
   92|      0|          std::transform(target->method.begin(), target->method.end(), target->method.begin(), ::toupper);
   93|      0|          target->url.parse(tmpurl);
   94|      0|          target->getvars = Utility::parseUrlParameters(target->url.parameters);
   95|      0|          state = 1;
   96|  3.59k|        } else if(target->kind == YAHTTP_TYPE_RESPONSE) {
  ------------------
  |  |   40|  3.59k|#define YAHTTP_TYPE_RESPONSE 2
  ------------------
  |  Branch (96:19): [True: 3.59k, False: 0]
  ------------------
   97|  3.59k|          std::string ver;
   98|  3.59k|          std::istringstream iss{std::string(line)};
   99|  3.59k|          std::string::size_type pos1;
  100|  3.59k|          iss >> ver >> target->status;
  101|  3.59k|          std::getline(iss, target->statusText);
  102|  3.59k|          pos1=0;
  103|  3.60k|          while(pos1 < target->statusText.size() && YaHTTP::isspace(target->statusText.at(pos1))) pos1++;
  ------------------
  |  Branch (103:17): [True: 16, False: 3.58k]
  |  Branch (103:53): [True: 6, False: 10]
  ------------------
  104|  3.59k|          target->statusText = target->statusText.substr(pos1); 
  105|  3.59k|          if ((pos1 = target->statusText.find("\r")) != std::string::npos) {
  ------------------
  |  Branch (105:15): [True: 0, False: 3.59k]
  ------------------
  106|      0|            target->statusText = target->statusText.substr(0, pos1-1);
  107|      0|          }
  108|  3.59k|          if (ver.size() == 0) {
  ------------------
  |  Branch (108:15): [True: 1.76k, False: 1.83k]
  ------------------
  109|  1.76k|            target->version = 9;
  110|  1.83k|          } else if (ver.find("HTTP/0.9") == 0)
  ------------------
  |  Branch (110:22): [True: 0, False: 1.83k]
  ------------------
  111|      0|            target->version = 9;
  112|  1.83k|          else if (ver.find("HTTP/1.0") == 0)
  ------------------
  |  Branch (112:20): [True: 0, False: 1.83k]
  ------------------
  113|      0|            target->version = 10;
  114|  1.83k|          else if (ver.find("HTTP/1.1") == 0)
  ------------------
  |  Branch (114:20): [True: 0, False: 1.83k]
  ------------------
  115|      0|            target->version = 11;
  116|  1.83k|          else
  117|  1.83k|            throw ParseError("HTTP version not supported");
  118|  1.76k|          state = 1;
  119|  1.76k|        }
  120|  21.3k|      } else if (state == 1) {
  ------------------
  |  Branch (120:18): [True: 21.3k, False: 0]
  ------------------
  121|  21.3k|        std::string key,value;
  122|  21.3k|        size_t pos1;
  123|  21.3k|        if (line.empty()) {
  ------------------
  |  Branch (123:13): [True: 933, False: 20.3k]
  ------------------
  124|    933|          chunked = (target->headers.find("transfer-encoding") != target->headers.end() && target->headers["transfer-encoding"] == "chunked");
  ------------------
  |  Branch (124:22): [True: 448, False: 485]
  |  Branch (124:92): [True: 409, False: 39]
  ------------------
  125|    933|          state = 2;
  126|    933|          break;
  127|    933|        }
  128|       |        // give up if there are too many header lines - this shouldn't happen in legitimate traffic
  129|  20.3k|        ++headerlines;
  130|  20.3k|        if (headerlines > YAHTTP_MAX_HEADER_LINES) {
  ------------------
  |  |   28|  20.3k|#define YAHTTP_MAX_HEADER_LINES 1000
  ------------------
  |  Branch (130:13): [True: 1, False: 20.3k]
  ------------------
  131|      1|          throw ParseError("Too many headers");
  132|      1|        }
  133|       |        // split headers
  134|  20.3k|        if ((pos1 = line.find(':')) == std::string::npos) {
  ------------------
  |  Branch (134:13): [True: 3, False: 20.3k]
  ------------------
  135|      3|          throw ParseError("Malformed header line");
  136|      3|        }
  137|  20.3k|        key = line.substr(0, pos1);
  138|  20.3k|        value = line.substr(pos1 + 1);
  139|   981k|        for(std::string::iterator it=key.begin(); it != key.end(); it++)
  ------------------
  |  Branch (139:51): [True: 961k, False: 20.3k]
  ------------------
  140|   961k|          if (YaHTTP::isspace(*it))
  ------------------
  |  Branch (140:15): [True: 10, False: 961k]
  ------------------
  141|     10|            throw ParseError("Header key contains whitespace which is not allowed by RFC");
  142|       |
  143|  20.3k|        Utility::trim(value);
  144|  20.3k|        std::transform(key.begin(), key.end(), key.begin(), ::tolower);
  145|       |        // is it already defined
  146|       |
  147|  20.3k|        if (key == "set-cookie" && target->kind == YAHTTP_TYPE_RESPONSE) {
  ------------------
  |  |   40|     77|#define YAHTTP_TYPE_RESPONSE 2
  ------------------
  |  Branch (147:13): [True: 77, False: 20.3k]
  |  Branch (147:36): [True: 77, False: 0]
  ------------------
  148|       |          // Nothing (intentional).
  149|  20.3k|        } else if (key == "cookie" && target->kind == YAHTTP_TYPE_REQUEST) {
  ------------------
  |  |   39|    745|#define YAHTTP_TYPE_REQUEST 1
  ------------------
  |  Branch (149:20): [True: 745, False: 19.5k]
  |  Branch (149:39): [True: 0, False: 745]
  ------------------
  150|       |          // Nothing (intentional).
  151|  20.3k|        } else {
  152|  20.3k|          if (key == "host" && target->kind == YAHTTP_TYPE_REQUEST) {
  ------------------
  |  |   39|  1.87k|#define YAHTTP_TYPE_REQUEST 1
  ------------------
  |  Branch (152:15): [True: 1.87k, False: 18.4k]
  |  Branch (152:32): [True: 0, False: 1.87k]
  ------------------
  153|       |            // maybe it contains port?
  154|      0|            if ((pos1 = value.find(':')) == std::string::npos) {
  ------------------
  |  Branch (154:17): [True: 0, False: 0]
  ------------------
  155|      0|              target->url.host = value;
  156|      0|            } else {
  157|      0|              target->url.host = value.substr(0, pos1);
  158|      0|              target->url.port = ::atoi(value.substr(pos1).c_str());
  159|      0|            }
  160|      0|          }
  161|  20.3k|          if (target->headers.find(key) != target->headers.end()) {
  ------------------
  |  Branch (161:15): [True: 14.0k, False: 6.20k]
  ------------------
  162|  14.0k|            target->headers[key] = target->headers[key] + ";" + value;
  163|  14.0k|          } else {
  164|  6.20k|            target->headers[key] = std::move(value);
  165|  6.20k|          }
  166|  20.3k|        }
  167|  20.3k|      }
  168|  24.9k|    }
  169|       |    // Remove all the data which has been consumed as header.
  170|    933|    if (cursor != 0) {
  ------------------
  |  Branch (170:9): [True: 933, False: 0]
  ------------------
  171|       |      // Release memory as soon as we can
  172|    933|      if (cursor == buffer.length()) {
  ------------------
  |  Branch (172:11): [True: 377, False: 556]
  ------------------
  173|    377|        buffer.clear();
  174|    377|        cursor = 0;
  175|    377|      }
  176|    556|      else {
  177|    556|        buffer.erase(buffer.begin(), buffer.begin() + cursor); // NOLINT(bugprone-narrowing-conversions, cppcoreguidelines-narrowing-conversions)
  178|    556|      }
  179|    933|    }
  180|       |
  181|    933|    minbody = 0;
  182|       |    // check for expected body size
  183|    933|    if (target->kind == YAHTTP_TYPE_REQUEST) maxbody = target->max_request_size;
  ------------------
  |  |   39|    933|#define YAHTTP_TYPE_REQUEST 1
  ------------------
  |  Branch (183:9): [True: 0, False: 933]
  ------------------
  184|    933|    else if (target->kind == YAHTTP_TYPE_RESPONSE) maxbody = target->max_response_size;
  ------------------
  |  |   40|    933|#define YAHTTP_TYPE_RESPONSE 2
  ------------------
  |  Branch (184:14): [True: 933, False: 0]
  ------------------
  185|      0|    else maxbody = 0;
  186|       |
  187|    933|    if (!chunked) {
  ------------------
  |  Branch (187:9): [True: 524, False: 409]
  ------------------
  188|    524|      if (target->headers.find("content-length") != target->headers.end()) {
  ------------------
  |  Branch (188:11): [True: 305, False: 219]
  ------------------
  189|    305|        std::istringstream maxbodyS(target->headers["content-length"]);
  190|    305|        maxbodyS >> minbody;
  191|    305|        maxbody = minbody;
  192|    305|      }
  193|    524|      if (minbody < 1) return true; // guess there isn't anything left.
  ------------------
  |  Branch (193:11): [True: 227, False: 297]
  ------------------
  194|    297|      if (target->kind == YAHTTP_TYPE_REQUEST && minbody > target->max_request_size) throw ParseError("Max request body size exceeded");
  ------------------
  |  |   39|    594|#define YAHTTP_TYPE_REQUEST 1
  ------------------
  |  Branch (194:11): [True: 0, False: 297]
  |  Branch (194:50): [True: 0, False: 0]
  ------------------
  195|    297|      else if (target->kind == YAHTTP_TYPE_RESPONSE && minbody > target->max_response_size) throw ParseError("Max response body size exceeded");
  ------------------
  |  |   40|    594|#define YAHTTP_TYPE_RESPONSE 2
  ------------------
  |  Branch (195:16): [True: 297, False: 0]
  |  Branch (195:56): [True: 139, False: 158]
  ------------------
  196|    297|    }
  197|       |
  198|    567|    if (maxbody == 0) hasBody = false;
  ------------------
  |  Branch (198:9): [True: 0, False: 567]
  ------------------
  199|    567|    else hasBody = true;
  200|       |
  201|    567|    if (buffer.size() == 0) return ready();
  ------------------
  |  Branch (201:9): [True: 24, False: 543]
  ------------------
  202|       |
  203|  4.16k|    while(buffer.size() > 0) {
  ------------------
  |  Branch (203:11): [True: 3.99k, False: 169]
  ------------------
  204|  3.99k|      if (chunked) {
  ------------------
  |  Branch (204:11): [True: 3.86k, False: 136]
  ------------------
  205|  3.86k|        if (chunk_size == 0) {
  ------------------
  |  Branch (205:13): [True: 2.07k, False: 1.78k]
  ------------------
  206|  2.07k|          char buf[100];
  207|       |          // read chunk length
  208|  2.07k|          size_t pos = buffer.find('\n');
  209|  2.07k|          if (pos == std::string::npos) {
  ------------------
  |  Branch (209:15): [True: 31, False: 2.04k]
  ------------------
  210|     31|            if (buffer.size() > 99) {
  ------------------
  |  Branch (210:17): [True: 10, False: 21]
  ------------------
  211|     10|              throw ParseError("Nonsensical chunk_size");
  212|     10|            }
  213|     21|            return false;
  214|     31|          }
  215|  2.04k|          if (pos > 99)
  ------------------
  |  Branch (215:15): [True: 27, False: 2.01k]
  ------------------
  216|     27|            throw ParseError("Impossible chunk_size");
  217|  2.01k|          buffer.copy(buf, pos);
  218|  2.01k|          buf[pos]=0; // just in case...
  219|  2.01k|          buffer.erase(buffer.begin(), buffer.begin()+pos+1); // remove line from buffer
  220|  2.01k|          if (sscanf(buf, "%zx", &chunk_size) != 1) {
  ------------------
  |  Branch (220:15): [True: 22, False: 1.99k]
  ------------------
  221|     22|            throw ParseError("Unable to parse chunk size");
  222|     22|          }
  223|  1.99k|          if (chunk_size == 0) { state = 3; break; } // last chunk
  ------------------
  |  Branch (223:15): [True: 6, False: 1.99k]
  ------------------
  224|  1.99k|          if (chunk_size > (std::numeric_limits<decltype(chunk_size)>::max() - 2) || chunk_size > maxbody) {
  ------------------
  |  Branch (224:15): [True: 1, False: 1.98k]
  |  Branch (224:86): [True: 171, False: 1.81k]
  ------------------
  225|    172|            throw ParseError("Chunk is too large");
  226|    172|          }
  227|  1.99k|        } else {
  228|  1.78k|          int crlf=1;
  229|  1.78k|          if (buffer.size() < chunk_size + 1) {
  ------------------
  |  Branch (229:15): [True: 31, False: 1.75k]
  ------------------
  230|     31|            return false; // expecting \n or \r\n at chunk_size, but we're not there yet.
  231|     31|          }
  232|  1.75k|          switch (buffer.at(chunk_size)) {
  233|  1.48k|          case '\n':
  ------------------
  |  Branch (233:11): [True: 1.48k, False: 273]
  ------------------
  234|       |            // Well-formed chunk
  235|  1.48k|            break;
  236|    256|          case '\r':
  ------------------
  |  Branch (236:11): [True: 256, False: 1.49k]
  ------------------
  237|    256|            if (buffer.size() < chunk_size + 2) {
  ------------------
  |  Branch (237:17): [True: 5, False: 251]
  ------------------
  238|      5|              return false; // expecting \n to follow \r, but we're not there yet.
  239|      5|            }
  240|    251|            if (buffer.at(chunk_size+1) == '\n') {
  ------------------
  |  Branch (240:17): [True: 241, False: 10]
  ------------------
  241|    241|              crlf=2;
  242|    241|              break;
  243|    241|            }
  244|     10|            [[fallthrough]];
  245|     27|          default:
  ------------------
  |  Branch (245:11): [True: 17, False: 1.73k]
  ------------------
  246|     27|            throw ParseError("Chunked body is not terminated correctly");
  247|  1.75k|          }
  248|  1.72k|          if (bodysize + chunk_size > maxbody) {
  ------------------
  |  Branch (248:15): [True: 0, False: 1.72k]
  ------------------
  249|      0|            throw ParseError("Chunked body is too large");
  250|      0|          }
  251|  1.72k|          std::string tmp = buffer.substr(0, chunk_size);
  252|  1.72k|          buffer.erase(buffer.begin(), buffer.begin()+chunk_size+crlf);
  253|  1.72k|          bodybuf << tmp;
  254|  1.72k|          bodysize += chunk_size;
  255|  1.72k|          chunk_size = 0;
  256|  1.72k|          if (buffer.size() == 0) break; // just in case
  ------------------
  |  Branch (256:15): [True: 53, False: 1.66k]
  ------------------
  257|  1.72k|        }
  258|  3.86k|      } else {
  259|    136|        if (bodysize + buffer.length() > maxbody) {
  ------------------
  |  Branch (259:13): [True: 77, False: 59]
  ------------------
  260|     77|          bodybuf << buffer.substr(0, maxbody - bodybuf.str().length());
  261|     77|          bodysize = maxbody;
  262|     77|        }
  263|     59|        else {
  264|     59|          bodybuf << buffer;
  265|     59|          bodysize += buffer.length();
  266|     59|        }
  267|    136|        buffer.clear();
  268|    136|      }
  269|  3.99k|    }
  270|       |
  271|    228|    if (chunk_size!=0) return false; // need more data
  ------------------
  |  Branch (271:9): [True: 33, False: 195]
  ------------------
  272|       |
  273|    195|    return ready();
  274|    228|  };
_ZN6YaHTTP11AsyncLoaderINS_7RequestEE4feedERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEE:
   45|  3.66k|  {
   46|  3.66k|    if (state < 2) {
  ------------------
  |  Branch (46:9): [True: 3.66k, False: 0]
  ------------------
   47|  3.66k|      headersize += somedata.length(); // maybe include some body data, we don't know yet...
   48|  3.66k|      if (headersize > target->max_header_size) {
  ------------------
  |  Branch (48:11): [True: 45, False: 3.61k]
  ------------------
   49|     45|        if (target->kind == YAHTTP_TYPE_REQUEST) {
  ------------------
  |  |   39|     45|#define YAHTTP_TYPE_REQUEST 1
  ------------------
  |  Branch (49:13): [True: 45, False: 0]
  ------------------
   50|     45|          throw ParseError("Request header too large");
   51|     45|        }
   52|      0|        else {
   53|      0|          throw ParseError("Response header too large");
   54|      0|        }
   55|     45|      }
   56|  3.66k|    }
   57|  3.61k|    buffer.append(somedata);
   58|  3.61k|    size_t cursor = 0;
   59|  36.1k|    while(state < 2) {
  ------------------
  |  Branch (59:11): [True: 36.1k, False: 14]
  ------------------
   60|  36.1k|      int cr=0;
   61|  36.1k|      size_t pos = buffer.find_first_of("\n", cursor); // NOLINT(performance-faster-string-find)
   62|       |      // need to find CRLF in buffer
   63|  36.1k|      if (pos == std::string::npos) {
  ------------------
  |  Branch (63:11): [True: 2.46k, False: 33.6k]
  ------------------
   64|       |        // Remove all the data which has been consumed as header.
   65|  2.46k|        if (cursor != 0) {
  ------------------
  |  Branch (65:13): [True: 2.44k, False: 18]
  ------------------
   66|  2.44k|          buffer.erase(buffer.begin(), buffer.begin() + cursor); // NOLINT(bugprone-narrowing-conversions, cppcoreguidelines-narrowing-conversions)
   67|  2.44k|        }
   68|  2.46k|        return false;
   69|  2.46k|      }
   70|  33.6k|      if (pos>0 && buffer[pos-1]=='\r') {
  ------------------
  |  Branch (70:11): [True: 31.8k, False: 1.75k]
  |  Branch (70:20): [True: 212, False: 31.6k]
  ------------------
   71|    212|        cr=1;
   72|    212|      }
   73|  33.6k|      std::string_view line(buffer.data() + cursor, (pos - cr) - cursor); // exclude CRLF // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
   74|  33.6k|      cursor = pos + 1; // skip line, including CRLF
   75|  33.6k|      if (state == 0) { // startup line
  ------------------
  |  Branch (75:11): [True: 3.59k, False: 30.0k]
  ------------------
   76|  3.59k|        if (target->kind == YAHTTP_TYPE_REQUEST) {
  ------------------
  |  |   39|  3.59k|#define YAHTTP_TYPE_REQUEST 1
  ------------------
  |  Branch (76:13): [True: 3.59k, False: 0]
  ------------------
   77|  3.59k|          std::string ver;
   78|  3.59k|          std::string tmpurl;
   79|  3.59k|          std::istringstream iss{std::string(line)};
   80|  3.59k|          iss >> target->method >> tmpurl >> ver;
   81|  3.59k|          if (ver.size() == 0)
  ------------------
  |  Branch (81:15): [True: 3.50k, False: 93]
  ------------------
   82|  3.50k|            target->version = 9;
   83|     93|          else if (ver.find("HTTP/0.9") == 0)
  ------------------
  |  Branch (83:20): [True: 2, False: 91]
  ------------------
   84|      2|            target->version = 9;
   85|     91|          else if (ver.find("HTTP/1.0") == 0)
  ------------------
  |  Branch (85:20): [True: 2, False: 89]
  ------------------
   86|      2|            target->version = 10;
   87|     89|          else if (ver.find("HTTP/1.1") == 0)
  ------------------
  |  Branch (87:20): [True: 2, False: 87]
  ------------------
   88|      2|            target->version = 11;
   89|     87|          else
   90|     87|            throw ParseError("HTTP version not supported");
   91|       |          // uppercase the target method
   92|  3.51k|          std::transform(target->method.begin(), target->method.end(), target->method.begin(), ::toupper);
   93|  3.51k|          target->url.parse(tmpurl);
   94|  3.51k|          target->getvars = Utility::parseUrlParameters(target->url.parameters);
   95|  3.51k|          state = 1;
   96|  3.51k|        } else if(target->kind == YAHTTP_TYPE_RESPONSE) {
  ------------------
  |  |   40|      0|#define YAHTTP_TYPE_RESPONSE 2
  ------------------
  |  Branch (96:19): [True: 0, False: 0]
  ------------------
   97|      0|          std::string ver;
   98|      0|          std::istringstream iss{std::string(line)};
   99|      0|          std::string::size_type pos1;
  100|      0|          iss >> ver >> target->status;
  101|      0|          std::getline(iss, target->statusText);
  102|      0|          pos1=0;
  103|      0|          while(pos1 < target->statusText.size() && YaHTTP::isspace(target->statusText.at(pos1))) pos1++;
  ------------------
  |  Branch (103:17): [True: 0, False: 0]
  |  Branch (103:53): [True: 0, False: 0]
  ------------------
  104|      0|          target->statusText = target->statusText.substr(pos1); 
  105|      0|          if ((pos1 = target->statusText.find("\r")) != std::string::npos) {
  ------------------
  |  Branch (105:15): [True: 0, False: 0]
  ------------------
  106|      0|            target->statusText = target->statusText.substr(0, pos1-1);
  107|      0|          }
  108|      0|          if (ver.size() == 0) {
  ------------------
  |  Branch (108:15): [True: 0, False: 0]
  ------------------
  109|      0|            target->version = 9;
  110|      0|          } else if (ver.find("HTTP/0.9") == 0)
  ------------------
  |  Branch (110:22): [True: 0, False: 0]
  ------------------
  111|      0|            target->version = 9;
  112|      0|          else if (ver.find("HTTP/1.0") == 0)
  ------------------
  |  Branch (112:20): [True: 0, False: 0]
  ------------------
  113|      0|            target->version = 10;
  114|      0|          else if (ver.find("HTTP/1.1") == 0)
  ------------------
  |  Branch (114:20): [True: 0, False: 0]
  ------------------
  115|      0|            target->version = 11;
  116|      0|          else
  117|      0|            throw ParseError("HTTP version not supported");
  118|      0|          state = 1;
  119|      0|        }
  120|  30.0k|      } else if (state == 1) {
  ------------------
  |  Branch (120:18): [True: 30.0k, False: 0]
  ------------------
  121|  30.0k|        std::string key,value;
  122|  30.0k|        size_t pos1;
  123|  30.0k|        if (line.empty()) {
  ------------------
  |  Branch (123:13): [True: 1.03k, False: 29.0k]
  ------------------
  124|  1.03k|          chunked = (target->headers.find("transfer-encoding") != target->headers.end() && target->headers["transfer-encoding"] == "chunked");
  ------------------
  |  Branch (124:22): [True: 470, False: 563]
  |  Branch (124:92): [True: 431, False: 39]
  ------------------
  125|  1.03k|          state = 2;
  126|  1.03k|          break;
  127|  1.03k|        }
  128|       |        // give up if there are too many header lines - this shouldn't happen in legitimate traffic
  129|  29.0k|        ++headerlines;
  130|  29.0k|        if (headerlines > YAHTTP_MAX_HEADER_LINES) {
  ------------------
  |  |   28|  29.0k|#define YAHTTP_MAX_HEADER_LINES 1000
  ------------------
  |  Branch (130:13): [True: 1, False: 29.0k]
  ------------------
  131|      1|          throw ParseError("Too many headers");
  132|      1|        }
  133|       |        // split headers
  134|  29.0k|        if ((pos1 = line.find(':')) == std::string::npos) {
  ------------------
  |  Branch (134:13): [True: 9, False: 29.0k]
  ------------------
  135|      9|          throw ParseError("Malformed header line");
  136|      9|        }
  137|  29.0k|        key = line.substr(0, pos1);
  138|  29.0k|        value = line.substr(pos1 + 1);
  139|  1.02M|        for(std::string::iterator it=key.begin(); it != key.end(); it++)
  ------------------
  |  Branch (139:51): [True: 993k, False: 28.9k]
  ------------------
  140|   993k|          if (YaHTTP::isspace(*it))
  ------------------
  |  Branch (140:15): [True: 11, False: 993k]
  ------------------
  141|     11|            throw ParseError("Header key contains whitespace which is not allowed by RFC");
  142|       |
  143|  28.9k|        Utility::trim(value);
  144|  28.9k|        std::transform(key.begin(), key.end(), key.begin(), ::tolower);
  145|       |        // is it already defined
  146|       |
  147|  28.9k|        if (key == "set-cookie" && target->kind == YAHTTP_TYPE_RESPONSE) {
  ------------------
  |  |   40|    205|#define YAHTTP_TYPE_RESPONSE 2
  ------------------
  |  Branch (147:13): [True: 205, False: 28.7k]
  |  Branch (147:36): [True: 0, False: 205]
  ------------------
  148|       |          // Nothing (intentional).
  149|  28.9k|        } else if (key == "cookie" && target->kind == YAHTTP_TYPE_REQUEST) {
  ------------------
  |  |   39|    862|#define YAHTTP_TYPE_REQUEST 1
  ------------------
  |  Branch (149:20): [True: 862, False: 28.1k]
  |  Branch (149:39): [True: 862, False: 0]
  ------------------
  150|       |          // Nothing (intentional).
  151|  28.1k|        } else {
  152|  28.1k|          if (key == "host" && target->kind == YAHTTP_TYPE_REQUEST) {
  ------------------
  |  |   39|  3.42k|#define YAHTTP_TYPE_REQUEST 1
  ------------------
  |  Branch (152:15): [True: 3.42k, False: 24.7k]
  |  Branch (152:32): [True: 3.42k, False: 0]
  ------------------
  153|       |            // maybe it contains port?
  154|  3.42k|            if ((pos1 = value.find(':')) == std::string::npos) {
  ------------------
  |  Branch (154:17): [True: 503, False: 2.92k]
  ------------------
  155|    503|              target->url.host = value;
  156|  2.92k|            } else {
  157|  2.92k|              target->url.host = value.substr(0, pos1);
  158|  2.92k|              target->url.port = ::atoi(value.substr(pos1).c_str());
  159|  2.92k|            }
  160|  3.42k|          }
  161|  28.1k|          if (target->headers.find(key) != target->headers.end()) {
  ------------------
  |  Branch (161:15): [True: 16.0k, False: 12.0k]
  ------------------
  162|  16.0k|            target->headers[key] = target->headers[key] + ";" + value;
  163|  16.0k|          } else {
  164|  12.0k|            target->headers[key] = std::move(value);
  165|  12.0k|          }
  166|  28.1k|        }
  167|  28.9k|      }
  168|  33.6k|    }
  169|       |    // Remove all the data which has been consumed as header.
  170|  1.04k|    if (cursor != 0) {
  ------------------
  |  Branch (170:9): [True: 1.03k, False: 14]
  ------------------
  171|       |      // Release memory as soon as we can
  172|  1.03k|      if (cursor == buffer.length()) {
  ------------------
  |  Branch (172:11): [True: 390, False: 643]
  ------------------
  173|    390|        buffer.clear();
  174|    390|        cursor = 0;
  175|    390|      }
  176|    643|      else {
  177|    643|        buffer.erase(buffer.begin(), buffer.begin() + cursor); // NOLINT(bugprone-narrowing-conversions, cppcoreguidelines-narrowing-conversions)
  178|    643|      }
  179|  1.03k|    }
  180|       |
  181|  1.04k|    minbody = 0;
  182|       |    // check for expected body size
  183|  1.04k|    if (target->kind == YAHTTP_TYPE_REQUEST) maxbody = target->max_request_size;
  ------------------
  |  |   39|  1.04k|#define YAHTTP_TYPE_REQUEST 1
  ------------------
  |  Branch (183:9): [True: 1.03k, False: 14]
  ------------------
  184|     14|    else if (target->kind == YAHTTP_TYPE_RESPONSE) maxbody = target->max_response_size;
  ------------------
  |  |   40|     14|#define YAHTTP_TYPE_RESPONSE 2
  ------------------
  |  Branch (184:14): [True: 0, False: 14]
  ------------------
  185|     14|    else maxbody = 0;
  186|       |
  187|  1.04k|    if (!chunked) {
  ------------------
  |  Branch (187:9): [True: 602, False: 445]
  ------------------
  188|    602|      if (target->headers.find("content-length") != target->headers.end()) {
  ------------------
  |  Branch (188:11): [True: 365, False: 237]
  ------------------
  189|    365|        std::istringstream maxbodyS(target->headers["content-length"]);
  190|    365|        maxbodyS >> minbody;
  191|    365|        maxbody = minbody;
  192|    365|      }
  193|    602|      if (minbody < 1) return true; // guess there isn't anything left.
  ------------------
  |  Branch (193:11): [True: 246, False: 356]
  ------------------
  194|    356|      if (target->kind == YAHTTP_TYPE_REQUEST && minbody > target->max_request_size) throw ParseError("Max request body size exceeded");
  ------------------
  |  |   39|    712|#define YAHTTP_TYPE_REQUEST 1
  ------------------
  |  Branch (194:11): [True: 356, False: 0]
  |  Branch (194:50): [True: 141, False: 215]
  ------------------
  195|    215|      else if (target->kind == YAHTTP_TYPE_RESPONSE && minbody > target->max_response_size) throw ParseError("Max response body size exceeded");
  ------------------
  |  |   40|    430|#define YAHTTP_TYPE_RESPONSE 2
  ------------------
  |  Branch (195:16): [True: 0, False: 215]
  |  Branch (195:56): [True: 0, False: 0]
  ------------------
  196|    356|    }
  197|       |
  198|    660|    if (maxbody == 0) hasBody = false;
  ------------------
  |  Branch (198:9): [True: 0, False: 660]
  ------------------
  199|    660|    else hasBody = true;
  200|       |
  201|    660|    if (buffer.size() == 0) return ready();
  ------------------
  |  Branch (201:9): [True: 25, False: 635]
  ------------------
  202|       |
  203|  4.63k|    while(buffer.size() > 0) {
  ------------------
  |  Branch (203:11): [True: 4.39k, False: 239]
  ------------------
  204|  4.39k|      if (chunked) {
  ------------------
  |  Branch (204:11): [True: 4.20k, False: 192]
  ------------------
  205|  4.20k|        if (chunk_size == 0) {
  ------------------
  |  Branch (205:13): [True: 2.25k, False: 1.95k]
  ------------------
  206|  2.25k|          char buf[100];
  207|       |          // read chunk length
  208|  2.25k|          size_t pos = buffer.find('\n');
  209|  2.25k|          if (pos == std::string::npos) {
  ------------------
  |  Branch (209:15): [True: 34, False: 2.21k]
  ------------------
  210|     34|            if (buffer.size() > 99) {
  ------------------
  |  Branch (210:17): [True: 10, False: 24]
  ------------------
  211|     10|              throw ParseError("Nonsensical chunk_size");
  212|     10|            }
  213|     24|            return false;
  214|     34|          }
  215|  2.21k|          if (pos > 99)
  ------------------
  |  Branch (215:15): [True: 28, False: 2.18k]
  ------------------
  216|     28|            throw ParseError("Impossible chunk_size");
  217|  2.18k|          buffer.copy(buf, pos);
  218|  2.18k|          buf[pos]=0; // just in case...
  219|  2.18k|          buffer.erase(buffer.begin(), buffer.begin()+pos+1); // remove line from buffer
  220|  2.18k|          if (sscanf(buf, "%zx", &chunk_size) != 1) {
  ------------------
  |  Branch (220:15): [True: 23, False: 2.16k]
  ------------------
  221|     23|            throw ParseError("Unable to parse chunk size");
  222|     23|          }
  223|  2.16k|          if (chunk_size == 0) { state = 3; break; } // last chunk
  ------------------
  |  Branch (223:15): [True: 8, False: 2.15k]
  ------------------
  224|  2.15k|          if (chunk_size > (std::numeric_limits<decltype(chunk_size)>::max() - 2) || chunk_size > maxbody) {
  ------------------
  |  Branch (224:15): [True: 1, False: 2.15k]
  |  Branch (224:86): [True: 171, False: 1.98k]
  ------------------
  225|    172|            throw ParseError("Chunk is too large");
  226|    172|          }
  227|  2.15k|        } else {
  228|  1.95k|          int crlf=1;
  229|  1.95k|          if (buffer.size() < chunk_size + 1) {
  ------------------
  |  Branch (229:15): [True: 32, False: 1.92k]
  ------------------
  230|     32|            return false; // expecting \n or \r\n at chunk_size, but we're not there yet.
  231|     32|          }
  232|  1.92k|          switch (buffer.at(chunk_size)) {
  233|  1.63k|          case '\n':
  ------------------
  |  Branch (233:11): [True: 1.63k, False: 289]
  ------------------
  234|       |            // Well-formed chunk
  235|  1.63k|            break;
  236|    271|          case '\r':
  ------------------
  |  Branch (236:11): [True: 271, False: 1.64k]
  ------------------
  237|    271|            if (buffer.size() < chunk_size + 2) {
  ------------------
  |  Branch (237:17): [True: 5, False: 266]
  ------------------
  238|      5|              return false; // expecting \n to follow \r, but we're not there yet.
  239|      5|            }
  240|    266|            if (buffer.at(chunk_size+1) == '\n') {
  ------------------
  |  Branch (240:17): [True: 252, False: 14]
  ------------------
  241|    252|              crlf=2;
  242|    252|              break;
  243|    252|            }
  244|     14|            [[fallthrough]];
  245|     32|          default:
  ------------------
  |  Branch (245:11): [True: 18, False: 1.90k]
  ------------------
  246|     32|            throw ParseError("Chunked body is not terminated correctly");
  247|  1.92k|          }
  248|  1.88k|          if (bodysize + chunk_size > maxbody) {
  ------------------
  |  Branch (248:15): [True: 0, False: 1.88k]
  ------------------
  249|      0|            throw ParseError("Chunked body is too large");
  250|      0|          }
  251|  1.88k|          std::string tmp = buffer.substr(0, chunk_size);
  252|  1.88k|          buffer.erase(buffer.begin(), buffer.begin()+chunk_size+crlf);
  253|  1.88k|          bodybuf << tmp;
  254|  1.88k|          bodysize += chunk_size;
  255|  1.88k|          chunk_size = 0;
  256|  1.88k|          if (buffer.size() == 0) break; // just in case
  ------------------
  |  Branch (256:15): [True: 62, False: 1.82k]
  ------------------
  257|  1.88k|        }
  258|  4.20k|      } else {
  259|    192|        if (bodysize + buffer.length() > maxbody) {
  ------------------
  |  Branch (259:13): [True: 97, False: 95]
  ------------------
  260|     97|          bodybuf << buffer.substr(0, maxbody - bodybuf.str().length());
  261|     97|          bodysize = maxbody;
  262|     97|        }
  263|     95|        else {
  264|     95|          bodybuf << buffer;
  265|     95|          bodysize += buffer.length();
  266|     95|        }
  267|    192|        buffer.clear();
  268|    192|      }
  269|  4.39k|    }
  270|       |
  271|    309|    if (chunk_size!=0) return false; // need more data
  ------------------
  |  Branch (271:9): [True: 33, False: 276]
  ------------------
  272|       |
  273|    276|    return ready();
  274|    309|  };

_ZN6YaHTTP7RequestC2Ev:
  235|  3.66k|    Request() { Request::initialize(); };
_ZN6YaHTTP8HTTPBaseC2Ev:
  104|  7.32k|    HTTPBase() {
  105|  7.32k|      HTTPBase::initialize();
  106|  7.32k|    };
_ZN6YaHTTP8HTTPBase10initializeEv:
  109|  21.9k|    virtual void initialize() {
  110|  21.9k|      kind = 0;
  111|  21.9k|      status = 0;
  112|  21.9k|#ifdef HAVE_CPP_FUNC_PTR
  113|  21.9k|      renderer = SendBodyRender();
  114|  21.9k|#endif
  115|  21.9k|      max_request_size = YAHTTP_MAX_REQUEST_SIZE;
  ------------------
  |  |   32|  21.9k|#define YAHTTP_MAX_REQUEST_SIZE 2097152
  ------------------
  116|  21.9k|      max_response_size = YAHTTP_MAX_RESPONSE_SIZE;
  ------------------
  |  |   36|  21.9k|#define YAHTTP_MAX_RESPONSE_SIZE 2097152
  ------------------
  117|  21.9k|      max_header_size = YAHTTP_MAX_HEADER_SIZE;
  ------------------
  |  |   24|  21.9k|#define YAHTTP_MAX_HEADER_SIZE (100 * 1024)
  ------------------
  118|  21.9k|      url = "";
  119|  21.9k|      method = "";
  120|  21.9k|      statusText = "";
  121|  21.9k|      headers.clear();
  122|  21.9k|      parameters.clear();
  123|  21.9k|      getvars.clear();
  124|  21.9k|      postvars.clear();
  125|  21.9k|      body = "";
  126|  21.9k|      routeName = "";
  127|  21.9k|      version = 11; // default to version 1.1
  128|  21.9k|      is_multipart = false;
  129|  21.9k|    }
_ZN6YaHTTP8HTTPBase14SendBodyRenderC2Ev:
   54|  21.9k|      SendBodyRender() {};
_ZN6YaHTTP7Request10initializeEv:
  244|  7.32k|    void initialize() override {
  245|  7.32k|      HTTPBase::initialize();
  246|  7.32k|      this->kind = YAHTTP_TYPE_REQUEST;
  ------------------
  |  |   39|  7.32k|#define YAHTTP_TYPE_REQUEST 1
  ------------------
  247|  7.32k|    }
_ZN6YaHTTP8HTTPBaseD2Ev:
  107|  7.32k|    virtual ~HTTPBase() = default;
_ZN6YaHTTP8ResponseC2Ev:
  207|  3.66k|    Response() { Response::initialize(); };
_ZN6YaHTTP8Response10initializeEv:
  216|  7.32k|    void initialize() override {
  217|  7.32k|      HTTPBase::initialize();
  218|  7.32k|      this->kind = YAHTTP_TYPE_RESPONSE;
  ------------------
  |  |   40|  7.32k|#define YAHTTP_TYPE_RESPONSE 2
  ------------------
  219|  7.32k|    }
_ZN6YaHTTP11AsyncLoaderINS_7RequestEE10initializeEPS1_:
  319|  3.66k|    void initialize(T* target_) {
  320|  3.66k|      chunked = false; chunk_size = 0;
  321|  3.66k|      bodybuf.str(""); minbody = 0; maxbody = 0;
  322|  3.66k|      state = 0; this->target = target_;
  323|  3.66k|      hasBody = false;
  324|  3.66k|      buffer = "";
  325|  3.66k|      headersize = 0;
  326|  3.66k|      headerlines = 0;
  327|  3.66k|      bodysize = 0;
  328|  3.66k|      this->target->initialize();
  329|  3.66k|    }; //<! Initialize the parser for target and clear state
_ZN6YaHTTP11AsyncLoaderINS_7RequestEE8finalizeEv:
  336|    424|    void finalize() {
  337|    424|      bodybuf.flush();
  338|    424|      if (ready()) {
  ------------------
  |  Branch (338:11): [True: 424, False: 0]
  ------------------
  339|    424|        std::string body = bodybuf.str();
  340|    424|        strstr_map_t::iterator cpos = target->headers.find("content-type");
  341|    424|        if (cpos != target->headers.end() && Utility::iequals(cpos->second, "application/x-www-form-urlencoded", 32)) {
  ------------------
  |  Branch (341:13): [True: 121, False: 303]
  |  Branch (341:13): [True: 93, False: 331]
  |  Branch (341:46): [True: 93, False: 28]
  ------------------
  342|     93|          target->postvars = Utility::parseUrlParameters(body);
  343|     93|        }
  344|    424|        target->body = std::move(body);
  345|    424|      }
  346|    424|      bodybuf.str("");
  347|    424|      bodysize = 0;
  348|       |      this->target = NULL;
  349|    424|    }; //<! finalize and release target
_ZN6YaHTTP11AsyncLoaderINS_7RequestEE5readyEv:
  331|    711|    bool ready() {
  332|    711|     return (chunked == true && state == 3) || // if it's chunked we get end of data indication
  ------------------
  |  Branch (332:14): [True: 80, False: 631]
  |  Branch (332:33): [True: 16, False: 64]
  ------------------
  333|    695|             (chunked == false && state > 1 &&  
  ------------------
  |  Branch (333:15): [True: 631, False: 64]
  |  Branch (333:35): [True: 631, False: 0]
  ------------------
  334|    631|               (!hasBody || (bodysize <= maxbody && bodysize >= minbody))); 
  ------------------
  |  Branch (334:17): [True: 246, False: 385]
  |  Branch (334:30): [True: 385, False: 0]
  |  Branch (334:53): [True: 340, False: 45]
  ------------------
  335|    711|    }; //<! whether we have received enough data
_ZN6YaHTTP11AsyncLoaderINS_8ResponseEE10initializeEPS1_:
  319|  3.66k|    void initialize(T* target_) {
  320|  3.66k|      chunked = false; chunk_size = 0;
  321|  3.66k|      bodybuf.str(""); minbody = 0; maxbody = 0;
  322|  3.66k|      state = 0; this->target = target_;
  323|  3.66k|      hasBody = false;
  324|  3.66k|      buffer = "";
  325|  3.66k|      headersize = 0;
  326|  3.66k|      headerlines = 0;
  327|  3.66k|      bodysize = 0;
  328|  3.66k|      this->target->initialize();
  329|  3.66k|    }; //<! Initialize the parser for target and clear state
_ZN6YaHTTP11AsyncLoaderINS_8ResponseEE8finalizeEv:
  336|    347|    void finalize() {
  337|    347|      bodybuf.flush();
  338|    347|      if (ready()) {
  ------------------
  |  Branch (338:11): [True: 347, False: 0]
  ------------------
  339|    347|        std::string body = bodybuf.str();
  340|    347|        strstr_map_t::iterator cpos = target->headers.find("content-type");
  341|    347|        if (cpos != target->headers.end() && Utility::iequals(cpos->second, "application/x-www-form-urlencoded", 32)) {
  ------------------
  |  Branch (341:13): [True: 75, False: 272]
  |  Branch (341:13): [True: 47, False: 300]
  |  Branch (341:46): [True: 47, False: 28]
  ------------------
  342|     47|          target->postvars = Utility::parseUrlParameters(body);
  343|     47|        }
  344|    347|        target->body = std::move(body);
  345|    347|      }
  346|    347|      bodybuf.str("");
  347|    347|      bodysize = 0;
  348|       |      this->target = NULL;
  349|    347|    }; //<! finalize and release target
_ZN6YaHTTP11AsyncLoaderINS_8ResponseEE5readyEv:
  331|    566|    bool ready() {
  332|    566|     return (chunked == true && state == 3) || // if it's chunked we get end of data indication
  ------------------
  |  Branch (332:14): [True: 67, False: 499]
  |  Branch (332:33): [True: 12, False: 55]
  ------------------
  333|    554|             (chunked == false && state > 1 &&  
  ------------------
  |  Branch (333:15): [True: 499, False: 55]
  |  Branch (333:35): [True: 499, False: 0]
  ------------------
  334|    499|               (!hasBody || (bodysize <= maxbody && bodysize >= minbody))); 
  ------------------
  |  Branch (334:17): [True: 227, False: 272]
  |  Branch (334:30): [True: 272, False: 0]
  |  Branch (334:53): [True: 228, False: 44]
  ------------------
  335|    566|    }; //<! whether we have received enough data

_ZN6YaHTTP3URLC2Ev:
  166|  7.32k|      URL() { initialize(); }; //<! construct empty url
_ZN6YaHTTP3URL10initializeEv:
  116|  32.7k|      void initialize() {
  117|  32.7k|        protocol = ""; host = ""; port = 0; username = ""; password = ""; path = ""; parameters = ""; anchor =""; pathless = true;
  118|  32.7k|      }; //<! initialize to empty URL
_ZN6YaHTTP3URLC2EPKc:
  171|  21.9k|      URL(const char *url) {
  172|  21.9k|        parse(std::string(url));
  173|  21.9k|      }; //<! calls parse with url
_ZN6YaHTTP3URL5parseERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE:
  175|  25.4k|      bool parse(const std::string& url) {
  176|       |        // setup
  177|  25.4k|        initialize();
  178|       |
  179|  25.4k|        if (url.size() > YAHTTP_MAX_URL_LENGTH) return false;
  ------------------
  |  |    8|  25.4k|#define YAHTTP_MAX_URL_LENGTH 2048
  ------------------
  |  Branch (179:13): [True: 8, False: 25.4k]
  ------------------
  180|  25.4k|        size_t pos = 0;
  181|  25.4k|        if (*(url.begin()) != '/') { // full url?
  ------------------
  |  Branch (181:13): [True: 25.2k, False: 226]
  ------------------
  182|  25.2k|          if (parseSchema(url, pos) == false) return false;
  ------------------
  |  Branch (182:15): [True: 23.8k, False: 1.36k]
  ------------------
  183|  1.36k|          if (pathless) {
  ------------------
  |  Branch (183:15): [True: 850, False: 514]
  ------------------
  184|    850|            parameters = url.substr(pos);
  185|    850|            return true;
  186|    850|          }
  187|    514|          if (parseUserPass(url, pos) == false) return false;
  ------------------
  |  Branch (187:15): [True: 0, False: 514]
  ------------------
  188|    514|          if (parseHost(url, pos) == false) return false;
  ------------------
  |  Branch (188:15): [True: 24, False: 490]
  ------------------
  189|    514|        }
  190|    716|        if (parsePath(url, pos) == false) return false;
  ------------------
  |  Branch (190:13): [True: 0, False: 716]
  ------------------
  191|    716|        if (parseParameters(url, pos) == false) return false;
  ------------------
  |  Branch (191:13): [True: 0, False: 716]
  ------------------
  192|    716|        return parseAnchor(url, pos);
  193|    716|    }; //<! parse various formats of urls ranging from http://example.com/foo?bar=baz into data:base64:d089swt64wt... 
_ZN6YaHTTP3URL11parseSchemaERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEERm:
   15|  25.2k|      bool parseSchema(const std::string& url, size_t &pos) {
   16|  25.2k|          size_t pos1;
   17|  25.2k|          if (pos >= url.size()) return false; // no data
  ------------------
  |  Branch (17:15): [True: 23.8k, False: 1.39k]
  ------------------
   18|  1.39k|          if ( (pos1 = url.find_first_of(":",pos)) == std::string::npos ) return false; // schema is mandatory
  ------------------
  |  Branch (18:16): [True: 34, False: 1.36k]
  ------------------
   19|  1.36k|          protocol = url.substr(pos, pos1-pos);
   20|  1.36k|          if (protocol == "http") port = 80;
  ------------------
  |  Branch (20:15): [True: 2, False: 1.36k]
  ------------------
   21|  1.36k|          if (protocol == "https") port = 443;
  ------------------
  |  Branch (21:15): [True: 1, False: 1.36k]
  ------------------
   22|  1.36k|          pos = pos1+1; // after :
   23|  1.36k|          if (url.compare(pos, 2, "//") == 0) {
  ------------------
  |  Branch (23:15): [True: 514, False: 850]
  ------------------
   24|    514|             pathless = false; // if this is true we put rest into parameters
   25|    514|             pos += 2;
   26|    514|          }
   27|  1.36k|          return true;
   28|  1.39k|      }; //<! parse schema/protocol part 
_ZN6YaHTTP3URL13parseUserPassERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEERm:
   60|    514|      bool parseUserPass(const std::string& url, size_t &pos) {
   61|    514|          size_t pos1,pos2;
   62|    514|          if (pos >= url.size()) return true; // no data
  ------------------
  |  Branch (62:15): [True: 1, False: 513]
  ------------------
   63|       |
   64|    513|          if ( (pos1 = url.find_first_of("@",pos)) == std::string::npos ) return true; // no userinfo
  ------------------
  |  Branch (64:16): [True: 335, False: 178]
  ------------------
   65|    178|          pos2 = url.find_first_of(":",pos);
   66|       |
   67|    178|          if (pos2 != std::string::npos) { // comes with password
  ------------------
  |  Branch (67:15): [True: 95, False: 83]
  ------------------
   68|     95|             username = url.substr(pos, pos2 - pos);
   69|     95|             password = url.substr(pos2+1, pos1 - pos2 - 1);
   70|     95|             password = Utility::decodeURL(password);
   71|     95|          } else {
   72|     83|             username = url.substr(pos, pos1 - pos);
   73|     83|          }
   74|    178|          pos = pos1+1;
   75|    178|          username = Utility::decodeURL(username);
   76|    178|          return true;
   77|    513|      }; //<! parse possible username and password
_ZN6YaHTTP3URL9parseHostERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEERm:
   30|    514|      bool parseHost(const std::string& url, size_t &pos) {
   31|    514|          size_t pos1;
   32|    514|          if (pos >= url.size()) return true; // no data
  ------------------
  |  Branch (32:15): [True: 65, False: 449]
  ------------------
   33|    449|          if ( (pos1 = url.find_first_of("/", pos)) == std::string::npos ) {
  ------------------
  |  Branch (33:16): [True: 338, False: 111]
  ------------------
   34|    338|             host = url.substr(pos);
   35|    338|             path = "/";
   36|    338|             pos = url.size();
   37|    338|          } else {
   38|    111|             host = url.substr(pos, pos1-pos);
   39|    111|             pos = pos1;
   40|    111|          }
   41|    449|          if (host.at(0) == '[') { // IPv6
  ------------------
  |  Branch (41:15): [True: 150, False: 299]
  ------------------
   42|    150|            if ((pos1 = host.find_first_of("]")) == std::string::npos) {
  ------------------
  |  Branch (42:17): [True: 24, False: 126]
  ------------------
   43|       |              // incomplete address
   44|     24|              return false;
   45|     24|            }
   46|    126|            size_t pos2;
   47|    126|            if ((pos2 = host.find_first_of(":", pos1)) != std::string::npos) {
  ------------------
  |  Branch (47:17): [True: 63, False: 63]
  ------------------
   48|     63|              std::istringstream tmp(host.substr(pos2 + 1));
   49|     63|              tmp >> port;
   50|     63|            }
   51|    126|            host = host.substr(1, pos1 - 1);
   52|    299|          } else if ( (pos1 = host.find_first_of(":")) != std::string::npos ) {
  ------------------
  |  Branch (52:23): [True: 175, False: 124]
  ------------------
   53|    175|             std::istringstream tmp(host.substr(pos1+1));
   54|    175|             tmp >> port;
   55|    175|             host = host.substr(0, pos1);
   56|    175|          }
   57|    425|          return true;
   58|    449|      }; //<! parse host and port
_ZN6YaHTTP3URL9parsePathERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEERm:
   79|    702|      bool parsePath(const std::string& url, size_t &pos) {
   80|    702|          size_t pos1;
   81|    702|          if (pos >= url.size()) return true; // no data
  ------------------
  |  Branch (81:15): [True: 381, False: 321]
  ------------------
   82|    321|          if (url[pos] != '/') return false; // not an url
  ------------------
  |  Branch (82:15): [True: 0, False: 321]
  ------------------
   83|    321|          if ( (pos1 = url.find_first_of("?", pos)) == std::string::npos ) {
  ------------------
  |  Branch (83:16): [True: 101, False: 220]
  ------------------
   84|    101|             path = url.substr(pos);
   85|    101|             pos = url.size();
   86|    220|          } else {
   87|    220|             path = url.substr(pos, pos1-pos);
   88|    220|             pos = pos1;
   89|    220|          }
   90|    321|          return true;
   91|    321|      }; //<! parse path component
_ZN6YaHTTP3URL15parseParametersERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEERm:
   93|    702|      bool parseParameters(const std::string& url, size_t &pos) {
   94|    702|          size_t pos1;
   95|    702|          if (pos >= url.size()) return true; // no data
  ------------------
  |  Branch (95:15): [True: 482, False: 220]
  ------------------
   96|    220|          if (url[pos] == '#') return true; // anchor starts here
  ------------------
  |  Branch (96:15): [True: 0, False: 220]
  ------------------
   97|    220|          if (url[pos] != '?') return false; // not a parameter
  ------------------
  |  Branch (97:15): [True: 0, False: 220]
  ------------------
   98|    220|          if ( (pos1 = url.find_first_of("#", pos)) == std::string::npos ) {
  ------------------
  |  Branch (98:16): [True: 130, False: 90]
  ------------------
   99|    130|             parameters = url.substr(pos+1);;
  100|    130|             pos = url.size();
  101|    130|          } else {
  102|     90|             parameters = url.substr(pos+1, pos1-pos-1);
  103|     90|             pos = pos1;
  104|     90|          }
  105|    220|          if (parameters.size()>0 && *(parameters.end()-1) == '&') parameters.resize(parameters.size()-1);
  ------------------
  |  Branch (105:15): [True: 144, False: 76]
  |  Branch (105:15): [True: 7, False: 213]
  |  Branch (105:38): [True: 7, False: 137]
  ------------------
  106|    220|          return true;
  107|    220|      }; //<! parse url parameters
_ZN6YaHTTP3URL11parseAnchorERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEERm:
  109|    702|      bool parseAnchor(const std::string& url, size_t &pos) {
  110|    702|          if (pos >= url.size()) return true; // no data
  ------------------
  |  Branch (110:15): [True: 612, False: 90]
  ------------------
  111|     90|          if (url[pos] != '#') return false; // not anchor
  ------------------
  |  Branch (111:15): [True: 0, False: 90]
  ------------------
  112|     90|          anchor = url.substr(pos+1);
  113|     90|          return true;
  114|     90|      }; //<! parse anchor

_ZN6YaHTTP7Utility9decodeURLERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE:
  122|  36.6k|    static std::string decodeURL(const std::string& component) {
  123|  36.6k|        std::string result = component;
  124|  36.6k|        size_t pos1,pos2;
  125|  36.6k|        pos2 = 0;
  126|   469k|        while((pos1 = result.find_first_of("%", pos2))!=std::string::npos) {
  ------------------
  |  Branch (126:15): [True: 438k, False: 31.0k]
  ------------------
  127|   438k|           std::string code;
  128|   438k|           char a,b,c;
  129|   438k|           if (pos1 + 2 > result.length()) return result; // end of result
  ------------------
  |  Branch (129:16): [True: 5.58k, False: 433k]
  ------------------
  130|   433k|           code = result.substr(pos1+1, 2);
  131|   433k|           a = std::tolower(code[0]); b = std::tolower(code[1]);
  132|       |
  133|   433k|           if ((( '0' > a || a > '9') && ('a' > a || a > 'f')) ||
  ------------------
  |  Branch (133:19): [True: 192k, False: 241k]
  |  Branch (133:30): [True: 217k, False: 23.2k]
  |  Branch (133:43): [True: 233k, False: 176k]
  |  Branch (133:54): [True: 33.3k, False: 143k]
  ------------------
  134|   326k|              (( '0' > b || b > '9') && ('a' > b || b > 'f'))) {
  ------------------
  |  Branch (134:18): [True: 55.9k, False: 110k]
  |  Branch (134:29): [True: 100k, False: 10.1k]
  |  Branch (134:42): [True: 58.2k, False: 98.5k]
  |  Branch (134:53): [True: 1.50k, False: 97.0k]
  ------------------
  135|   326k|              pos2 = pos1+3;
  136|   326k|              continue;
  137|   326k|           }
  138|       |
  139|   107k|           if ('0' <= a && a <= '9') a = a - '0';
  ------------------
  |  Branch (139:16): [True: 107k, False: 0]
  |  Branch (139:28): [True: 10.1k, False: 97.0k]
  ------------------
  140|  97.0k|           else if ('a' <= a && a <= 'f') a = a - 'a' + 0x0a;
  ------------------
  |  Branch (140:21): [True: 97.0k, False: 0]
  |  Branch (140:33): [True: 97.0k, False: 0]
  ------------------
  141|   107k|           if ('0' <= b && b <= '9') b = b - '0';
  ------------------
  |  Branch (141:16): [True: 107k, False: 0]
  |  Branch (141:28): [True: 10.1k, False: 97.0k]
  ------------------
  142|  97.0k|           else if ('a' <= b && b <= 'f') b = b - 'a' + 0x0a;
  ------------------
  |  Branch (142:21): [True: 97.0k, False: 0]
  |  Branch (142:33): [True: 97.0k, False: 0]
  ------------------
  143|       |
  144|   107k|           c = (a<<4)+b;
  145|   107k|           result = result.replace(pos1,3,1,c);
  146|   107k|           pos2=pos1;
  147|   107k|        }
  148|  31.0k|        return result;
  149|  36.6k|    }; //<! Decodes %xx from string into bytes
_ZNK6YaHTTP25ASCIICINullSafeComparatorclERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_:
   25|   643k|    bool operator() (const std::string& lhs, const std::string& rhs) const {
   26|   643k|      int v;
   27|   643k|      std::string::const_iterator lhi = lhs.begin();
   28|   643k|      std::string::const_iterator rhi = rhs.begin();
   29|  1.91M|      for(;lhi != lhs.end() && rhi != rhs.end(); lhi++, rhi++)
  ------------------
  |  Branch (29:12): [True: 1.65M, False: 253k]
  |  Branch (29:12): [True: 1.63M, False: 279k]
  |  Branch (29:32): [True: 1.63M, False: 25.2k]
  ------------------
   30|  1.63M|        if ((v = ::tolower(*lhi) - ::tolower(*rhi)) != 0) return v<0; 
  ------------------
  |  Branch (30:13): [True: 364k, False: 1.26M]
  ------------------
   31|   279k|      if (lhi == lhs.end() && rhi != rhs.end()) return true;
  ------------------
  |  Branch (31:11): [True: 253k, False: 25.2k]
  |  Branch (31:11): [True: 49.8k, False: 229k]
  |  Branch (31:31): [True: 49.8k, False: 204k]
  ------------------
   32|   229k|      if (lhi != lhs.end() && rhi == rhs.end()) return false;
  ------------------
  |  Branch (32:11): [True: 25.2k, False: 204k]
  |  Branch (32:11): [True: 25.2k, False: 204k]
  |  Branch (32:31): [True: 25.2k, False: 0]
  ------------------
   33|   204k|      return false; // they are equal
   34|   229k|    }
_ZN6YaHTTP7Utility7iequalsERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_m:
  296|    196|    static bool iequals(const std::string& a, const std::string& b, size_t length) {
  297|    196|      std::string::const_iterator ai, bi;
  298|    196|      size_t i;
  299|  5.23k|      for(ai = a.begin(), bi = b.begin(), i = 0; ai != a.end() && bi != b.end() && i < length; ai++,bi++,i++) {
  ------------------
  |  Branch (299:50): [True: 5.20k, False: 36]
  |  Branch (299:50): [True: 5.05k, False: 184]
  |  Branch (299:67): [True: 5.20k, False: 0]
  |  Branch (299:84): [True: 5.05k, False: 148]
  ------------------
  300|  5.05k|        if (::toupper(*ai) != ::toupper(*bi)) return false;
  ------------------
  |  Branch (300:13): [True: 12, False: 5.04k]
  ------------------
  301|  5.05k|      }
  302|       |
  303|    184|      if (ai == a.end() && bi == b.end()) return true;
  ------------------
  |  Branch (303:11): [True: 36, False: 148]
  |  Branch (303:11): [True: 0, False: 184]
  |  Branch (303:28): [True: 0, False: 36]
  ------------------
  304|    184|      if ((ai == a.end() && bi != b.end()) ||
  ------------------
  |  Branch (304:11): [True: 36, False: 148]
  |  Branch (304:12): [True: 36, False: 148]
  |  Branch (304:29): [True: 36, False: 0]
  ------------------
  305|    148|          (ai != a.end() && bi == b.end())) return false;
  ------------------
  |  Branch (305:12): [True: 148, False: 0]
  |  Branch (305:29): [True: 0, False: 148]
  ------------------
  306|       |      
  307|    148|      return ::toupper(*ai) == ::toupper(*bi);
  308|    184|    }; //<! case-insensitive comparison with length
_ZN6YaHTTP7Utility18parseUrlParametersERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE:
  253|  3.63k|    static strstr_map_t parseUrlParameters(const std::string& parameters) {
  254|  3.63k|      if (parameters.size() > YAHTTP_MAX_REQUEST_LINE_SIZE) {
  ------------------
  |  |    4|  3.63k|#define YAHTTP_MAX_REQUEST_LINE_SIZE 8192
  ------------------
  |  Branch (254:11): [True: 3, False: 3.63k]
  ------------------
  255|      3|        return {};
  256|      3|      }
  257|  3.63k|      std::string::size_type pos = 0;
  258|  3.63k|      strstr_map_t parameter_map;
  259|  21.0k|      while (pos != std::string::npos) {
  ------------------
  |  Branch (259:14): [True: 21.0k, False: 0]
  ------------------
  260|       |        // find next parameter start
  261|  21.0k|        std::string::size_type nextpos = parameters.find('&', pos);
  262|  21.0k|        std::string::size_type delim = parameters.find('=', pos);
  263|  21.0k|        if (delim > nextpos) {
  ------------------
  |  Branch (263:13): [True: 15.2k, False: 5.80k]
  ------------------
  264|  15.2k|          delim = nextpos;
  265|  15.2k|        }
  266|  21.0k|        std::string key;
  267|  21.0k|        std::string value;
  268|  21.0k|        if (delim == std::string::npos) {
  ------------------
  |  Branch (268:13): [True: 3.38k, False: 17.6k]
  ------------------
  269|  3.38k|          key = parameters.substr(pos);
  270|  17.6k|        } else {
  271|  17.6k|          key = parameters.substr(pos, delim-pos);
  272|  17.6k|          if (nextpos == std::string::npos) {
  ------------------
  |  Branch (272:15): [True: 118, False: 17.5k]
  ------------------
  273|    118|            value = parameters.substr(delim+1);
  274|  17.5k|          } else {
  275|  17.5k|            value = parameters.substr(delim+1, nextpos-delim-1);
  276|  17.5k|          }
  277|  17.6k|        }
  278|  21.0k|        if (key.empty()) {
  ------------------
  |  Branch (278:13): [True: 2.87k, False: 18.1k]
  ------------------
  279|       |          // no parameters at all
  280|  2.87k|          break;
  281|  2.87k|        }
  282|  18.1k|        parameter_map[decodeURL(key)] = decodeURL(value);
  283|  18.1k|        if (nextpos == std::string::npos) {
  ------------------
  |  Branch (283:13): [True: 756, False: 17.4k]
  ------------------
  284|       |          // no more parameters left
  285|    756|          break;
  286|    756|        }
  287|  17.4k|        if (parameter_map.size() >= YAHTTP_MAX_REQUEST_FIELDS) {
  ------------------
  |  |    8|  17.4k|#define YAHTTP_MAX_REQUEST_FIELDS 100
  ------------------
  |  Branch (287:13): [True: 5, False: 17.4k]
  ------------------
  288|      5|          break;
  289|      5|        }
  290|       |
  291|  17.4k|        pos = nextpos+1;
  292|  17.4k|      }
  293|  3.63k|      return parameter_map;
  294|  3.63k|    }; //<! parses URL parameters into string map 
_ZN6YaHTTP7Utility8trimLeftERNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE:
  315|  49.3k|    static void trimLeft(std::string &str) {
  316|  49.3k|       const std::locale &loc = std::locale::classic();
  317|  49.3k|       std::string::iterator iter = str.begin();
  318|  50.7k|       while(iter != str.end() && YaHTTP::isspace(*iter, loc)) iter++;
  ------------------
  |  Branch (318:14): [True: 12.4k, False: 38.3k]
  |  Branch (318:14): [True: 1.41k, False: 49.3k]
  |  Branch (318:35): [True: 1.41k, False: 10.9k]
  ------------------
  319|  49.3k|       str.erase(str.begin(), iter);
  320|  49.3k|    }; //<! removes whitespace from left
_ZN6YaHTTP7Utility9trimRightERNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE:
  322|  49.3k|    static void trimRight(std::string &str) {
  323|  49.3k|       const std::locale &loc = std::locale::classic();
  324|  49.3k|       std::string::reverse_iterator iter = str.rbegin();
  325|  51.3k|       while(iter != str.rend() && YaHTTP::isspace(*iter, loc)) iter++;
  ------------------
  |  Branch (325:14): [True: 12.9k, False: 38.3k]
  |  Branch (325:14): [True: 1.99k, False: 49.3k]
  |  Branch (325:36): [True: 1.99k, False: 10.9k]
  ------------------
  326|  49.3k|       str.erase(iter.base(), str.end());
  327|  49.3k|    }; //<! removes whitespace from right
_ZN6YaHTTP7Utility4trimERNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE:
  329|  49.3k|    static void trim(std::string &str) {
  330|  49.3k|       trimLeft(str);
  331|  49.3k|       trimRight(str);
  332|  49.3k|    }; //<! removes whitespace from left and right

LLVMFuzzerTestOneInput:
   30|  3.66k|{
   31|  3.66k|  try {
   32|  3.66k|    YaHTTP::AsyncRequestLoader yarl;
   33|  3.66k|    YaHTTP::Request req;
   34|       |
   35|  3.66k|    yarl.initialize(&req);
   36|       |    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
   37|  3.66k|    bool finished = yarl.feed(std::string(reinterpret_cast<const char*>(data), size));
   38|  3.66k|    if (finished) {
  ------------------
  |  Branch (38:9): [True: 424, False: 3.23k]
  ------------------
   39|    424|      yarl.finalize();
   40|    424|    }
   41|  3.66k|  }
   42|       |  // NOLINTNEXTLINE(bugprone-empty-catch)
   43|  3.66k|  catch (const YaHTTP::ParseError& e) {
   44|    559|  }
   45|       |  // NOLINTNEXTLINE(bugprone-empty-catch)
   46|  3.66k|  catch (const std::exception& e) {
   47|     14|  }
   48|       |  // NOLINTNEXTLINE(bugprone-empty-catch)
   49|  3.66k|  catch (...) {
   50|      0|  }
   51|       |
   52|  3.66k|  try {
   53|  3.66k|    YaHTTP::AsyncResponseLoader yarl;
   54|  3.66k|    YaHTTP::Response resp;
   55|       |
   56|  3.66k|    yarl.initialize(&resp);
   57|       |    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
   58|  3.66k|    bool finished = yarl.feed(std::string(reinterpret_cast<const char*>(data), size));
   59|  3.66k|    if (finished) {
  ------------------
  |  Branch (59:9): [True: 347, False: 3.31k]
  ------------------
   60|    347|      yarl.finalize();
   61|    347|    }
   62|  3.66k|  }
   63|       |  // NOLINTNEXTLINE(bugprone-empty-catch)
   64|  3.66k|  catch (const YaHTTP::ParseError& e) {
   65|  2.28k|  }
   66|       |  // NOLINTNEXTLINE(bugprone-empty-catch)
   67|  3.66k|  catch (const std::exception& e) {
   68|      0|  }
   69|       |  // NOLINTNEXTLINE(bugprone-empty-catch)
   70|  3.66k|  catch (...) {
   71|      0|  }
   72|       |
   73|  3.66k|  return 0;
   74|  3.66k|}

