_ZN7httplib6StreamD2Ev:
 2047|  1.40k|  virtual ~Stream() = default;
_ZN7httplib6detail12BufferStreamC2Ev:
 4110|  1.40k|  BufferStream() = default;
_ZN7httplib6detail12BufferStream5writeEPKcm:
13707|  1.40k|inline ssize_t BufferStream::write(const char *ptr, size_t size) {
13708|  1.40k|  buffer.append(ptr, size);
13709|  1.40k|  return static_cast<ssize_t>(size);
13710|  1.40k|}
_ZN7httplib2ws4impl20read_websocket_frameERNS_6StreamERNS0_6OpcodeERNSt3__112basic_stringIcNS6_11char_traitsIcEENS6_9allocatorIcEEEERbbm:
 6330|    271|                                      bool expect_masked, size_t max_len) {
 6331|    271|  FrameReader reader;
 6332|    271|  auto r = reader.read(strm, opcode, payload, fin, expect_masked, max_len);
 6333|    271|  return r == FrameRead::Timeout && reader.begun() ? FrameRead::Fail : r;
  ------------------
  |  Branch (6333:10): [True: 0, False: 271]
  |  Branch (6333:37): [True: 0, False: 0]
  ------------------
 6334|    271|}
_ZN7httplib2ws4impl11FrameReader4readERNS_6StreamERNS0_6OpcodeERNSt3__112basic_stringIcNS7_11char_traitsIcEENS7_9allocatorIcEEEERbbm:
 6248|    271|                                   bool expect_masked, size_t max_len) {
 6249|       |  // A timeout keeps what was read; anything else ends the frame
 6250|    271|  auto stopped = [&]() {
 6251|    271|    if (strm.get_error() == Error::Timeout) { return FrameRead::Timeout; }
 6252|    271|    reset();
 6253|    271|    return FrameRead::Fail;
 6254|    271|  };
 6255|    271|  auto reject = [&](FrameRead r) {
 6256|    271|    reset();
 6257|    271|    return r;
 6258|    271|  };
 6259|       |
 6260|    759|  while (have_ < need_) {
  ------------------
  |  Branch (6260:10): [True: 509, False: 250]
  ------------------
 6261|    509|    auto n = strm.read(reinterpret_cast<char *>(head_) + have_, need_ - have_);
 6262|    509|    if (n <= 0) { return stopped(); }
  ------------------
  |  Branch (6262:9): [True: 12, False: 497]
  ------------------
 6263|    497|    have_ += static_cast<size_t>(n);
 6264|    497|    if (have_ < 2 || need_ > 2) { continue; }
  ------------------
  |  Branch (6264:9): [True: 2, False: 495]
  |  Branch (6264:22): [True: 226, False: 269]
  ------------------
 6265|       |
 6266|       |    // RSV1, RSV2, RSV3 must be 0 when no extension is negotiated
 6267|    269|    if (head_[0] & 0x70) { return reject(FrameRead::ProtocolError); }
  ------------------
  |  Branch (6267:9): [True: 3, False: 266]
  ------------------
 6268|       |    // RFC 6455 Section 5.5: control frames MUST NOT be fragmented and
 6269|       |    // MUST have a payload length of 125 bytes or less
 6270|    266|    auto len7 = head_[1] & 0x7F;
 6271|    266|    if ((head_[0] & 0x08) && (!(head_[0] & 0x80) || len7 > 125)) {
  ------------------
  |  Branch (6271:9): [True: 24, False: 242]
  |  Branch (6271:31): [True: 1, False: 23]
  |  Branch (6271:53): [True: 1, False: 22]
  ------------------
 6272|      2|      return reject(FrameRead::ProtocolError);
 6273|      2|    }
 6274|    264|    auto masked = (head_[1] & 0x80) != 0;
 6275|    264|    if (masked != expect_masked) { return reject(FrameRead::ProtocolError); }
  ------------------
  |  Branch (6275:9): [True: 4, False: 260]
  ------------------
 6276|       |    // The extended length and the mask key follow
 6277|    260|    need_ = 2 + (len7 == 126 ? 2 : len7 == 127 ? 8 : 0) + (masked ? 4 : 0);
  ------------------
  |  Branch (6277:18): [True: 71, False: 189]
  |  Branch (6277:36): [True: 141, False: 48]
  |  Branch (6277:60): [True: 32, False: 228]
  ------------------
 6278|    260|  }
 6279|       |
 6280|    250|  if (!sized_) {
  ------------------
  |  Branch (6280:7): [True: 250, False: 0]
  ------------------
 6281|    250|    uint64_t len = head_[1] & 0x7F;
 6282|    250|    if (len == 126) {
  ------------------
  |  Branch (6282:9): [True: 69, False: 181]
  ------------------
 6283|     69|      len = (static_cast<uint64_t>(head_[2]) << 8) | head_[3];
 6284|    181|    } else if (len == 127) {
  ------------------
  |  Branch (6284:16): [True: 136, False: 45]
  ------------------
 6285|       |      // RFC 6455 Section 5.2: the most significant bit MUST be 0
 6286|    136|      if (head_[2] & 0x80) { return reject(FrameRead::ProtocolError); }
  ------------------
  |  Branch (6286:11): [True: 1, False: 135]
  ------------------
 6287|    135|      len = 0;
 6288|  1.21k|      for (size_t i = 2; i < 10; i++) {
  ------------------
  |  Branch (6288:26): [True: 1.08k, False: 135]
  ------------------
 6289|  1.08k|        len = (len << 8) | head_[i];
 6290|  1.08k|      }
 6291|    135|    }
 6292|       |    // A max_len of 0 means no limit, as payload_max_length does, and a length
 6293|       |    // size_t cannot hold (32-bit builds) is refused either way.
 6294|    249|    if ((max_len > 0 && len > max_len) || !detail::fits_in_size_t(len)) {
  ------------------
  |  Branch (6294:10): [True: 141, False: 108]
  |  Branch (6294:25): [True: 97, False: 44]
  |  Branch (6294:43): [True: 0, False: 152]
  ------------------
 6295|     97|      return reject(FrameRead::TooBig);
 6296|     97|    }
 6297|    152|    len_ = static_cast<size_t>(len);
 6298|    152|    sized_ = true;
 6299|    152|  }
 6300|       |
 6301|       |  // Grow the payload only as it arrives, since a header alone can announce
 6302|       |  // max_len bytes that never come.
 6303|    216|  while (payload_.size() < len_) {
  ------------------
  |  Branch (6303:10): [True: 183, False: 33]
  ------------------
 6304|    183|    auto offset = payload_.size();
 6305|    183|    auto n = (std::min)(len_ - offset, CPPHTTPLIB_RECV_BUFSIZ);
  ------------------
  |  |  199|    183|#define CPPHTTPLIB_RECV_BUFSIZ size_t(16384u)
  ------------------
 6306|    183|    payload_.resize(offset + n);
 6307|    183|    auto got = strm.read(&payload_[offset], n);
 6308|    183|    if (got <= 0) {
  ------------------
  |  Branch (6308:9): [True: 119, False: 64]
  ------------------
 6309|    119|      payload_.resize(offset);
 6310|    119|      return stopped();
 6311|    119|    }
 6312|     64|    payload_.resize(offset + static_cast<size_t>(got));
 6313|     64|  }
 6314|       |
 6315|     33|  if (head_[1] & 0x80) {
  ------------------
  |  Branch (6315:7): [True: 28, False: 5]
  ------------------
 6316|     28|    const auto *mask_key = head_ + need_ - 4;
 6317|   133k|    for (size_t i = 0; i < payload_.size(); i++) {
  ------------------
  |  Branch (6317:24): [True: 133k, False: 28]
  ------------------
 6318|   133k|      payload_[i] ^= static_cast<char>(mask_key[i % 4]);
 6319|   133k|    }
 6320|     28|  }
 6321|     33|  fin = (head_[0] & 0x80) != 0;
 6322|     33|  opcode = static_cast<Opcode>(head_[0] & 0x0F);
 6323|     33|  payload = std::move(payload_);
 6324|     33|  reset();
 6325|     33|  return FrameRead::Ok;
 6326|    152|}
_ZZN7httplib2ws4impl11FrameReader4readERNS_6StreamERNS0_6OpcodeERNSt3__112basic_stringIcNS7_11char_traitsIcEENS7_9allocatorIcEEEERbbmENKUlvE_clEv:
 6250|    131|  auto stopped = [&]() {
 6251|    131|    if (strm.get_error() == Error::Timeout) { return FrameRead::Timeout; }
  ------------------
  |  Branch (6251:9): [True: 0, False: 131]
  ------------------
 6252|    131|    reset();
 6253|    131|    return FrameRead::Fail;
 6254|    131|  };
_ZNK7httplib6Stream9get_errorEv:
 2092|    131|  Error get_error() const { return error_; }
