proxygen
proxygen::HTTPArchive Class Reference

#include <HTTPArchive.h>

Static Public Member Functions

static std::vector< std::vector< HPACKHeader > > convertToHPACK (const std::vector< HTTPMessage > &msgs)
 
static std::unique_ptr< HTTPArchivefromFile (const std::string &filename)
 
static std::unique_ptr< HTTPArchivefromPublicFile (const std::string &fname)
 
static uint32_t getSize (const HTTPMessage &msg)
 
static uint32_t getSize (const std::vector< HPACKHeader > &headers)
 

Public Attributes

std::vector< HTTPMessagerequests
 
std::vector< HTTPMessageresponses
 

Detailed Description

Definition at line 22 of file HTTPArchive.h.

Member Function Documentation

std::vector< std::vector< HPACKHeader > > proxygen::HTTPArchive::convertToHPACK ( const std::vector< HTTPMessage > &  msgs)
static

Definition at line 210 of file HTTPArchive.cpp.

References proxygen::HTTPHeaders::forEach(), proxygen::HTTPMessage::getHeaders(), and folly::gen::move.

211  {
212  std::vector<std::vector<HPACKHeader>> result;
213  for (const HTTPMessage& msg: msgs) {
214  std::vector<HPACKHeader> headers;
215  msg.getHeaders().forEach(
216  [&headers] (const string& name, const string& value) {
217  headers.emplace_back(name, value);
218  });
219  result.emplace_back(std::move(headers));
220  }
221  return result;
222 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const char * name
Definition: http_parser.c:437
static const char *const value
Definition: Conv.cpp:50
unique_ptr< HTTPArchive > proxygen::HTTPArchive::fromFile ( const std::string filename)
static

Definition at line 148 of file HTTPArchive.cpp.

References buffer(), proxygen::HTTPMessage::getHeaders(), i, folly::parseJson(), proxygen::readFileToIOBuf(), and proxygen::HTTPHeaders::size().

148  {
149  unique_ptr<HTTPArchive> har = std::make_unique<HTTPArchive>();
150  auto buffer = readFileToIOBuf(filename);
151  if (!buffer) {
152  return nullptr;
153  }
154  folly::dynamic jsonObj = folly::parseJson((const char *)buffer->data());
155  auto entries = jsonObj["log"]["entries"];
156  // go over all the transactions
157  for (size_t i = 0; i < entries.size(); i++) {
158  HTTPMessage msg = extractMessage(entries[i]["request"],
159  entries[i]["startedDateTime"].asString(),
160  true);
161  if (msg.getHeaders().size() != 0) {
162  har->requests.push_back(msg);
163  }
164  msg = extractMessage(entries[i]["response"], "", false);
165  if (msg.getHeaders().size() != 0) {
166  har->responses.push_back(msg);
167  }
168  }
169 
170  return har;
171 }
std::vector< uint8_t > buffer(kBufferSize+16)
dynamic parseJson(StringPiece range)
Definition: json.cpp:900
std::unique_ptr< IOBuf > readFileToIOBuf(const std::string &filename)
unique_ptr< HTTPArchive > proxygen::HTTPArchive::fromPublicFile ( const std::string fname)
static

Definition at line 191 of file HTTPArchive.cpp.

References buffer(), proxygen::HTTPMessage::getHeaders(), i, folly::parseJson(), proxygen::readFileToIOBuf(), and proxygen::HTTPHeaders::size().

191  {
192  unique_ptr<HTTPArchive> har = std::make_unique<HTTPArchive>();
193  auto buffer = readFileToIOBuf(filename);
194  if (!buffer) {
195  return nullptr;
196  }
197  folly::dynamic jsonObj = folly::parseJson((const char *)buffer->data());
198  auto entries = jsonObj["cases"];
199  // go over all the transactions
200  for (size_t i = 0; i < entries.size(); i++) {
201  HTTPMessage msg = extractMessageFromPublic(entries[i]);
202  if (msg.getHeaders().size() != 0) {
203  har->requests.emplace_back(msg);
204  }
205  }
206 
207  return har;
208 }
std::vector< uint8_t > buffer(kBufferSize+16)
dynamic parseJson(StringPiece range)
Definition: json.cpp:900
std::unique_ptr< IOBuf > readFileToIOBuf(const std::string &filename)
uint32_t proxygen::HTTPArchive::getSize ( const HTTPMessage msg)
static

Definition at line 173 of file HTTPArchive.cpp.

References proxygen::HTTPHeaders::forEach(), proxygen::HTTPMessage::getHeaders(), folly::size(), and uint32_t.

173  {
174  uint32_t size = 0;
175 
176  msg.getHeaders().forEach([&size] (const string& name, const string& value) {
177  size += name.size() + value.size() + 2;
178  });
179  return size;
180 }
const char * name
Definition: http_parser.c:437
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
static const char *const value
Definition: Conv.cpp:50
uint32_t proxygen::HTTPArchive::getSize ( const std::vector< HPACKHeader > &  headers)
static

Definition at line 182 of file HTTPArchive.cpp.

References folly::size(), and uint32_t.

182  {
183  uint32_t size = 0;
184 
185  for (const auto& header : headers) {
186  size += header.name.size() + header.value.size() + 2;
187  }
188  return size;
189 }
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45

Member Data Documentation

std::vector<HTTPMessage> proxygen::HTTPArchive::requests
std::vector<HTTPMessage> proxygen::HTTPArchive::responses

Definition at line 25 of file HTTPArchive.h.


The documentation for this class was generated from the following files: