コード例 #1
0
ファイル: HTTPArchive.cpp プロジェクト: viswanathgs/proxygen
unique_ptr<HTTPArchive> HTTPArchive::fromFile(const string& filename) {
  unique_ptr<HTTPArchive> har = folly::make_unique<HTTPArchive>();
  auto buffer = readFileToIOBuf(filename);
  if (!buffer) {
    return nullptr;
  }
  folly::dynamic jsonObj = folly::parseJson((const char *)buffer->data());
  auto entries = jsonObj["log"]["entries"];
  vector<HPACKHeader> msg;
  // go over all the transactions
  for (size_t i = 0; i < entries.size(); i++) {
    extractHeaders(entries[i]["request"], msg);
    if (!msg.empty()) {
      har->requests.push_back(msg);
    }
    extractHeaders(entries[i]["response"], msg);
    if (!msg.empty()) {
      har->responses.push_back(msg);
    }
  }

  return har;
}
コード例 #2
0
bool MTD_FLASHMEM HTTPHandler::processRequest() {
  // look for 0x0D 0x0A 0x0D 0x0A
  CharChunksIterator headerEnd =
      t_strstr(m_receivedData.getIterator(), CharChunksIterator(), CharIterator(FSTR("\x0D\x0A\x0D\x0A")));
  if (headerEnd.isValid()) {
    // move header end after CRLFCRLF
    headerEnd += 4;

    CharChunksIterator curc = m_receivedData.getIterator();

    // extract method (GET, POST, etc..)
    CharChunksIterator method = curc;
    while (curc != headerEnd && *curc != ' ')
      ++curc;
    *curc++ = 0; // ends method
    if (t_strcmp(method, CharIterator(FSTR("GET"))) == 0)
      m_request.method = Get;
    else if (t_strcmp(method, CharIterator(FSTR("POST"))) == 0)
      m_request.method = Post;
    else if (t_strcmp(method, CharIterator(FSTR("HEAD"))) == 0)
      m_request.method = Head;
    else
      m_request.method = Unsupported;

    // extract requested page and query parameters
    m_request.requestedPage = curc;
    while (curc != headerEnd) {
      if (*curc == '?') {
        *curc++ = 0; // ends requestedPage
        curc = extractURLEncodedFields(curc, headerEnd, &m_request.query);
        break;
      } else if (*curc == ' ') {
        *curc++ = 0; // ends requestedPage
        break;
      }
      ++curc;
    }

    // bypass HTTP version
    while (curc != headerEnd && *curc != 0x0D)
      ++curc;

    // extract headers
    curc = extractHeaders(curc, headerEnd, &m_request.headers);

    // get content length (may be NULL)
    char const *contentLengthStr = m_request.headers[STR_Content_Length];
    int32_t contentLength = contentLengthStr ? strtol(contentLengthStr, NULL, 10) : 0;

    if (m_request.method == Post) {
      // check content type (POST)
      char const *contentType = m_request.headers[STR_Content_Type];
      if (contentType && f_strstr(contentType, FSTR("multipart/form-data"))) {
        //// content type is multipart/form-data
        processMultipartFormData(headerEnd, contentLength, contentType);
      } else if (contentType == NULL ||
                 (contentType && f_strstr(contentType, FSTR("application/x-www-form-urlencoded")))) {
        //// content type is application/x-www-form-urlencoded
        processXWWWFormUrlEncoded(headerEnd, contentLength);
      }
    } else
      dispatch();

    return true;
  } else {
    // header is not complete
    return false;
  }
}