_ZZN7httplib2ws4impl11FrameReader4readERNS_6StreamERNS0_6OpcodeERNSt3__112basic_stringIcNS7_11char_traitsIcEENS7_9allocatorIcEEEERbbmENKUlNS1_9FrameReadEE_clESG_:
 6255|    107|  auto reject = [&](FrameRead r) {
 6256|    107|    reset();
 6257|    107|    return r;
 6258|    107|  };
_ZN7httplib6detail14fits_in_size_tEm:
 5825|    152|inline bool fits_in_size_t(uint64_t n) {
 5826|    152|  return static_cast<uint64_t>(static_cast<size_t>(n)) == n;
 5827|    152|}
_ZN7httplib2ws4impl11FrameReader5resetEv:
 6234|    271|inline void FrameReader::reset() {
 6235|    271|  have_ = 0;
 6236|    271|  need_ = 2;
 6237|    271|  sized_ = false;
 6238|    271|  len_ = 0;
 6239|    271|  payload_.clear();
 6240|    271|}
_ZN7httplib6detail12BufferStreamD2Ev:
 4111|  1.40k|  ~BufferStream() override = default;
_ZN7httplib2ws4impl13is_valid_utf8ERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE:
 5953|    261|inline bool is_valid_utf8(const std::string &s) {
 5954|    261|  size_t i = 0;
 5955|    261|  auto n = s.size();
 5956|   236k|  while (i < n) {
  ------------------
  |  Branch (5956:10): [True: 235k, False: 137]
  ------------------
 5957|   235k|    auto c = static_cast<unsigned char>(s[i]);
 5958|   235k|    size_t len;
 5959|   235k|    uint32_t cp;
 5960|   235k|    if (c < 0x80) {
  ------------------
  |  Branch (5960:9): [True: 222k, False: 13.1k]
  ------------------
 5961|   222k|      i++;
 5962|   222k|      continue;
 5963|   222k|    } else if ((c & 0xE0) == 0xC0) {
  ------------------
  |  Branch (5963:16): [True: 1.79k, False: 11.3k]
  ------------------
 5964|  1.79k|      len = 2;
 5965|  1.79k|      cp = c & 0x1F;
 5966|  11.3k|    } else if ((c & 0xF0) == 0xE0) {
  ------------------
  |  Branch (5966:16): [True: 5.47k, False: 5.85k]
  ------------------
 5967|  5.47k|      len = 3;
 5968|  5.47k|      cp = c & 0x0F;
 5969|  5.85k|    } else if ((c & 0xF8) == 0xF0) {
  ------------------
  |  Branch (5969:16): [True: 5.84k, False: 11]
  ------------------
 5970|  5.84k|      len = 4;
 5971|  5.84k|      cp = c & 0x07;
 5972|  5.84k|    } else {
 5973|     11|      return false;
 5974|     11|    }
 5975|  13.1k|    if (i + len > n) { return false; }
  ------------------
  |  Branch (5975:9): [True: 36, False: 13.0k]
  ------------------
 5976|  43.2k|    for (size_t j = 1; j < len; j++) {
  ------------------
  |  Branch (5976:24): [True: 30.1k, False: 13.0k]
  ------------------
 5977|  30.1k|      auto b = static_cast<unsigned char>(s[i + j]);
 5978|  30.1k|      if ((b & 0xC0) != 0x80) { return false; }
  ------------------
  |  Branch (5978:11): [True: 13, False: 30.1k]
  ------------------
 5979|  30.1k|      cp = (cp << 6) | (b & 0x3F);
 5980|  30.1k|    }
 5981|       |    // Overlong encoding check
 5982|  13.0k|    if (len == 2 && cp < 0x80) { return false; }
  ------------------
  |  Branch (5982:9): [True: 1.77k, False: 11.2k]
  |  Branch (5982:21): [True: 11, False: 1.76k]
  ------------------
 5983|  13.0k|    if (len == 3 && cp < 0x800) { return false; }
  ------------------
  |  Branch (5983:9): [True: 5.46k, False: 7.58k]
  |  Branch (5983:21): [True: 14, False: 5.44k]
  ------------------
 5984|  13.0k|    if (len == 4 && cp < 0x10000) { return false; }
  ------------------
  |  Branch (5984:9): [True: 5.82k, False: 7.21k]
  |  Branch (5984:21): [True: 14, False: 5.80k]
  ------------------
 5985|       |    // Surrogate halves (U+D800..U+DFFF) and beyond U+10FFFF are invalid
 5986|  13.0k|    if (cp >= 0xD800 && cp <= 0xDFFF) { return false; }
  ------------------
  |  Branch (5986:9): [True: 6.25k, False: 6.77k]
  |  Branch (5986:25): [True: 14, False: 6.23k]
  ------------------
 5987|  13.0k|    if (cp > 0x10FFFF) { return false; }
  ------------------
  |  Branch (5987:9): [True: 11, False: 12.9k]
  ------------------
 5988|  12.9k|    i += len;
 5989|  12.9k|  }
 5990|    137|  return true;
 5991|    261|}
_ZN7httplib2ws4impl22is_valid_close_payloadERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE:
 6344|    100|inline bool is_valid_close_payload(const std::string &payload) {
 6345|    100|  if (payload.empty()) { return true; }
  ------------------
  |  Branch (6345:7): [True: 0, False: 100]
  ------------------
 6346|    100|  if (payload.size() < 2) { return false; }
  ------------------
  |  Branch (6346:7): [True: 1, False: 99]
  ------------------
 6347|     99|  auto code = close_code(payload);
 6348|     99|  auto may_be_sent = (1000 <= code && code <= 1003) ||
  ------------------
  |  Branch (6348:23): [True: 87, False: 12]
  |  Branch (6348:39): [True: 3, False: 84]
  ------------------
 6349|     96|                     (1007 <= code && code <= 1014) ||
  ------------------
  |  Branch (6349:23): [True: 82, False: 14]
  |  Branch (6349:39): [True: 5, False: 77]
  ------------------
 6350|     91|                     (3000 <= code && code <= 4999);
  ------------------
  |  Branch (6350:23): [True: 58, False: 33]
  |  Branch (6350:39): [True: 25, False: 33]
  ------------------
 6351|     99|  return may_be_sent && is_valid_utf8(payload.substr(2));
  ------------------
  |  Branch (6351:10): [True: 33, False: 66]
  |  Branch (6351:25): [True: 24, False: 9]
  ------------------
 6352|    100|}
_ZN7httplib2ws4impl10close_codeERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE:
 6339|     99|inline uint16_t close_code(const std::string &payload) {
 6340|     99|  return static_cast<uint16_t>((static_cast<uint8_t>(payload[0]) << 8) |
 6341|     99|                               static_cast<uint8_t>(payload[1]));
 6342|     99|}
_ZN7httplib6detail20websocket_accept_keyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE:
 6122|      1|inline std::string websocket_accept_key(const std::string &client_key) {
 6123|      1|  const std::string magic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
 6124|      1|  return base64_encode(sha1(client_key + magic));
 6125|      1|}
_ZN7httplib6detail13base64_encodeERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE:
 6000|      1|inline std::string base64_encode(const std::string &in) {
 6001|      1|  static const auto lookup =
 6002|      1|      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 6003|       |
 6004|      1|  std::string out;
 6005|      1|  out.reserve(in.size());
 6006|       |
 6007|       |  // Unsigned: the accumulator is never masked, so with a signed int the
 6008|       |  // `val << 8` below overflows once enough bytes are folded in (undefined
 6009|       |  // behaviour before C++20). Only the low bits are ever emitted, so the
 6010|       |  // wrap-around of an unsigned accumulator does not affect the output.
 6011|      1|  uint32_t val = 0;
 6012|      1|  auto valb = -6;
 6013|       |
 6014|     20|  for (auto c : in) {
  ------------------
  |  Branch (6014:15): [True: 20, False: 1]
  ------------------
 6015|     20|    val = (val << 8) + static_cast<uint8_t>(c);
 6016|     20|    valb += 8;
 6017|     46|    while (valb >= 0) {
  ------------------
  |  Branch (6017:12): [True: 26, False: 20]
  ------------------
 6018|     26|      out.push_back(lookup[(val >> valb) & 0x3F]);
 6019|     26|      valb -= 6;
 6020|     26|    }
 6021|     20|  }
 6022|       |
 6023|      1|  if (valb > -6) { out.push_back(lookup[((val << 8) >> (valb + 8)) & 0x3F]); }
  ------------------
  |  Branch (6023:7): [True: 1, False: 0]
  ------------------
 6024|       |
 6025|      2|  while (out.size() % 4) {
  ------------------
  |  Branch (6025:10): [True: 1, False: 1]
  ------------------
 6026|      1|    out.push_back('=');
 6027|      1|  }
 6028|       |
 6029|      1|  return out;
 6030|      1|}
