void HTTPHeaders::stripPerHopHeaders()

in proxygen/lib/http/HTTPHeaders.cpp [255:316]


void HTTPHeaders::stripPerHopHeaders(HTTPHeaders& strippedHeaders) {
  int len;
  forEachValueOfHeader(
      HTTP_HEADER_CONNECTION, [&](const string& stdStr) -> bool {
        // Remove all headers specified in Connection header
        // look for multiple values separated by commas
        char const* str = stdStr.c_str();

        // skip leading whitespace
        while (isLWS(*str))
          str++;

        while (*str != 0) {
          char const* pos = strchr(str, ',');
          if (pos == nullptr) {
            // last (or only) token, done

            // count chars in the token
            len = 0;
            while (str[len] != 0 && !isLWS(str[len]))
              len++;
            if (len > 0) {
              string hdr(str, len);
              if (transferHeaderIfPresent(hdr, strippedHeaders)) {
                VLOG(3) << "Stripped connection-named hop-by-hop header "
                        << hdr;
              }
            }
            break;
          }
          len = pos - str;
          // strip trailing whitespace
          while (len > 0 && isLWS(str[len - 1]))
            len--;
          if (len > 0) {
            // non-empty token
            string hdr(str, len);
            if (transferHeaderIfPresent(hdr, strippedHeaders)) {
              VLOG(3) << "Stripped connection-named hop-by-hop header " << hdr;
            }
          } // else empty token, no-op
          str = pos + 1;

          // skip whitespace
          while (isLWS(*str))
            str++;
        }
        return false; // continue processing "connection" headers
      });

  // Strip hop-by-hop headers
  auto& perHopHeaders = perHopHeaderCodes();
  for (size_t i = 0; i < length_; ++i) {
    if (perHopHeaders[codes()[i]]) {
      strippedHeaders.emplace_back(
          codes()[i], names()[i], std::move(values()[i]));
      codes()[i] = HTTP_HEADER_NONE;
      ++deletedCount_;
      VLOG(5) << "Stripped hop-by-hop header " << *names()[i];
    }
  }
}