2012-01-26 17:32:05 +01:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2012-01-26 17:32:05 +01:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/tcp.h>
|
2012-10-14 16:39:41 +02:00
|
|
|
#include <poll.h>
|
2012-01-26 17:32:05 +01:00
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cerrno>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <set>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <fstream>
|
|
|
|
|
2014-05-02 16:34:57 +02:00
|
|
|
#include <zlib.h>
|
|
|
|
|
2013-07-22 15:12:54 +02:00
|
|
|
#include "app_helper.h"
|
2012-08-21 16:22:33 +02:00
|
|
|
#include "util.h"
|
2013-12-05 13:54:36 +01:00
|
|
|
#include "http2.h"
|
2012-01-26 17:32:05 +01:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
namespace nghttp2 {
|
2012-01-29 16:34:10 +01:00
|
|
|
|
2012-01-30 16:46:46 +01:00
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
const char *strstatus(uint32_t error_code) {
|
|
|
|
switch (error_code) {
|
2013-07-15 17:15:04 +02:00
|
|
|
case NGHTTP2_NO_ERROR:
|
|
|
|
return "NO_ERROR";
|
|
|
|
case NGHTTP2_PROTOCOL_ERROR:
|
|
|
|
return "PROTOCOL_ERROR";
|
|
|
|
case NGHTTP2_INTERNAL_ERROR:
|
|
|
|
return "INTERNAL_ERROR";
|
|
|
|
case NGHTTP2_FLOW_CONTROL_ERROR:
|
|
|
|
return "FLOW_CONTROL_ERROR";
|
2013-10-27 11:31:24 +01:00
|
|
|
case NGHTTP2_SETTINGS_TIMEOUT:
|
|
|
|
return "SETTINGS_TIMEOUT";
|
2013-07-15 17:15:04 +02:00
|
|
|
case NGHTTP2_STREAM_CLOSED:
|
|
|
|
return "STREAM_CLOSED";
|
2013-10-27 11:31:24 +01:00
|
|
|
case NGHTTP2_FRAME_SIZE_ERROR:
|
|
|
|
return "FRAME_SIZE_ERROR";
|
2013-07-15 17:15:04 +02:00
|
|
|
case NGHTTP2_REFUSED_STREAM:
|
|
|
|
return "REFUSED_STREAM";
|
|
|
|
case NGHTTP2_CANCEL:
|
|
|
|
return "CANCEL";
|
2013-09-28 15:57:12 +02:00
|
|
|
case NGHTTP2_COMPRESSION_ERROR:
|
|
|
|
return "COMPRESSION_ERROR";
|
2013-10-27 11:31:24 +01:00
|
|
|
case NGHTTP2_CONNECT_ERROR:
|
|
|
|
return "CONNECT_ERROR";
|
|
|
|
case NGHTTP2_ENHANCE_YOUR_CALM:
|
|
|
|
return "ENHANCE_YOUR_CALM";
|
2014-02-07 15:22:17 +01:00
|
|
|
case NGHTTP2_INADEQUATE_SECURITY:
|
|
|
|
return "INADEQUATE_SECURITY";
|
2014-10-28 15:35:45 +01:00
|
|
|
case NGHTTP2_HTTP_1_1_REQUIRED:
|
|
|
|
return "HTTP_1_1_REQUIRED";
|
2013-07-15 17:15:04 +02:00
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2013-08-09 17:37:57 +02:00
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
const char *strsettingsid(int32_t id) {
|
|
|
|
switch (id) {
|
2013-10-27 11:22:51 +01:00
|
|
|
case NGHTTP2_SETTINGS_HEADER_TABLE_SIZE:
|
|
|
|
return "SETTINGS_HEADER_TABLE_SIZE";
|
|
|
|
case NGHTTP2_SETTINGS_ENABLE_PUSH:
|
|
|
|
return "SETTINGS_ENABLE_PUSH";
|
2013-08-09 17:37:57 +02:00
|
|
|
case NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS:
|
2013-10-27 11:22:51 +01:00
|
|
|
return "SETTINGS_MAX_CONCURRENT_STREAMS";
|
2013-08-09 17:37:57 +02:00
|
|
|
case NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE:
|
2013-10-27 11:22:51 +01:00
|
|
|
return "SETTINGS_INITIAL_WINDOW_SIZE";
|
2014-08-28 17:14:10 +02:00
|
|
|
case NGHTTP2_SETTINGS_MAX_FRAME_SIZE:
|
|
|
|
return "SETTINGS_MAX_FRAME_SIZE";
|
|
|
|
case NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE:
|
|
|
|
return "SETTINGS_MAX_HEADER_LIST_SIZE";
|
2013-08-09 17:37:57 +02:00
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2013-07-15 17:15:04 +02:00
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
const char *strframetype(uint8_t type) {
|
|
|
|
switch (type) {
|
2013-08-09 17:42:11 +02:00
|
|
|
case NGHTTP2_DATA:
|
|
|
|
return "DATA";
|
|
|
|
case NGHTTP2_HEADERS:
|
|
|
|
return "HEADERS";
|
|
|
|
case NGHTTP2_PRIORITY:
|
|
|
|
return "PRIORITY";
|
|
|
|
case NGHTTP2_RST_STREAM:
|
|
|
|
return "RST_STREAM";
|
|
|
|
case NGHTTP2_SETTINGS:
|
|
|
|
return "SETTINGS";
|
|
|
|
case NGHTTP2_PUSH_PROMISE:
|
|
|
|
return "PUSH_PROMISE";
|
|
|
|
case NGHTTP2_PING:
|
|
|
|
return "PING";
|
|
|
|
case NGHTTP2_GOAWAY:
|
|
|
|
return "GOAWAY";
|
|
|
|
case NGHTTP2_WINDOW_UPDATE:
|
|
|
|
return "WINDOW_UPDATE";
|
2014-06-09 16:16:54 +02:00
|
|
|
case NGHTTP2_EXT_ALTSVC:
|
2014-04-03 06:20:50 +02:00
|
|
|
return "ALTSVC";
|
2013-08-09 17:42:11 +02:00
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
2012-01-27 20:30:23 +01:00
|
|
|
};
|
2012-01-30 16:46:46 +01:00
|
|
|
} // namespace
|
2012-01-27 20:30:23 +01:00
|
|
|
|
2012-02-01 16:37:48 +01:00
|
|
|
namespace {
|
2014-02-09 10:47:26 +01:00
|
|
|
bool color_output = false;
|
|
|
|
} // namespace
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void set_color_output(bool f) { color_output = f; }
|
2012-02-01 16:37:48 +01:00
|
|
|
|
2013-01-27 08:27:17 +01:00
|
|
|
namespace {
|
2014-02-09 10:47:26 +01:00
|
|
|
FILE *outfile = stdout;
|
2013-01-27 08:27:17 +01:00
|
|
|
} // namespace
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void set_output(FILE *file) { outfile = file; }
|
2014-02-09 10:47:26 +01:00
|
|
|
|
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
void print_frame_attr_indent() { fprintf(outfile, " "); }
|
2014-02-09 10:47:26 +01:00
|
|
|
} // namespace
|
2013-01-27 08:27:17 +01:00
|
|
|
|
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
const char *ansi_esc(const char *code) { return color_output ? code : ""; }
|
2013-01-27 08:27:17 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
const char *ansi_escend() { return color_output ? "\033[0m" : ""; }
|
2013-01-27 08:27:17 +01:00
|
|
|
} // namespace
|
|
|
|
|
2014-01-27 16:20:48 +01:00
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
void print_nv(nghttp2_nv *nv) {
|
2015-03-23 15:25:57 +01:00
|
|
|
fprintf(outfile, "%s%s%s: %s\n", ansi_esc("\033[1;34m"), nv->name,
|
|
|
|
ansi_escend(), nv->value);
|
2014-04-30 02:56:33 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
void print_nv(nghttp2_nv *nva, size_t nvlen) {
|
2014-08-07 14:55:30 +02:00
|
|
|
auto end = nva + nvlen;
|
2014-11-27 15:39:04 +01:00
|
|
|
for (; nva != end; ++nva) {
|
2014-04-30 02:56:33 +02:00
|
|
|
print_frame_attr_indent();
|
|
|
|
|
2014-08-07 14:55:30 +02:00
|
|
|
print_nv(nva);
|
2012-01-29 16:34:10 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-27 16:20:48 +01:00
|
|
|
} // namelen
|
2012-01-29 16:34:10 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void print_timer() {
|
2013-09-16 10:36:24 +02:00
|
|
|
auto millis = get_timer();
|
2014-11-27 15:39:04 +01:00
|
|
|
fprintf(outfile, "%s[%3ld.%03ld]%s", ansi_esc("\033[33m"),
|
|
|
|
(long int)(millis.count() / 1000), (long int)(millis.count() % 1000),
|
2014-02-09 10:47:26 +01:00
|
|
|
ansi_escend());
|
2012-01-30 16:46:46 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 16:37:48 +01:00
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
void print_frame_hd(const nghttp2_frame_hd &hd) {
|
|
|
|
fprintf(outfile, "<length=%zu, flags=0x%02x, stream_id=%d>\n", hd.length,
|
|
|
|
hd.flags, hd.stream_id);
|
2013-07-15 17:15:04 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
void print_flags(const nghttp2_frame_hd &hd) {
|
2013-07-15 17:15:04 +02:00
|
|
|
std::string s;
|
2014-11-27 15:39:04 +01:00
|
|
|
switch (hd.type) {
|
2013-07-15 17:15:04 +02:00
|
|
|
case NGHTTP2_DATA:
|
2014-11-27 15:39:04 +01:00
|
|
|
if (hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
2013-07-15 17:15:04 +02:00
|
|
|
s += "END_STREAM";
|
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
if (hd.flags & NGHTTP2_FLAG_PADDED) {
|
|
|
|
if (!s.empty()) {
|
2014-02-07 15:22:17 +01:00
|
|
|
s += " | ";
|
|
|
|
}
|
2014-06-07 11:15:36 +02:00
|
|
|
s += "PADDED";
|
2014-02-07 15:22:17 +01:00
|
|
|
}
|
2013-07-15 17:15:04 +02:00
|
|
|
break;
|
|
|
|
case NGHTTP2_HEADERS:
|
2014-11-27 15:39:04 +01:00
|
|
|
if (hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
2013-07-15 17:15:04 +02:00
|
|
|
s += "END_STREAM";
|
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
if (hd.flags & NGHTTP2_FLAG_END_HEADERS) {
|
|
|
|
if (!s.empty()) {
|
2013-07-15 17:15:04 +02:00
|
|
|
s += " | ";
|
|
|
|
}
|
|
|
|
s += "END_HEADERS";
|
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
if (hd.flags & NGHTTP2_FLAG_PADDED) {
|
|
|
|
if (!s.empty()) {
|
2014-02-08 16:35:21 +01:00
|
|
|
s += " | ";
|
|
|
|
}
|
2014-06-07 11:15:36 +02:00
|
|
|
s += "PADDED";
|
2014-02-08 16:35:21 +01:00
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
if (hd.flags & NGHTTP2_FLAG_PRIORITY) {
|
|
|
|
if (!s.empty()) {
|
2014-03-25 18:04:24 +01:00
|
|
|
s += " | ";
|
|
|
|
}
|
2014-04-14 16:53:54 +02:00
|
|
|
s += "PRIORITY";
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case NGHTTP2_PRIORITY:
|
2013-07-15 17:15:04 +02:00
|
|
|
break;
|
2013-10-27 11:22:51 +01:00
|
|
|
case NGHTTP2_SETTINGS:
|
2014-11-27 15:39:04 +01:00
|
|
|
if (hd.flags & NGHTTP2_FLAG_ACK) {
|
2013-10-27 11:22:51 +01:00
|
|
|
s += "ACK";
|
|
|
|
}
|
|
|
|
break;
|
2013-07-15 17:15:04 +02:00
|
|
|
case NGHTTP2_PUSH_PROMISE:
|
2014-11-27 15:39:04 +01:00
|
|
|
if (hd.flags & NGHTTP2_FLAG_END_HEADERS) {
|
2014-02-21 13:23:51 +01:00
|
|
|
s += "END_HEADERS";
|
2013-07-15 17:15:04 +02:00
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
if (hd.flags & NGHTTP2_FLAG_PADDED) {
|
|
|
|
if (!s.empty()) {
|
2014-02-08 16:35:21 +01:00
|
|
|
s += " | ";
|
|
|
|
}
|
2014-06-07 11:15:36 +02:00
|
|
|
s += "PADDED";
|
2014-02-08 16:35:21 +01:00
|
|
|
}
|
2013-07-15 17:15:04 +02:00
|
|
|
break;
|
|
|
|
case NGHTTP2_PING:
|
2014-11-27 15:39:04 +01:00
|
|
|
if (hd.flags & NGHTTP2_FLAG_ACK) {
|
2013-10-27 11:22:51 +01:00
|
|
|
s += "ACK";
|
2013-07-15 17:15:04 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-02-09 10:47:26 +01:00
|
|
|
fprintf(outfile, "; %s\n", s.c_str());
|
2012-02-01 16:37:48 +01:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
enum print_type { PRINT_SEND, PRINT_RECV };
|
2013-01-27 08:27:17 +01:00
|
|
|
|
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
const char *frame_name_ansi_esc(print_type ptype) {
|
2013-01-27 08:27:17 +01:00
|
|
|
return ansi_esc(ptype == PRINT_SEND ? "\033[1;35m" : "\033[1;36m");
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2012-02-07 17:50:58 +01:00
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
void print_frame(print_type ptype, const nghttp2_frame *frame) {
|
|
|
|
fprintf(outfile, "%s%s%s frame ", frame_name_ansi_esc(ptype),
|
|
|
|
strframetype(frame->hd.type), ansi_escend());
|
2013-07-15 17:15:04 +02:00
|
|
|
print_frame_hd(frame->hd);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (frame->hd.flags) {
|
2012-02-01 16:37:48 +01:00
|
|
|
print_frame_attr_indent();
|
2013-07-15 17:15:04 +02:00
|
|
|
print_flags(frame->hd);
|
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
switch (frame->hd.type) {
|
2014-01-27 14:13:41 +01:00
|
|
|
case NGHTTP2_DATA:
|
2014-11-27 15:39:04 +01:00
|
|
|
if (frame->data.padlen > 0) {
|
2014-02-07 15:22:17 +01:00
|
|
|
print_frame_attr_indent();
|
2014-02-09 10:47:26 +01:00
|
|
|
fprintf(outfile, "(padlen=%zu)\n", frame->data.padlen);
|
2014-02-07 15:22:17 +01:00
|
|
|
}
|
2014-01-27 14:13:41 +01:00
|
|
|
break;
|
2013-07-15 17:15:04 +02:00
|
|
|
case NGHTTP2_HEADERS:
|
2014-02-08 16:35:21 +01:00
|
|
|
print_frame_attr_indent();
|
2014-03-29 17:19:14 +01:00
|
|
|
fprintf(outfile, "(padlen=%zu", frame->headers.padlen);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (frame->hd.flags & NGHTTP2_FLAG_PRIORITY) {
|
2014-12-12 17:20:58 +01:00
|
|
|
fprintf(outfile, ", dep_stream_id=%d, weight=%u, exclusive=%d",
|
2014-11-27 15:39:04 +01:00
|
|
|
frame->headers.pri_spec.stream_id, frame->headers.pri_spec.weight,
|
2014-04-14 16:53:54 +02:00
|
|
|
frame->headers.pri_spec.exclusive);
|
2014-02-09 13:34:28 +01:00
|
|
|
}
|
2014-03-29 17:19:14 +01:00
|
|
|
fprintf(outfile, ")\n");
|
2014-11-27 15:39:04 +01:00
|
|
|
switch (frame->headers.cat) {
|
2013-07-25 13:53:30 +02:00
|
|
|
case NGHTTP2_HCAT_REQUEST:
|
2013-07-15 17:15:04 +02:00
|
|
|
print_frame_attr_indent();
|
2014-02-09 10:47:26 +01:00
|
|
|
fprintf(outfile, "; Open new stream\n");
|
2013-07-15 17:15:04 +02:00
|
|
|
break;
|
2013-07-25 13:53:30 +02:00
|
|
|
case NGHTTP2_HCAT_RESPONSE:
|
2013-07-15 17:15:04 +02:00
|
|
|
print_frame_attr_indent();
|
2014-02-09 10:47:26 +01:00
|
|
|
fprintf(outfile, "; First response header\n");
|
2013-07-15 17:15:04 +02:00
|
|
|
break;
|
2013-07-25 13:53:30 +02:00
|
|
|
case NGHTTP2_HCAT_PUSH_RESPONSE:
|
|
|
|
print_frame_attr_indent();
|
2014-02-09 10:47:26 +01:00
|
|
|
fprintf(outfile, "; First push response header\n");
|
2013-07-25 13:53:30 +02:00
|
|
|
break;
|
2013-07-15 17:15:04 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-07-19 17:08:14 +02:00
|
|
|
print_nv(frame->headers.nva, frame->headers.nvlen);
|
2012-01-27 19:54:53 +01:00
|
|
|
break;
|
2013-07-22 17:29:52 +02:00
|
|
|
case NGHTTP2_PRIORITY:
|
|
|
|
print_frame_attr_indent();
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-12-12 17:20:58 +01:00
|
|
|
fprintf(outfile, "(dep_stream_id=%d, weight=%u, exclusive=%d)\n",
|
2014-11-27 15:39:04 +01:00
|
|
|
frame->priority.pri_spec.stream_id, frame->priority.pri_spec.weight,
|
2014-04-14 16:53:54 +02:00
|
|
|
frame->priority.pri_spec.exclusive);
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2013-07-22 17:29:52 +02:00
|
|
|
break;
|
2013-07-12 17:19:03 +02:00
|
|
|
case NGHTTP2_RST_STREAM:
|
2012-02-01 16:37:48 +01:00
|
|
|
print_frame_attr_indent();
|
2014-06-18 03:48:31 +02:00
|
|
|
fprintf(outfile, "(error_code=%s(0x%02x))\n",
|
2014-02-09 10:47:26 +01:00
|
|
|
strstatus(frame->rst_stream.error_code),
|
|
|
|
frame->rst_stream.error_code);
|
2012-01-31 17:16:35 +01:00
|
|
|
break;
|
2013-07-12 17:19:03 +02:00
|
|
|
case NGHTTP2_SETTINGS:
|
2012-02-01 16:37:48 +01:00
|
|
|
print_frame_attr_indent();
|
2014-02-09 10:47:26 +01:00
|
|
|
fprintf(outfile, "(niv=%lu)\n",
|
|
|
|
static_cast<unsigned long>(frame->settings.niv));
|
2014-11-27 15:39:04 +01:00
|
|
|
for (size_t i = 0; i < frame->settings.niv; ++i) {
|
2012-02-01 16:37:48 +01:00
|
|
|
print_frame_attr_indent();
|
2014-06-18 03:48:31 +02:00
|
|
|
fprintf(outfile, "[%s(0x%02x):%u]\n",
|
2014-02-09 10:47:26 +01:00
|
|
|
strsettingsid(frame->settings.iv[i].settings_id),
|
2014-11-27 15:39:04 +01:00
|
|
|
frame->settings.iv[i].settings_id, frame->settings.iv[i].value);
|
2012-01-31 17:16:35 +01:00
|
|
|
}
|
|
|
|
break;
|
2013-07-27 15:37:09 +02:00
|
|
|
case NGHTTP2_PUSH_PROMISE:
|
|
|
|
print_frame_attr_indent();
|
2014-03-29 17:19:14 +01:00
|
|
|
fprintf(outfile, "(padlen=%zu, promised_stream_id=%d)\n",
|
2014-11-27 15:39:04 +01:00
|
|
|
frame->push_promise.padlen, frame->push_promise.promised_stream_id);
|
2014-01-16 15:41:13 +01:00
|
|
|
print_nv(frame->push_promise.nva, frame->push_promise.nvlen);
|
2013-07-27 15:37:09 +02:00
|
|
|
break;
|
2013-07-12 17:19:03 +02:00
|
|
|
case NGHTTP2_PING:
|
2012-02-01 16:37:48 +01:00
|
|
|
print_frame_attr_indent();
|
2014-02-09 10:47:26 +01:00
|
|
|
fprintf(outfile, "(opaque_data=%s)\n",
|
|
|
|
util::format_hex(frame->ping.opaque_data, 8).c_str());
|
2012-01-29 16:34:10 +01:00
|
|
|
break;
|
2013-07-12 17:19:03 +02:00
|
|
|
case NGHTTP2_GOAWAY:
|
2012-02-01 16:37:48 +01:00
|
|
|
print_frame_attr_indent();
|
2014-11-27 15:39:04 +01:00
|
|
|
fprintf(outfile, "(last_stream_id=%d, error_code=%s(0x%02x), "
|
|
|
|
"opaque_data(%u)=[%s])\n",
|
|
|
|
frame->goaway.last_stream_id, strstatus(frame->goaway.error_code),
|
2014-02-09 10:47:26 +01:00
|
|
|
frame->goaway.error_code,
|
|
|
|
static_cast<unsigned int>(frame->goaway.opaque_data_len),
|
2014-07-12 16:30:13 +02:00
|
|
|
util::ascii_dump(frame->goaway.opaque_data,
|
|
|
|
frame->goaway.opaque_data_len).c_str());
|
2012-01-31 17:16:35 +01:00
|
|
|
break;
|
2013-07-12 17:19:03 +02:00
|
|
|
case NGHTTP2_WINDOW_UPDATE:
|
2012-02-25 16:12:32 +01:00
|
|
|
print_frame_attr_indent();
|
2014-02-09 10:47:26 +01:00
|
|
|
fprintf(outfile, "(window_size_increment=%d)\n",
|
|
|
|
frame->window_update.window_size_increment);
|
2012-02-25 16:12:32 +01:00
|
|
|
break;
|
2014-06-09 16:16:54 +02:00
|
|
|
case NGHTTP2_EXT_ALTSVC: {
|
2014-04-03 06:20:50 +02:00
|
|
|
print_frame_attr_indent();
|
2014-06-09 16:16:54 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
auto altsvc = static_cast<const nghttp2_ext_altsvc *>(frame->ext.payload);
|
2014-06-09 16:16:54 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
fprintf(outfile, "(max-age=%u, port=%u, protocol_id=", altsvc->max_age,
|
|
|
|
altsvc->port);
|
2014-06-09 16:16:54 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (altsvc->protocol_id_len) {
|
2014-06-09 16:16:54 +02:00
|
|
|
fwrite(altsvc->protocol_id, altsvc->protocol_id_len, 1, outfile);
|
2014-04-03 06:20:50 +02:00
|
|
|
}
|
2014-06-09 16:16:54 +02:00
|
|
|
|
2014-04-03 06:20:50 +02:00
|
|
|
fprintf(outfile, ", host=");
|
2014-06-09 16:16:54 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (altsvc->host_len) {
|
2014-06-09 16:16:54 +02:00
|
|
|
fwrite(altsvc->host, altsvc->host_len, 1, outfile);
|
2014-04-03 06:20:50 +02:00
|
|
|
}
|
2014-06-09 16:16:54 +02:00
|
|
|
|
2014-04-03 06:20:50 +02:00
|
|
|
fprintf(outfile, ", origin=");
|
2014-06-09 16:16:54 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (altsvc->origin_len) {
|
2014-06-09 16:16:54 +02:00
|
|
|
fwrite(altsvc->origin, altsvc->origin_len, 1, outfile);
|
2014-04-03 06:20:50 +02:00
|
|
|
}
|
2014-06-09 16:16:54 +02:00
|
|
|
|
2014-04-03 06:20:50 +02:00
|
|
|
fprintf(outfile, ")\n");
|
|
|
|
|
|
|
|
break;
|
2014-06-09 16:16:54 +02:00
|
|
|
}
|
2012-01-27 19:54:53 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-01-30 16:46:46 +01:00
|
|
|
}
|
2012-02-07 17:50:58 +01:00
|
|
|
} // namespace
|
2012-01-30 16:46:46 +01:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
int verbose_on_header_callback(nghttp2_session *session,
|
2014-11-27 15:39:04 +01:00
|
|
|
const nghttp2_frame *frame, const uint8_t *name,
|
|
|
|
size_t namelen, const uint8_t *value,
|
|
|
|
size_t valuelen, uint8_t flags,
|
|
|
|
void *user_data) {
|
|
|
|
nghttp2_nv nv = {const_cast<uint8_t *>(name), const_cast<uint8_t *>(value),
|
|
|
|
namelen, valuelen};
|
2014-04-30 02:56:33 +02:00
|
|
|
|
2014-08-07 14:55:30 +02:00
|
|
|
print_timer();
|
2015-02-24 15:12:12 +01:00
|
|
|
fprintf(outfile, " recv (stream_id=%d", frame->hd.stream_id);
|
|
|
|
if (flags & NGHTTP2_NV_FLAG_NO_INDEX) {
|
|
|
|
fprintf(outfile, ", sensitive");
|
|
|
|
}
|
|
|
|
fprintf(outfile, ") ");
|
2014-04-30 02:56:33 +02:00
|
|
|
|
2014-08-07 14:55:30 +02:00
|
|
|
print_nv(&nv);
|
2014-08-10 10:15:35 +02:00
|
|
|
fflush(outfile);
|
2014-04-30 02:56:33 +02:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int verbose_on_frame_recv_callback(nghttp2_session *session,
|
|
|
|
const nghttp2_frame *frame,
|
|
|
|
void *user_data) {
|
2012-01-30 16:46:46 +01:00
|
|
|
print_timer();
|
2014-02-09 10:47:26 +01:00
|
|
|
fprintf(outfile, " recv ");
|
2013-07-15 17:15:04 +02:00
|
|
|
print_frame(PRINT_RECV, frame);
|
2014-02-09 10:47:26 +01:00
|
|
|
fflush(outfile);
|
2013-08-29 14:03:39 +02:00
|
|
|
return 0;
|
2012-01-27 19:54:53 +01:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int verbose_on_invalid_frame_recv_callback(nghttp2_session *session,
|
|
|
|
const nghttp2_frame *frame,
|
|
|
|
uint32_t error_code,
|
|
|
|
void *user_data) {
|
2012-05-09 16:27:44 +02:00
|
|
|
print_timer();
|
2014-02-09 10:47:26 +01:00
|
|
|
fprintf(outfile, " [INVALID; status=%s] recv ", strstatus(error_code));
|
2013-07-15 17:15:04 +02:00
|
|
|
print_frame(PRINT_RECV, frame);
|
2014-02-09 10:47:26 +01:00
|
|
|
fflush(outfile);
|
2013-08-29 14:12:43 +02:00
|
|
|
return 0;
|
2012-05-09 16:27:44 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int verbose_on_frame_send_callback(nghttp2_session *session,
|
|
|
|
const nghttp2_frame *frame,
|
|
|
|
void *user_data) {
|
2012-02-07 17:50:58 +01:00
|
|
|
print_timer();
|
2014-02-09 10:47:26 +01:00
|
|
|
fprintf(outfile, " send ");
|
2013-07-15 17:15:04 +02:00
|
|
|
print_frame(PRINT_SEND, frame);
|
2014-02-09 10:47:26 +01:00
|
|
|
fflush(outfile);
|
2013-08-29 14:48:34 +02:00
|
|
|
return 0;
|
2012-02-07 17:50:58 +01:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int verbose_on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags,
|
|
|
|
int32_t stream_id, const uint8_t *data,
|
|
|
|
size_t len, void *user_data) {
|
2014-08-10 10:15:35 +02:00
|
|
|
print_timer();
|
2014-11-27 15:39:04 +01:00
|
|
|
auto srecv =
|
|
|
|
nghttp2_session_get_stream_effective_recv_data_length(session, stream_id);
|
2014-08-10 10:15:35 +02:00
|
|
|
auto crecv = nghttp2_session_get_effective_recv_data_length(session);
|
|
|
|
|
|
|
|
fprintf(outfile,
|
|
|
|
" recv (stream_id=%d, length=%zu, srecv=%d, crecv=%d) DATA\n",
|
|
|
|
stream_id, len, srecv, crecv);
|
|
|
|
fflush(outfile);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-30 16:46:46 +01:00
|
|
|
namespace {
|
2013-09-16 10:36:24 +02:00
|
|
|
std::chrono::steady_clock::time_point base_tv;
|
2012-01-30 16:46:46 +01:00
|
|
|
} // namespace
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void reset_timer() { base_tv = std::chrono::steady_clock::now(); }
|
2012-01-30 16:46:46 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
std::chrono::milliseconds get_timer() {
|
2013-09-16 10:36:24 +02:00
|
|
|
return time_delta(std::chrono::steady_clock::now(), base_tv);
|
2012-01-30 16:46:46 +01:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
std::chrono::steady_clock::time_point get_time() {
|
2013-09-16 10:36:24 +02:00
|
|
|
return std::chrono::steady_clock::now();
|
2013-01-27 09:16:13 +01:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
ssize_t deflate_data(uint8_t *out, size_t outlen, const uint8_t *in,
|
|
|
|
size_t inlen) {
|
2014-05-02 16:34:57 +02:00
|
|
|
int rv;
|
|
|
|
z_stream zst;
|
|
|
|
uint8_t temp_out[8192];
|
|
|
|
auto temp_outlen = sizeof(temp_out);
|
|
|
|
|
|
|
|
zst.next_in = Z_NULL;
|
|
|
|
zst.zalloc = Z_NULL;
|
|
|
|
zst.zfree = Z_NULL;
|
|
|
|
zst.opaque = Z_NULL;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
rv = deflateInit2(&zst, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 31, 9,
|
|
|
|
Z_DEFAULT_STRATEGY);
|
2014-05-02 16:34:57 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (rv != Z_OK) {
|
2014-05-02 16:34:57 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
zst.avail_in = inlen;
|
2014-11-27 15:39:04 +01:00
|
|
|
zst.next_in = (uint8_t *)in;
|
2014-05-02 16:34:57 +02:00
|
|
|
zst.avail_out = temp_outlen;
|
|
|
|
zst.next_out = temp_out;
|
|
|
|
|
|
|
|
rv = deflate(&zst, Z_FINISH);
|
|
|
|
|
|
|
|
deflateEnd(&zst);
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (rv != Z_STREAM_END) {
|
2014-05-02 16:34:57 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp_outlen -= zst.avail_out;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (temp_outlen > outlen) {
|
2014-05-02 16:34:57 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(out, temp_out, temp_outlen);
|
|
|
|
|
|
|
|
return temp_outlen;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
} // namespace nghttp2
|