_ZN7httplib6detail4sha1ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE:
 6032|      1|inline std::string sha1(const std::string &input) {
 6033|       |  // RFC 3174 SHA-1 implementation
 6034|      1|  auto left_rotate = [](uint32_t x, uint32_t n) -> uint32_t {
 6035|      1|    return (x << n) | (x >> (32 - n));
 6036|      1|  };
 6037|       |
 6038|      1|  uint32_t h0 = 0x67452301;
 6039|      1|  uint32_t h1 = 0xEFCDAB89;
 6040|      1|  uint32_t h2 = 0x98BADCFE;
 6041|      1|  uint32_t h3 = 0x10325476;
 6042|      1|  uint32_t h4 = 0xC3D2E1F0;
 6043|       |
 6044|       |  // Pre-processing: adding padding bits
 6045|      1|  std::string msg = input;
 6046|      1|  uint64_t original_bit_len = static_cast<uint64_t>(msg.size()) * 8;
 6047|      1|  msg.push_back(static_cast<char>(0x80u));
 6048|     60|  while (msg.size() % 64 != 56) {
  ------------------
  |  Branch (6048:10): [True: 59, False: 1]
  ------------------
 6049|     59|    msg.push_back(0);
 6050|     59|  }
 6051|       |
 6052|       |  // Append original length in bits as 64-bit big-endian
 6053|      9|  for (int i = 56; i >= 0; i -= 8) {
  ------------------
  |  Branch (6053:20): [True: 8, False: 1]
  ------------------
 6054|      8|    msg.push_back(static_cast<char>((original_bit_len >> i) & 0xFF));
 6055|      8|  }
 6056|       |
 6057|       |  // Process each 512-bit chunk
 6058|      3|  for (size_t offset = 0; offset < msg.size(); offset += 64) {
  ------------------
  |  Branch (6058:27): [True: 2, False: 1]
  ------------------
 6059|      2|    uint32_t w[80];
 6060|       |
 6061|     34|    for (size_t i = 0; i < 16; i++) {
  ------------------
  |  Branch (6061:24): [True: 32, False: 2]
  ------------------
 6062|     32|      w[i] =
 6063|     32|          (static_cast<uint32_t>(static_cast<uint8_t>(msg[offset + i * 4]))
 6064|     32|           << 24) |
 6065|     32|          (static_cast<uint32_t>(static_cast<uint8_t>(msg[offset + i * 4 + 1]))
 6066|     32|           << 16) |
 6067|     32|          (static_cast<uint32_t>(static_cast<uint8_t>(msg[offset + i * 4 + 2]))
 6068|     32|           << 8) |
 6069|     32|          (static_cast<uint32_t>(
 6070|     32|              static_cast<uint8_t>(msg[offset + i * 4 + 3])));
 6071|     32|    }
 6072|       |
 6073|    130|    for (int i = 16; i < 80; i++) {
  ------------------
  |  Branch (6073:22): [True: 128, False: 2]
  ------------------
 6074|    128|      w[i] = left_rotate(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
 6075|    128|    }
 6076|       |
 6077|      2|    uint32_t a = h0, b = h1, c = h2, d = h3, e = h4;
 6078|       |
 6079|    162|    for (int i = 0; i < 80; i++) {
  ------------------
  |  Branch (6079:21): [True: 160, False: 2]
  ------------------
 6080|    160|      uint32_t f, k;
 6081|    160|      if (i < 20) {
  ------------------
  |  Branch (6081:11): [True: 40, False: 120]
  ------------------
 6082|     40|        f = (b & c) | ((~b) & d);
 6083|     40|        k = 0x5A827999;
 6084|    120|      } else if (i < 40) {
  ------------------
  |  Branch (6084:18): [True: 40, False: 80]
  ------------------
 6085|     40|        f = b ^ c ^ d;
 6086|     40|        k = 0x6ED9EBA1;
 6087|     80|      } else if (i < 60) {
  ------------------
  |  Branch (6087:18): [True: 40, False: 40]
  ------------------
 6088|     40|        f = (b & c) | (b & d) | (c & d);
 6089|     40|        k = 0x8F1BBCDC;
 6090|     40|      } else {
 6091|     40|        f = b ^ c ^ d;
 6092|     40|        k = 0xCA62C1D6;
 6093|     40|      }
 6094|       |
 6095|    160|      uint32_t temp = left_rotate(a, 5) + f + e + k + w[i];
 6096|    160|      e = d;
 6097|    160|      d = c;
 6098|    160|      c = left_rotate(b, 30);
 6099|    160|      b = a;
 6100|    160|      a = temp;
 6101|    160|    }
 6102|       |
 6103|      2|    h0 += a;
 6104|      2|    h1 += b;
 6105|      2|    h2 += c;
 6106|      2|    h3 += d;
 6107|      2|    h4 += e;
 6108|      2|  }
 6109|       |
 6110|       |  // Produce the final hash as a 20-byte binary string
 6111|      1|  std::string hash(20, '\0');
 6112|      5|  for (size_t i = 0; i < 4; i++) {
  ------------------
  |  Branch (6112:22): [True: 4, False: 1]
  ------------------
 6113|      4|    hash[i] = static_cast<char>((h0 >> (24 - i * 8)) & 0xFF);
 6114|      4|    hash[4 + i] = static_cast<char>((h1 >> (24 - i * 8)) & 0xFF);
 6115|      4|    hash[8 + i] = static_cast<char>((h2 >> (24 - i * 8)) & 0xFF);
 6116|      4|    hash[12 + i] = static_cast<char>((h3 >> (24 - i * 8)) & 0xFF);
 6117|      4|    hash[16 + i] = static_cast<char>((h4 >> (24 - i * 8)) & 0xFF);
 6118|      4|  }
 6119|      1|  return hash;
 6120|      1|}
_ZZN7httplib6detail4sha1ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEENKUljjE_clEjj:
 6034|    448|  auto left_rotate = [](uint32_t x, uint32_t n) -> uint32_t {
 6035|    448|    return (x << n) | (x >> (32 - n));
 6036|    448|  };
_ZN7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEEC2Ev:
 1299|  1.13k|  insertion_ordered_multimap() = default;
_ZN7httplib6detail31read_websocket_upgrade_responseERNS_6StreamERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESB_RNS0_24WebSocketUpgradeResponseE:
 9344|  1.13k|                                WebSocketUpgradeResponse &upgrade) {
 9345|       |  // The headers of a rejection are kept so the caller can see why the server
 9346|       |  // refused the upgrade.
 9347|  1.13k|  if (!read_response_head(strm, upgrade.status, upgrade.headers)) {
  ------------------
  |  Branch (9347:7): [True: 647, False: 488]
  ------------------
 9348|    647|    upgrade.error = Error::Read;
 9349|    647|    return false;
 9350|    647|  }
 9351|       |
 9352|    488|  const auto &headers = upgrade.headers;
 9353|       |
 9354|    488|  if (upgrade.status != StatusCode::SwitchingProtocol_101) {
  ------------------
  |  Branch (9354:7): [True: 274, False: 214]
  ------------------
 9355|    274|    upgrade.error = Error::WebSocketHandshake;
 9356|    274|    return false;
 9357|    274|  }
 9358|       |
 9359|       |  // Verify Upgrade: websocket (a comma-separated list, matched per token)
 9360|    214|  if (!has_header_token(headers, "Upgrade", "websocket")) {
  ------------------
  |  Branch (9360:7): [True: 214, False: 0]
  ------------------
 9361|    214|    upgrade.error = Error::WebSocketHandshake;
 9362|    214|    return false;
 9363|    214|  }
 9364|       |
 9365|       |  // Verify Connection: Upgrade
 9366|      0|  if (!has_header_token(headers, "Connection", "upgrade")) {
  ------------------
  |  Branch (9366:7): [True: 0, False: 0]
  ------------------
 9367|      0|    upgrade.error = Error::WebSocketHandshake;
 9368|      0|    return false;
 9369|      0|  }
 9370|       |
 9371|       |  // Verify Sec-WebSocket-Accept header value
 9372|      0|  auto it = headers.find("Sec-WebSocket-Accept");
 9373|      0|  if (it == headers.end() || it->second != expected_accept) {
  ------------------
  |  Branch (9373:7): [True: 0, False: 0]
  |  Branch (9373:7): [True: 0, False: 0]
  |  Branch (9373:30): [True: 0, False: 0]
  ------------------
 9374|      0|    upgrade.error = Error::WebSocketHandshake;
 9375|      0|    return false;
 9376|      0|  }
 9377|       |
 9378|       |  // Extract negotiated subprotocol
 9379|      0|  auto proto_it = headers.find("Sec-WebSocket-Protocol");
 9380|      0|  if (proto_it != headers.end()) {
  ------------------
  |  Branch (9380:7): [True: 0, False: 0]
  ------------------
 9381|      0|    upgrade.selected_subprotocol = proto_it->second;
 9382|      0|  }
 9383|       |
 9384|       |  // Verify the subprotocol is one the client offered (RFC 6455 4.1)
 9385|      0|  if (!upgrade.selected_subprotocol.empty()) {
  ------------------
  |  Branch (9385:7): [True: 0, False: 0]
  ------------------
 9386|      0|    auto was_offered = false;
 9387|      0|    split(offered_subprotocols.data(),
 9388|      0|          offered_subprotocols.data() + offered_subprotocols.size(), ',',
 9389|      0|          [&](const char *b, const char *e) {
 9390|      0|            if (std::string(b, e) == upgrade.selected_subprotocol) {
 9391|      0|              was_offered = true;
 9392|      0|            }
 9393|      0|          });
 9394|      0|    if (!was_offered) {
  ------------------
  |  Branch (9394:9): [True: 0, False: 0]
  ------------------
 9395|      0|      upgrade.error = Error::WebSocketHandshake;
 9396|      0|      return false;
 9397|      0|    }
 9398|      0|  }
 9399|       |
 9400|      0|  return true;
 9401|      0|}
_ZN7httplib6detail18read_response_headERNS_6StreamERiRNS0_26insertion_ordered_multimapINSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEENS0_11case_ignore8equal_toEEE:
 9326|  1.13k|inline bool read_response_head(Stream &strm, int &status, Headers &headers) {
 9327|  1.13k|  const auto bufsiz = 2048;
 9328|  1.13k|  char buf[bufsiz];
 9329|  1.13k|  stream_line_reader line_reader(strm, buf, bufsiz);
 9330|  1.13k|  if (!line_reader.getline()) { return false; }
  ------------------
  |  Branch (9330:7): [True: 1, False: 1.13k]
  ------------------
 9331|       |
 9332|  1.13k|  std::string version;
 9333|  1.13k|  std::string reason;
 9334|  1.13k|  if (!parse_status_line(line_reader.ptr(), version, status, reason)) {
  ------------------
  |  Branch (9334:7): [True: 245, False: 889]
  ------------------
 9335|    245|    return true;
 9336|    245|  }
 9337|    889|  return read_headers(strm, headers);
 9338|  1.13k|}
_ZN7httplib6detail18stream_line_readerC2ERNS_6StreamEPcm:
 6849|  2.02k|    : strm_(strm), fixed_buffer_(fixed_buffer),
 6850|  2.02k|      fixed_buffer_size_(fixed_buffer_size) {}
_ZN7httplib6detail18stream_line_reader7getlineEv:
 6873|  7.48k|inline bool stream_line_reader::getline() {
 6874|  7.48k|  fixed_buffer_used_size_ = 0;
 6875|  7.48k|  growable_buffer_.clear();
 6876|       |
 6877|  7.48k|#ifndef CPPHTTPLIB_ALLOW_LF_AS_LINE_TERMINATOR
 6878|  7.48k|  char prev_byte = 0;
 6879|  7.48k|#endif
 6880|       |
 6881|  1.11M|  for (size_t i = 0;; i++) {
 6882|       |    // Fast path: whatever the stream has already buffered can be scanned for
 6883|       |    // the terminator in one pass. Asking for a byte at a time costs a virtual
 6884|       |    // call, a bounds check and a one-byte copy per character of the request.
 6885|  1.11M|    size_t buffered_size = 0;
 6886|  1.11M|    if (auto buffered = strm_.buffered_data(buffered_size)) {
  ------------------
  |  Branch (6886:14): [True: 0, False: 1.11M]
  ------------------
 6887|      0|      auto take = buffered_size;
 6888|      0|      auto terminated = false;
 6889|       |
 6890|      0|      for (size_t at = 0; at < buffered_size;) {
  ------------------
  |  Branch (6890:27): [True: 0, False: 0]
  ------------------
 6891|      0|        auto nl = static_cast<const char *>(
 6892|      0|            memchr(buffered + at, '\n', buffered_size - at));
 6893|      0|        if (!nl) { break; }
  ------------------
  |  Branch (6893:13): [True: 0, False: 0]
  ------------------
 6894|      0|        auto pos = static_cast<size_t>(nl - buffered);
 6895|       |#ifdef CPPHTTPLIB_ALLOW_LF_AS_LINE_TERMINATOR
 6896|       |        take = pos + 1;
 6897|       |        terminated = true;
 6898|       |        break;
 6899|       |#else
 6900|       |        // A bare LF does not end the line; keep looking for CRLF. The CR may
 6901|       |        // be the last byte of an earlier chunk, hence prev_byte.
 6902|      0|        if ((pos > 0 ? buffered[pos - 1] : prev_byte) == '\r') {
  ------------------
  |  Branch (6902:13): [True: 0, False: 0]
  |  Branch (6902:14): [True: 0, False: 0]
  ------------------
 6903|      0|          take = pos + 1;
 6904|      0|          terminated = true;
 6905|      0|          break;
 6906|      0|        }
 6907|      0|        at = pos + 1;
 6908|      0|#endif
 6909|      0|      }
 6910|       |
 6911|      0|      if (size() + take > CPPHTTPLIB_MAX_LINE_LENGTH) { return false; }
  ------------------
  |  |  238|      0|#define CPPHTTPLIB_MAX_LINE_LENGTH 32768
  ------------------
  |  Branch (6911:11): [True: 0, False: 0]
  ------------------
 6912|      0|#ifndef CPPHTTPLIB_ALLOW_LF_AS_LINE_TERMINATOR
 6913|      0|      prev_byte = buffered[take - 1];
 6914|      0|#endif
 6915|      0|      append(buffered, take);
 6916|      0|      strm_.consume_buffered(take);
 6917|      0|      i += take;
 6918|      0|      if (terminated) { return true; }
  ------------------
  |  Branch (6918:11): [True: 0, False: 0]
  ------------------
 6919|      0|      continue;
 6920|      0|    }
 6921|       |
 6922|  1.11M|    if (size() >= CPPHTTPLIB_MAX_LINE_LENGTH) {
  ------------------
  |  |  238|  1.11M|#define CPPHTTPLIB_MAX_LINE_LENGTH 32768
  ------------------
  |  Branch (6922:9): [True: 1, False: 1.11M]
  ------------------
 6923|       |      // Treat exceptionally long lines as an error to
 6924|       |      // prevent infinite loops/memory exhaustion
 6925|      1|      return false;
 6926|      1|    }
 6927|  1.11M|    char byte;
 6928|  1.11M|    auto n = strm_.read(&byte, 1);
 6929|       |
 6930|  1.11M|    if (n < 0) {
  ------------------
  |  Branch (6930:9): [True: 0, False: 1.11M]
  ------------------
 6931|      0|      return false;
 6932|  1.11M|    } else if (n == 0) {
  ------------------
  |  Branch (6932:16): [True: 540, False: 1.11M]
  ------------------
 6933|    540|      if (i == 0) {
  ------------------
  |  Branch (6933:11): [True: 246, False: 294]
  ------------------
 6934|    246|        return false;
 6935|    294|      } else {
 6936|    294|        break;
 6937|    294|      }
 6938|    540|    }
 6939|       |
 6940|  1.11M|    append(byte);
 6941|       |
 6942|       |#ifdef CPPHTTPLIB_ALLOW_LF_AS_LINE_TERMINATOR
 6943|       |    if (byte == '\n') { break; }
 6944|       |#else
 6945|  1.11M|    if (prev_byte == '\r' && byte == '\n') { break; }
  ------------------
  |  Branch (6945:9): [True: 7.87k, False: 1.10M]
  |  Branch (6945:30): [True: 6.94k, False: 930]
  ------------------
 6946|  1.10M|    prev_byte = byte;
 6947|  1.10M|#endif
 6948|  1.10M|  }
 6949|       |
 6950|  7.24k|  return true;
 6951|  7.48k|}
_ZNK7httplib6detail18stream_line_reader4sizeEv:
 6860|  1.14M|inline size_t stream_line_reader::size() const {
 6861|  1.14M|  if (growable_buffer_.empty()) {
  ------------------
  |  Branch (6861:7): [True: 543k, False: 598k]
  ------------------
 6862|   543k|    return fixed_buffer_used_size_;
 6863|   598k|  } else {
 6864|   598k|    return growable_buffer_.size();
 6865|   598k|  }
 6866|  1.14M|}
_ZN7httplib6detail18stream_line_reader6appendEPKcm:
 6955|  1.11M|inline void stream_line_reader::append(const char *data, size_t size) {
 6956|       |  // Once the line has outgrown the fixed buffer everything must keep going to
 6957|       |  // the growable one, even if a later chunk would have fit. Without the
 6958|       |  // emptiness check a short append after a long one would land in the fixed
 6959|       |  // buffer, which ptr() and size() no longer look at, and be lost.
 6960|  1.11M|  if (growable_buffer_.empty() &&
  ------------------
  |  Branch (6960:7): [True: 514k, False: 597k]
  ------------------
 6961|   514k|      fixed_buffer_used_size_ + size < fixed_buffer_size_) {
  ------------------
  |  Branch (6961:7): [True: 514k, False: 189]
  ------------------
 6962|   514k|    memcpy(fixed_buffer_ + fixed_buffer_used_size_, data, size);
 6963|   514k|    fixed_buffer_used_size_ += size;
 6964|   514k|    fixed_buffer_[fixed_buffer_used_size_] = '\0';
 6965|   597k|  } else {
 6966|       |    // Unlike the per-character overload, this can be the very first append of
 6967|       |    // the line, so the fixed buffer may hold nothing and carry no terminator
 6968|       |    // yet. assign() takes an explicit length and does not need one.
 6969|   597k|    if (growable_buffer_.empty()) {
  ------------------
  |  Branch (6969:9): [True: 189, False: 597k]
  ------------------
 6970|    189|      growable_buffer_.assign(fixed_buffer_, fixed_buffer_used_size_);
 6971|    189|    }
 6972|   597k|    growable_buffer_.append(data, size);
 6973|   597k|  }
 6974|  1.11M|}
