16 #include <glog/logging.h> 24 using std::unique_ptr;
40 if (sscanf(s.c_str(),
"%d-%d-%dT%d:%d:%d.%dZ",
54 tm.tm_year = tm.tm_year - 1900;
55 tm.tm_mon = tm.tm_mon - 1;
57 auto res = mktime(&tm);
58 return std::chrono::steady_clock::time_point(
59 std::chrono::seconds(res) + std::chrono::milliseconds(ms));
66 auto& headersObj = obj[
"headers"];
67 for (
size_t i = 0;
i < headersObj.size();
i++) {
68 string name = headersObj[
i][
"name"].asString();
71 if (name ==
":host" || name ==
":authority") {
79 headersObj[
i][
"value"].asString());
83 msg.
setURL(obj[
"url"].asString());
85 auto t = parseHTTPArchiveTime(timeStr);
96 folly::split(
'/', obj[
"httpVersion"].asString(), proto, version);
106 auto& headersObj = obj[
"headers"];
107 for (
size_t i = 0;
i < headersObj.size();
i++) {
108 auto& headerObj = headersObj[
i];
109 for (
auto&
k: headerObj.keys()) {
110 string name =
k.asString();
111 string value = headerObj[
name].asString();
112 std::transform(name.begin(), name.end(), name.begin(), ::tolower);
124 ifstream file(filename);
125 if (!file.is_open()) {
126 LOG(
ERROR) <<
"could not open file '" << filename <<
"'";
132 LOG(
ERROR) <<
"failed to fetch the position at the end of the file";
135 file.seekg(0, ios::beg);
136 unique_ptr<IOBuf>
buffer = IOBuf::create(size + 1);
141 LOG(
ERROR) <<
"error occurred, was able to read only " 142 << file.gcount() <<
" bytes out of " <<
size;
149 unique_ptr<HTTPArchive> har = std::make_unique<HTTPArchive>();
155 auto entries = jsonObj[
"log"][
"entries"];
157 for (
size_t i = 0;
i < entries.size();
i++) {
159 entries[i][
"startedDateTime"].asString(),
162 har->requests.push_back(msg);
164 msg = extractMessage(entries[i][
"response"],
"",
false);
166 har->responses.push_back(msg);
177 size += name.size() + value.size() + 2;
185 for (
const auto& header : headers) {
186 size += header.name.size() + header.value.size() + 2;
192 unique_ptr<HTTPArchive> har = std::make_unique<HTTPArchive>();
198 auto entries = jsonObj[
"cases"];
200 for (
size_t i = 0;
i < entries.size();
i++) {
203 har->requests.emplace_back(msg);
211 const std::vector<HTTPMessage>& msgs) {
212 std::vector<std::vector<HPACKHeader>> result;
214 std::vector<HPACKHeader> headers;
216 [&headers] (
const string& name,
const string& value) {
217 headers.emplace_back(name, value);
std::vector< uint8_t > buffer(kBufferSize+16)
dynamic parseJson(StringPiece range)
void setStatusMessage(T &&msg)
constexpr detail::Map< Move > move
static uint32_t getSize(const HTTPMessage &msg)
static std::vector< std::vector< HPACKHeader > > convertToHPACK(const std::vector< HTTPMessage > &msgs)
static std::unique_ptr< HTTPArchive > fromPublicFile(const std::string &fname)
void setVersionString(const std::string &ver)
PUSHMI_INLINE_VAR constexpr detail::transform_fn transform
void split(const Delim &delimiter, const String &input, std::vector< OutputType > &out, bool ignoreEmpty)
std::unique_ptr< IOBuf > readFileToIOBuf(const std::string &filename)
constexpr auto size(C const &c) -> decltype(c.size())
auto end(TestAdlIterable &instance)
static std::unique_ptr< HTTPArchive > fromFile(const std::string &filename)
void setStartTime(const TimePoint &startTime)
static const char *const value
HTTPHeaders & getHeaders()
void setMethod(HTTPMethod method)
void append(std::size_t amount)
void setStatusCode(uint16_t status)