_ZN7httplib6detail18stream_line_reader6appendEc:
 6953|  1.11M|inline void stream_line_reader::append(char c) { append(&c, 1); }
_ZN7httplib6detail17parse_status_lineEPKcRNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEERiSA_:
 9286|  1.13k|                              int &status, std::string &reason) {
 9287|  1.13k|  if (std::strncmp(line, "HTTP/1.", 7) != 0 ||
  ------------------
  |  Branch (9287:7): [True: 118, False: 1.01k]
  ------------------
 9288|  1.01k|      (line[7] != '0' && line[7] != '1') || line[8] != ' ' ||
  ------------------
  |  Branch (9288:8): [True: 267, False: 749]
  |  Branch (9288:26): [True: 26, False: 241]
  |  Branch (9288:45): [True: 20, False: 970]
  ------------------
 9289|    970|      !is_ascii_digit(line[9]) || !is_ascii_digit(line[10]) ||
  ------------------
  |  Branch (9289:7): [True: 18, False: 952]
  |  Branch (9289:35): [True: 6, False: 946]
  ------------------
 9290|    946|      !is_ascii_digit(line[11])) {
  ------------------
  |  Branch (9290:7): [True: 1, False: 945]
  ------------------
 9291|    189|    return false;
 9292|    189|  }
 9293|       |
 9294|    945|  auto p = line + 12;
 9295|    945|  auto reason_begin = p;
 9296|    945|  if (*p == ' ') {
  ------------------
  |  Branch (9296:7): [True: 69, False: 876]
  ------------------
 9297|     69|    reason_begin = ++p;
 9298|     69|    p += std::strcspn(p, "\r\n");
 9299|     69|  }
 9300|    945|  auto reason_end = p;
 9301|       |
 9302|       |#ifdef CPPHTTPLIB_ALLOW_LF_AS_LINE_TERMINATOR
 9303|       |  if (*p == '\r') { p++; }
 9304|       |#else
 9305|    945|  if (*p++ != '\r') { return false; }
  ------------------
  |  Branch (9305:7): [True: 35, False: 910]
  ------------------
 9306|    910|#endif
 9307|    910|  if (*p++ != '\n' || *p != '\0') { return false; }
  ------------------
  |  Branch (9307:7): [True: 21, False: 889]
  |  Branch (9307:23): [True: 0, False: 889]
  ------------------
 9308|       |
 9309|    889|  version.assign(line, 8);
 9310|    889|  status = (line[9] - '0') * 100 + (line[10] - '0') * 10 + (line[11] - '0');
 9311|    889|  reason.assign(reason_begin, reason_end);
 9312|    889|  return true;
 9313|    910|}
_ZN7httplib6detail14is_ascii_digitEc:
  674|  68.5k|inline bool is_ascii_digit(char c) { return '0' <= c && c <= '9'; }
  ------------------
  |  Branch (674:45): [True: 36.7k, False: 31.7k]
  |  Branch (674:57): [True: 4.50k, False: 32.2k]
  ------------------
_ZNK7httplib6detail18stream_line_reader3ptrEv:
 6852|  18.8k|inline const char *stream_line_reader::ptr() const {
 6853|  18.8k|  if (growable_buffer_.empty()) {
  ------------------
  |  Branch (6853:7): [True: 18.4k, False: 452]
  ------------------
 6854|  18.4k|    return fixed_buffer_;
 6855|  18.4k|  } else {
 6856|    452|    return growable_buffer_.data();
 6857|    452|  }
 6858|  18.8k|}
_ZN7httplib6detail12read_headersERNS_6StreamERNS0_26insertion_ordered_multimapINSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS0_11case_ignore8equal_toEEE:
 9227|    889|inline bool read_headers(Stream &strm, Headers &headers) {
 9228|    889|  const auto bufsiz = 2048;
 9229|    889|  char buf[bufsiz];
 9230|    889|  stream_line_reader line_reader(strm, buf, bufsiz);
 9231|       |
 9232|    889|  size_t header_count = 0;
 9233|       |
 9234|  6.35k|  for (;;) {
 9235|  6.35k|    if (!line_reader.getline()) { return false; }
  ------------------
  |  Branch (9235:9): [True: 246, False: 6.10k]
  ------------------
 9236|       |
 9237|       |    // Check if the line ends with CRLF.
 9238|  6.10k|    auto line_terminator_len = 2;
 9239|  6.10k|    if (line_reader.end_with_crlf()) {
  ------------------
  |  Branch (9239:9): [True: 6.05k, False: 54]
  ------------------
 9240|       |      // Blank line indicates end of headers.
 9241|  6.05k|      if (line_reader.size() == 2) { break; }
  ------------------
  |  Branch (9241:11): [True: 243, False: 5.81k]
  ------------------
 9242|  6.05k|    } else {
 9243|       |#ifdef CPPHTTPLIB_ALLOW_LF_AS_LINE_TERMINATOR
 9244|       |      // Blank line indicates end of headers.
 9245|       |      if (line_reader.size() == 1) { break; }
 9246|       |      line_terminator_len = 1;
 9247|       |#else
 9248|     54|      continue; // Skip invalid line.
 9249|     54|#endif
 9250|     54|    }
 9251|       |
 9252|  5.81k|    if (line_reader.size() > CPPHTTPLIB_HEADER_MAX_LENGTH) { return false; }
  ------------------
  |  |  127|  5.81k|#define CPPHTTPLIB_HEADER_MAX_LENGTH 8192
  ------------------
  |  Branch (9252:9): [True: 4, False: 5.80k]
  ------------------
 9253|       |
 9254|       |    // Check header count limit
 9255|  5.80k|    if (header_count >= CPPHTTPLIB_HEADER_MAX_COUNT) { return false; }
  ------------------
  |  |  131|  5.80k|#define CPPHTTPLIB_HEADER_MAX_COUNT 100
  ------------------
  |  Branch (9255:9): [True: 1, False: 5.80k]
  ------------------
 9256|       |
 9257|       |    // Exclude line terminator
 9258|  5.80k|    auto end = line_reader.ptr() + line_reader.size() - line_terminator_len;
 9259|       |
 9260|  5.80k|    if (!parse_header(line_reader.ptr(), end,
  ------------------
  |  Branch (9260:9): [True: 395, False: 5.41k]
  ------------------
 9261|  5.80k|                      [&](const std::string &key, const std::string &val) {
 9262|  5.80k|                        headers.emplace(key, val);
 9263|  5.80k|                      })) {
 9264|    395|      return false;
 9265|    395|    }
 9266|       |
 9267|  5.41k|    header_count++;
 9268|  5.41k|  }
 9269|       |
 9270|       |  // RFC 9110 Section 8.6: Reject requests with multiple Content-Length
 9271|       |  // headers that have different values to prevent request smuggling.
 9272|    243|  auto cl_range = headers.equal_range("Content-Length");
 9273|    243|  if (cl_range.first != cl_range.second) {
  ------------------
  |  Branch (9273:7): [True: 0, False: 243]
  ------------------
 9274|      0|    const auto &first_val = cl_range.first->second;
 9275|      0|    for (auto it = std::next(cl_range.first); it != cl_range.second; ++it) {
  ------------------
  |  Branch (9275:47): [True: 0, False: 0]
  ------------------
 9276|      0|      if (it->second != first_val) { return false; }
  ------------------
  |  Branch (9276:11): [True: 0, False: 0]
  ------------------
 9277|      0|    }
 9278|      0|  }
 9279|       |
 9280|    243|  return true;
 9281|    243|}
_ZNK7httplib6detail18stream_line_reader13end_with_crlfEv:
 6868|  6.10k|inline bool stream_line_reader::end_with_crlf() const {
 6869|  6.10k|  auto end = ptr() + size();
 6870|  6.10k|  return size() >= 2 && end[-2] == '\r' && end[-1] == '\n';
  ------------------
  |  Branch (6870:10): [True: 6.08k, False: 25]
  |  Branch (6870:25): [True: 6.05k, False: 26]
  |  Branch (6870:44): [True: 6.05k, False: 3]
  ------------------
 6871|  6.10k|}
_ZN7httplib6detail12parse_headerIZNS0_12read_headersERNS_6StreamERNS0_26insertion_ordered_multimapINSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEENS0_11case_ignore8equal_toEEEEUlRKSB_SH_E_EEbPKcSK_T_:
 6531|  5.80k|inline bool parse_header(const char *beg, const char *end, T fn) {
 6532|       |  // Skip trailing spaces and tabs.
 6533|  6.18k|  while (beg < end && is_space_or_tab(end[-1])) {
  ------------------
  |  Branch (6533:10): [True: 6.17k, False: 12]
  |  Branch (6533:23): [True: 381, False: 5.79k]
  ------------------
 6534|    381|    end--;
 6535|    381|  }
 6536|       |
 6537|  5.80k|  auto p = beg;
 6538|   198k|  while (p < end && *p != ':') {
  ------------------
  |  Branch (6538:10): [True: 198k, False: 312]
  |  Branch (6538:21): [True: 193k, False: 5.49k]
  ------------------
 6539|   193k|    p++;
 6540|   193k|  }
 6541|       |
 6542|  5.80k|  auto name = std::string(beg, p);
 6543|  5.80k|  if (!detail::fields::is_field_name(name)) { return false; }
  ------------------
  |  Branch (6543:7): [True: 161, False: 5.64k]
  ------------------
 6544|       |
 6545|  5.64k|  if (p == end) { return false; }
  ------------------
  |  Branch (6545:7): [True: 171, False: 5.47k]
  ------------------
 6546|       |
 6547|  5.47k|  auto key_end = p;
 6548|       |
 6549|  5.47k|  if (*p++ != ':') { return false; }
  ------------------
  |  Branch (6549:7): [True: 0, False: 5.47k]
  ------------------
 6550|       |
 6551|  5.86k|  while (p < end && is_space_or_tab(*p)) {
  ------------------
  |  Branch (6551:10): [True: 1.51k, False: 4.35k]
  |  Branch (6551:21): [True: 391, False: 1.12k]
  ------------------
 6552|    391|    p++;
 6553|    391|  }
 6554|       |
 6555|  5.47k|  if (p <= end) {
  ------------------
  |  Branch (6555:7): [True: 5.47k, False: 0]
  ------------------
 6556|  5.47k|    auto key_len = key_end - beg;
 6557|  5.47k|    if (!key_len) { return false; }
  ------------------
  |  Branch (6557:9): [True: 0, False: 5.47k]
  ------------------
 6558|       |
 6559|  5.47k|    auto key = std::string(beg, key_end);
 6560|  5.47k|    auto val = std::string(p, end);
 6561|       |
 6562|  5.47k|    if (!detail::fields::is_field_value(val)) { return false; }
  ------------------
  |  Branch (6562:9): [True: 63, False: 5.41k]
  ------------------
 6563|       |
 6564|       |    // RFC 9110 §5.5: header field values are opaque octets and MUST NOT be
 6565|       |    // percent-decoded by the recipient. Applications that need to interpret a
 6566|       |    // value as a URI component should call httplib::decode_uri_component()
 6567|       |    // (or decode_path_component()) explicitly.
 6568|  5.41k|    fn(key, val);
 6569|       |
 6570|  5.41k|    return true;
 6571|  5.47k|  }
 6572|       |
 6573|      0|  return false;
 6574|  5.47k|}
_ZN7httplib6detail15is_space_or_tabEc:
 6525|  62.6k|inline bool is_space_or_tab(char c) { return c == ' ' || c == '\t'; }
  ------------------
  |  Branch (6525:46): [True: 4.89k, False: 57.7k]
  |  Branch (6525:58): [True: 14.0k, False: 43.6k]
  ------------------
_ZN7httplib6detail6fields13is_field_nameERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE:
11270|  5.80k|inline bool is_field_name(const std::string &s) { return is_token(s); }
_ZN7httplib6detail6fields8is_tokenERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE:
11262|  5.80k|inline bool is_token(const std::string &s) {
11263|  5.80k|  if (s.empty()) { return false; }
  ------------------
  |  Branch (11263:7): [True: 26, False: 5.78k]
  ------------------
11264|  65.6k|  for (auto c : s) {
  ------------------
  |  Branch (11264:15): [True: 65.6k, False: 5.64k]
  ------------------
11265|  65.6k|    if (!is_token_char(c)) { return false; }
  ------------------
  |  Branch (11265:9): [True: 135, False: 65.5k]
  ------------------
11266|  65.6k|  }
11267|  5.64k|  return true;
11268|  5.78k|}
_ZN7httplib6detail6fields13is_token_charEc:
11256|  65.6k|inline bool is_token_char(char c) {
11257|  65.6k|  return is_ascii_alnum(c) || c == '!' || c == '#' || c == '$' || c == '%' ||
  ------------------
  |  Branch (11257:10): [True: 29.1k, False: 36.5k]
  |  Branch (11257:31): [True: 537, False: 35.9k]
  |  Branch (11257:43): [True: 1.50k, False: 34.4k]
  |  Branch (11257:55): [True: 535, False: 33.9k]
  |  Branch (11257:67): [True: 627, False: 33.3k]
  ------------------
11258|  33.3k|         c == '&' || c == '\'' || c == '*' || c == '+' || c == '-' ||
  ------------------
  |  Branch (11258:10): [True: 447, False: 32.8k]
  |  Branch (11258:22): [True: 17.6k, False: 15.2k]
  |  Branch (11258:35): [True: 611, False: 14.6k]
  |  Branch (11258:47): [True: 8.59k, False: 6.06k]
  |  Branch (11258:59): [True: 830, False: 5.23k]
  ------------------
11259|  5.23k|         c == '.' || c == '^' || c == '_' || c == '`' || c == '|' || c == '~';
  ------------------
  |  Branch (11259:10): [True: 352, False: 4.88k]
  |  Branch (11259:22): [True: 2.04k, False: 2.83k]
  |  Branch (11259:34): [True: 679, False: 2.15k]
  |  Branch (11259:46): [True: 379, False: 1.77k]
  |  Branch (11259:58): [True: 353, False: 1.42k]
  |  Branch (11259:70): [True: 1.28k, False: 135]
  ------------------
11260|  65.6k|}
_ZN7httplib6detail14is_ascii_alnumEc:
  680|  65.6k|inline bool is_ascii_alnum(char c) {
  681|  65.6k|  return is_ascii_digit(c) || is_ascii_alpha(c);
  ------------------
  |  Branch (681:10): [True: 1.66k, False: 63.9k]
  |  Branch (681:31): [True: 27.4k, False: 36.5k]
  ------------------
  682|  65.6k|}
_ZN7httplib6detail14is_ascii_alphaEc:
  676|  63.9k|inline bool is_ascii_alpha(char c) {
  677|  63.9k|  return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
  ------------------
  |  Branch (677:11): [True: 10.5k, False: 53.4k]
  |  Branch (677:23): [True: 8.90k, False: 1.64k]
  |  Branch (677:37): [True: 23.3k, False: 31.7k]
  |  Branch (677:49): [True: 18.5k, False: 4.75k]
  ------------------
  678|  63.9k|}
_ZN7httplib6detail6fields14is_field_valueERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE:
11303|  5.47k|inline bool is_field_value(const std::string &s) { return is_field_content(s); }
_ZN7httplib6detail6fields16is_field_contentERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE:
11278|  5.47k|inline bool is_field_content(const std::string &s) {
11279|  5.47k|  if (s.empty()) { return true; }
  ------------------
  |  Branch (11279:7): [True: 4.35k, False: 1.12k]
  ------------------
11280|       |
11281|  1.12k|  if (s.size() == 1) {
  ------------------
  |  Branch (11281:7): [True: 380, False: 742]
  ------------------
11282|    380|    return is_field_vchar(s[0]);
11283|    742|  } else if (s.size() == 2) {
  ------------------
  |  Branch (11283:14): [True: 179, False: 563]
  ------------------
11284|    179|    return is_field_vchar(s[0]) && is_field_vchar(s[1]);
  ------------------
  |  Branch (11284:12): [True: 178, False: 1]
  |  Branch (11284:36): [True: 175, False: 3]
  ------------------
11285|    563|  } else {
11286|    563|    size_t i = 0;
11287|       |
11288|    563|    if (!is_field_vchar(s[i])) { return false; }
  ------------------
  |  Branch (11288:9): [True: 5, False: 558]
  ------------------
11289|    558|    i++;
11290|       |
11291|   223k|    while (i < s.size() - 1) {
  ------------------
  |  Branch (11291:12): [True: 223k, False: 523]
  ------------------
11292|   223k|      auto c = s[i++];
11293|   223k|      if (c == ' ' || c == '\t' || is_field_vchar(c)) {
  ------------------
  |  Branch (11293:11): [True: 8.26k, False: 214k]
  |  Branch (11293:23): [True: 8.71k, False: 206k]
  |  Branch (11293:36): [True: 206k, False: 35]
  ------------------
11294|   223k|      } else {
11295|     35|        return false;
11296|     35|      }
11297|   223k|    }
11298|       |
11299|    523|    return is_field_vchar(s[i]);
11300|    558|  }
11301|  1.12k|}
_ZN7httplib6detail6fields14is_field_vcharEc:
11276|   207k|inline bool is_field_vchar(char c) { return is_vchar(c) || is_obs_text(c); }
  ------------------
  |  Branch (11276:45): [True: 166k, False: 40.9k]
  |  Branch (11276:60): [True: 40.9k, False: 63]
  ------------------
_ZN7httplib6detail6fields8is_vcharEc:
11272|   207k|inline bool is_vchar(char c) { return c >= 33 && c <= 126; }
  ------------------
  |  Branch (11272:39): [True: 166k, False: 40.9k]
  |  Branch (11272:50): [True: 166k, False: 3]
  ------------------
_ZN7httplib6detail6fields11is_obs_textEc:
11274|  40.9k|inline bool is_obs_text(char c) { return 128 <= static_cast<unsigned char>(c); }
_ZZN7httplib6detail12read_headersERNS_6StreamERNS0_26insertion_ordered_multimapINSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS0_11case_ignore8equal_toEEEENKUlRKSA_SG_E_clESG_SG_:
 9261|  5.41k|                      [&](const std::string &key, const std::string &val) {
 9262|  5.41k|                        headers.emplace(key, val);
 9263|  5.41k|                      })) {
_ZN7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE7emplaceIJRKS8_SE_EEENSB_10iterator_tINS2_4pairIS8_S8_EEEEDpOT_:
 1328|  5.41k|  template <typename... Args> iterator emplace(Args &&...args) {
 1329|  5.41k|    entries_.emplace_back(std::forward<Args>(args)...);
 1330|  5.41k|    return make_iter(entries_.size() - 1, npos());
 1331|  5.41k|  }
_ZN7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE9make_iterEmm:
 1437|  5.89k|  iterator make_iter(size_type idx, size_type key_idx) {
 1438|  5.89k|    return iterator(entries_.data(), idx, entries_.size(), key_idx);
 1439|  5.89k|  }
_ZN7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE10iterator_tINS2_4pairIS8_S8_EEEC2EPSE_mmm:
 1283|  5.89k|        : data_(data), idx_(idx), size_(size), key_idx_(key_idx) {}
_ZN7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE4nposEv:
 1203|  7.61k|  static size_type npos() { return static_cast<size_type>(-1); }
_ZN7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE11equal_rangeERKS8_:
 1358|    243|  std::pair<iterator, iterator> equal_range(const std::string &key) {
 1359|    243|    auto i = index_of(key);
 1360|    243|    return i == npos() ? std::make_pair(end(), end())
  ------------------
  |  Branch (1360:12): [True: 243, False: 0]
  ------------------
 1361|    243|                       : std::make_pair(make_iter(i, i), end());
 1362|    243|  }
_ZNK7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE8index_ofERKS8_:
 1430|    457|  size_type index_of(const std::string &key) const {
 1431|  3.41k|    for (size_type i = 0; i < entries_.size(); i++) {
  ------------------
  |  Branch (1431:27): [True: 3.11k, False: 297]
  ------------------
 1432|  3.11k|      if (keys_equal(entries_[i].first, key)) { return i; }
  ------------------
  |  Branch (1432:11): [True: 160, False: 2.95k]
  ------------------
 1433|  3.11k|    }
 1434|    297|    return npos();
 1435|    457|  }
_ZN7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE10keys_equalERKS8_SD_:
 1205|  4.07k|  static bool keys_equal(const std::string &a, const std::string &b) {
 1206|  4.07k|    return KeyEqual()(a, b);
 1207|  4.07k|  }
_ZNK7httplib6detail11case_ignore8equal_toclERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESB_:
  735|  4.07k|  bool operator()(const std::string &a, const std::string &b) const {
  736|  4.07k|    return equal(a, b);
  737|  4.07k|  }
_ZN7httplib6detail11case_ignore5equalERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEESA_:
  718|  6.99k|inline bool equal(const std::string &a, const std::string &b) {
  719|  6.99k|  return a.size() == b.size() &&
  ------------------
  |  Branch (719:10): [True: 1.39k, False: 5.59k]
  ------------------
  720|  1.39k|         std::equal(a.begin(), a.end(), b.begin(), [](char ca, char cb) {
  ------------------
  |  Branch (720:10): [True: 698, False: 701]
  ------------------
  721|  1.39k|           return to_lower(ca) == to_lower(cb);
  722|  1.39k|         });
  723|  6.99k|}
_ZZN7httplib6detail11case_ignore5equalERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEESA_ENKUlccE_clEcc:
  720|  6.14k|         std::equal(a.begin(), a.end(), b.begin(), [](char ca, char cb) {
  721|  6.14k|           return to_lower(ca) == to_lower(cb);
  722|  6.14k|         });
_ZN7httplib6detail11case_ignore8to_lowerEi:
  686|  12.2k|inline unsigned char to_lower(int c) {
  687|  12.2k|  const static unsigned char table[256] = {
  688|  12.2k|      0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   10,  11,  12,  13,  14,
  689|  12.2k|      15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,  29,
  690|  12.2k|      30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,
  691|  12.2k|      45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,
  692|  12.2k|      60,  61,  62,  63,  64,  97,  98,  99,  100, 101, 102, 103, 104, 105, 106,
  693|  12.2k|      107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
  694|  12.2k|      122, 91,  92,  93,  94,  95,  96,  97,  98,  99,  100, 101, 102, 103, 104,
  695|  12.2k|      105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
  696|  12.2k|      120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
  697|  12.2k|      135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
  698|  12.2k|      150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
  699|  12.2k|      165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
  700|  12.2k|      180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 224, 225, 226,
  701|  12.2k|      227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241,
  702|  12.2k|      242, 243, 244, 245, 246, 215, 248, 249, 250, 251, 252, 253, 254, 223, 224,
  703|  12.2k|      225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
  704|  12.2k|      240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
  705|  12.2k|      255,
  706|  12.2k|  };
  707|  12.2k|  return table[(unsigned char)(char)c];
  708|  12.2k|}
_ZN7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE3endEv:
 1307|    486|  iterator end() { return make_iter(entries_.size(), npos()); }
_ZNK7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE10iterator_tINS2_4pairIS8_S8_EEEneISE_EEbRKNSC_IT_EE:
 1274|    243|    template <typename U> bool operator!=(const iterator_t<U> &rhs) const {
 1275|    243|      return idx_ != rhs.idx_;
 1276|    243|    }
_ZN7httplib6detail16has_header_tokenERKNS0_26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEEERKS8_SF_:
 9183|    214|                             const std::string &token) {
 9184|       |  // RFC 9110 7.6.1: a comma-separated token list field such as Connection may
 9185|       |  // carry several tokens, and RFC 9110 5.3 lets that list be split across
 9186|       |  // several lines. Match complete tokens rather than searching the raw value,
 9187|       |  // so that a value such as "notupgrade" is not read as the token "upgrade".
 9188|    214|  auto rng = headers.equal_range(key);
 9189|    912|  for (auto it = rng.first; it != rng.second; ++it) {
  ------------------
  |  Branch (9189:29): [True: 698, False: 214]
  ------------------
 9190|    698|    const auto &value = it->second;
 9191|    698|    if (split_find(value.data(), value.data() + value.size(), ',',
  ------------------
  |  Branch (9191:9): [True: 0, False: 698]
  ------------------
 9192|    698|                   [&](const char *b, const char *e) {
 9193|    698|                     return case_ignore::equal(std::string(b, e), token);
 9194|    698|                   })) {
 9195|      0|      return true;
 9196|      0|    }
 9197|    698|  }
 9198|    214|  return false;
 9199|    214|}
_ZNK7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE11equal_rangeERKS8_:
 1365|    214|  equal_range(const std::string &key) const {
 1366|    214|    auto i = index_of(key);
 1367|    214|    return i == npos() ? std::make_pair(end(), end())
  ------------------
  |  Branch (1367:12): [True: 54, False: 160]
  ------------------
 1368|    214|                       : std::make_pair(make_citer(i, i), end());
 1369|    214|  }
_ZNK7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE10make_citerEmm:
 1441|    428|  const_iterator make_citer(size_type idx, size_type key_idx) const {
 1442|    428|    return const_iterator(entries_.data(), idx, entries_.size(), key_idx);
 1443|    428|  }
_ZN7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE10iterator_tIKNS2_4pairIS8_S8_EEEC2EPSF_mmm:
 1283|    428|        : data_(data), idx_(idx), size_(size), key_idx_(key_idx) {}
_ZN7httplib6detail10split_findEPKcS2_cNSt3__18functionIFbS2_S2_EEE:
 6842|    698|                       std::function<bool(const char *, const char *)> fn) {
 6843|    698|  return split_find(b, e, d, (std::numeric_limits<size_t>::max)(),
 6844|    698|                    std::move(fn));
 6845|    698|}
_ZN7httplib6detail10split_findEPKcS2_cmNSt3__18functionIFbS2_S2_EEE:
 6812|    698|                       std::function<bool(const char *, const char *)> fn) {
 6813|    698|  size_t i = 0;
 6814|    698|  size_t beg = 0;
 6815|    698|  size_t count = 1;
 6816|       |
 6817|  48.0k|  while (e ? (b + i < e) : (b[i] != '\0')) {
  ------------------
  |  Branch (6817:10): [True: 48.0k, False: 0]
  |  Branch (6817:10): [True: 47.3k, False: 698]
  ------------------
 6818|  47.3k|    if (b[i] == d && count < m) {
  ------------------
  |  Branch (6818:9): [True: 18.0k, False: 29.3k]
  |  Branch (6818:22): [True: 18.0k, False: 0]
  ------------------
 6819|  18.0k|      auto r = trim(b, e, beg, i);
 6820|  18.0k|      if (r.first < r.second) {
  ------------------
  |  Branch (6820:11): [True: 2.53k, False: 15.5k]
  ------------------
 6821|  2.53k|        auto found = fn(&b[r.first], &b[r.second]);
 6822|  2.53k|        if (found) { return true; }
  ------------------
  |  Branch (6822:13): [True: 0, False: 2.53k]
  ------------------
 6823|  2.53k|      }
 6824|  18.0k|      beg = i + 1;
 6825|  18.0k|      count++;
 6826|  18.0k|    }
 6827|  47.3k|    i++;
 6828|  47.3k|  }
 6829|       |
 6830|    698|  if (i) {
  ------------------
  |  Branch (6830:7): [True: 533, False: 165]
  ------------------
 6831|    533|    auto r = trim(b, e, beg, i);
 6832|    533|    if (r.first < r.second) {
  ------------------
  |  Branch (6832:9): [True: 391, False: 142]
  ------------------
 6833|    391|      auto found = fn(&b[r.first], &b[r.second]);
 6834|    391|      if (found) { return true; }
  ------------------
  |  Branch (6834:11): [True: 0, False: 391]
  ------------------
 6835|    391|    }
 6836|    533|  }
 6837|       |
 6838|    698|  return false;
 6839|    698|}
_ZN7httplib6detail4trimEPKcS2_mm:
 6672|  18.5k|                                      size_t right) {
 6673|  27.6k|  while (b + left < e && is_space_or_tab(b[left])) {
  ------------------
  |  Branch (6673:10): [True: 27.5k, False: 142]
  |  Branch (6673:26): [True: 9.09k, False: 18.4k]
  ------------------
 6674|  9.09k|    left++;
 6675|  9.09k|  }
 6676|  27.6k|  while (right > 0 && is_space_or_tab(b[right - 1])) {
  ------------------
  |  Branch (6676:10): [True: 27.4k, False: 254]
  |  Branch (6676:23): [True: 9.12k, False: 18.3k]
  ------------------
 6677|  9.12k|    right--;
 6678|  9.12k|  }
 6679|  18.5k|  return std::make_pair(left, right);
 6680|  18.5k|}
_ZZN7httplib6detail16has_header_tokenERKNS0_26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEEERKS8_SF_ENKUlPKcSH_E_clESH_SH_:
 9192|  2.92k|                   [&](const char *b, const char *e) {
 9193|  2.92k|                     return case_ignore::equal(std::string(b, e), token);
 9194|  2.92k|                   })) {
_ZN7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE10iterator_tIKNS2_4pairIS8_S8_EEEppEv:
 1234|    698|    iterator_t &operator++() {
 1235|       |      // Saturating, so that advancing past the last entry of a key stays at
 1236|       |      // end() instead of running off the container.
 1237|    698|      if (idx_ >= size_) { return *this; }
  ------------------
  |  Branch (1237:11): [True: 0, False: 698]
  ------------------
 1238|    698|      ++idx_;
 1239|    698|      if (key_idx_ != npos()) {
  ------------------
  |  Branch (1239:11): [True: 698, False: 0]
  ------------------
 1240|  1.11k|        while (idx_ < size_ && !matches(idx_)) {
  ------------------
  |  Branch (1240:16): [True: 956, False: 160]
  |  Branch (1240:32): [True: 418, False: 538]
  ------------------
 1241|    418|          ++idx_;
 1242|    418|        }
 1243|    698|      }
 1244|    698|      return *this;
 1245|    698|    }
_ZNK7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE10iterator_tIKNS2_4pairIS8_S8_EEE7matchesEm:
 1285|    956|    bool matches(size_type i) const {
 1286|    956|      return keys_equal(data_[i].first, data_[key_idx_].first);
 1287|    956|    }
_ZNK7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE3endEv:
 1309|    268|  const_iterator end() const { return make_citer(entries_.size(), npos()); }
_ZNK7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE10iterator_tIKNS2_4pairIS8_S8_EEEptEv:
 1232|    698|    pointer operator->() const { return data_ + idx_; }
_ZNK7httplib6detail26insertion_ordered_multimapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS0_11case_ignore8equal_toEE10iterator_tIKNS2_4pairIS8_S8_EEEneISF_EEbRKNSC_IT_EE:
 1274|    912|    template <typename U> bool operator!=(const iterator_t<U> &rhs) const {
 1275|    912|      return idx_ != rhs.idx_;
 1276|    912|    }
_ZN7httplib6detail12BufferStream4readEPcm:
13697|  1.11M|inline ssize_t BufferStream::read(char *ptr, size_t size) {
13698|       |#if defined(_MSC_VER) && _MSC_VER < 1910
13699|       |  auto len_read = buffer._Copy_s(ptr, size, size, position);
13700|       |#else
13701|  1.11M|  auto len_read = buffer.copy(ptr, size, position);
13702|  1.11M|#endif
13703|  1.11M|  position += static_cast<size_t>(len_read);
13704|  1.11M|  return static_cast<ssize_t>(len_read);
13705|  1.11M|}
_ZNK7httplib6Stream13buffered_dataERm:
 2081|  1.11M|  virtual const char *buffered_data(size_t &size) const {
 2082|  1.11M|    size = 0;
 2083|  1.11M|    return nullptr;
 2084|  1.11M|  }

LLVMFuzzerTestOneInput:
    6|  1.73k|extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
    7|  1.73k|  if (size < 2) { return 0; }
  ------------------
  |  Branch (7:7): [True: 1, False: 1.73k]
  ------------------
    8|       |
    9|  1.73k|  auto selector = data[0];
   10|  1.73k|  std::string input(reinterpret_cast<const char *>(data + 1), size - 1);
   11|       |
   12|  1.73k|  switch (selector % 4) {
  ------------------
  |  Branch (12:11): [True: 1.73k, False: 0]
  ------------------
   13|    271|  case 0: {
  ------------------
  |  Branch (13:3): [True: 271, False: 1.46k]
  ------------------
   14|       |    // read_websocket_frame. WebSocket::read passes the macro, close() passes
   15|       |    // 125, and 0 means no limit
   16|    271|    static const size_t max_lens[] = {0, 125,
   17|    271|                                      CPPHTTPLIB_WEBSOCKET_MAX_PAYLOAD_LENGTH};
  ------------------
  |  |  252|    271|#define CPPHTTPLIB_WEBSOCKET_MAX_PAYLOAD_LENGTH 16777216
  ------------------
   18|    271|    auto expect_masked = (selector / 4) % 2 != 0;
   19|    271|    auto max_len = max_lens[(selector / 8) % 3];
   20|    271|    httplib::detail::BufferStream strm;
   21|    271|    strm.write(input.data(), input.size());
   22|    271|    auto opcode = httplib::ws::Opcode::Text;
   23|    271|    std::string payload;
   24|    271|    auto fin = false;
   25|    271|    httplib::ws::impl::read_websocket_frame(strm, opcode, payload, fin,
   26|    271|                                            expect_masked, max_len);
   27|    271|    break;
   28|      0|  }
   29|    228|  case 1: {
  ------------------
  |  Branch (29:3): [True: 228, False: 1.50k]
  ------------------
   30|       |    // is_valid_utf8
   31|    228|    httplib::ws::impl::is_valid_utf8(input);
   32|    228|    break;
   33|      0|  }
   34|    100|  case 2: {
  ------------------
  |  Branch (34:3): [True: 100, False: 1.63k]
  ------------------
   35|       |    // is_valid_close_payload
   36|    100|    httplib::ws::impl::is_valid_close_payload(input);
   37|    100|    break;
   38|      0|  }
   39|  1.13k|  case 3: {
  ------------------
  |  Branch (39:3): [True: 1.13k, False: 599]
  ------------------
   40|       |    // read_websocket_upgrade_response, with a fixed key since
   41|       |    // perform_websocket_handshake draws a random one
   42|  1.13k|    static const auto expected_accept =
   43|  1.13k|        httplib::detail::websocket_accept_key("dGhlIHNhbXBsZSBub25jZQ==");
   44|  1.13k|    httplib::detail::BufferStream strm;
   45|  1.13k|    strm.write(input.data(), input.size());
   46|  1.13k|    httplib::detail::WebSocketUpgradeResponse upgrade;
   47|  1.13k|    httplib::detail::read_websocket_upgrade_response(strm, expected_accept,
   48|  1.13k|                                                     "chat, stream", upgrade);
   49|  1.13k|    break;
   50|      0|  }
   51|  1.73k|  }
   52|       |
   53|  1.73k|  return 0;
   54|  1.73k|}

