nghttpd: Add --encoder-header-table-size option

This commit is contained in:
Tatsuhiro Tsujikawa 2016-09-17 22:33:21 +09:00
parent f19b0724a3
commit 3ec71bf5a2
3 changed files with 38 additions and 1 deletions

View File

@ -96,6 +96,7 @@ Config::Config()
num_worker(1), num_worker(1),
max_concurrent_streams(100), max_concurrent_streams(100),
header_table_size(-1), header_table_size(-1),
encoder_header_table_size(-1),
window_bits(-1), window_bits(-1),
connection_window_bits(-1), connection_window_bits(-1),
port(0), port(0),
@ -231,6 +232,7 @@ public:
config_(config), config_(config),
ssl_ctx_(ssl_ctx), ssl_ctx_(ssl_ctx),
callbacks_(nullptr), callbacks_(nullptr),
option_(nullptr),
next_session_id_(1), next_session_id_(1),
tstamp_cached_(ev_now(loop)), tstamp_cached_(ev_now(loop)),
cached_date_(util::http_date(tstamp_cached_)) { cached_date_(util::http_date(tstamp_cached_)) {
@ -238,6 +240,13 @@ public:
fill_callback(callbacks_, config_); fill_callback(callbacks_, config_);
nghttp2_option_new(&option_);
if (config_->encoder_header_table_size != -1) {
nghttp2_option_set_max_deflate_dynamic_table_size(
option_, config_->encoder_header_table_size);
}
ev_timer_init(&release_fd_timer_, release_fd_cb, 0., RELEASE_FD_TIMEOUT); ev_timer_init(&release_fd_timer_, release_fd_cb, 0., RELEASE_FD_TIMEOUT);
release_fd_timer_.data = this; release_fd_timer_.data = this;
} }
@ -246,6 +255,7 @@ public:
for (auto handler : handlers_) { for (auto handler : handlers_) {
delete handler; delete handler;
} }
nghttp2_option_del(option_);
nghttp2_session_callbacks_del(callbacks_); nghttp2_session_callbacks_del(callbacks_);
} }
void add_handler(Http2Handler *handler) { handlers_.insert(handler); } void add_handler(Http2Handler *handler) { handlers_.insert(handler); }
@ -283,6 +293,7 @@ public:
return session_id; return session_id;
} }
const nghttp2_session_callbacks *get_callbacks() const { return callbacks_; } const nghttp2_session_callbacks *get_callbacks() const { return callbacks_; }
const nghttp2_option *get_option() const { return option_; }
void accept_connection(int fd) { void accept_connection(int fd) {
util::make_socket_nodelay(fd); util::make_socket_nodelay(fd);
SSL *ssl = nullptr; SSL *ssl = nullptr;
@ -408,6 +419,7 @@ private:
const Config *config_; const Config *config_;
SSL_CTX *ssl_ctx_; SSL_CTX *ssl_ctx_;
nghttp2_session_callbacks *callbacks_; nghttp2_session_callbacks *callbacks_;
nghttp2_option *option_;
ev_timer release_fd_timer_; ev_timer release_fd_timer_;
int64_t next_session_id_; int64_t next_session_id_;
ev_tstamp tstamp_cached_; ev_tstamp tstamp_cached_;
@ -825,7 +837,8 @@ int Http2Handler::on_write() { return write_(*this); }
int Http2Handler::connection_made() { int Http2Handler::connection_made() {
int r; int r;
r = nghttp2_session_server_new(&session_, sessions_->get_callbacks(), this); r = nghttp2_session_server_new2(&session_, sessions_->get_callbacks(), this,
sessions_->get_option());
if (r != 0) { if (r != 0) {
return r; return r;

View File

@ -69,6 +69,7 @@ struct Config {
size_t num_worker; size_t num_worker;
size_t max_concurrent_streams; size_t max_concurrent_streams;
ssize_t header_table_size; ssize_t header_table_size;
ssize_t encoder_header_table_size;
int window_bits; int window_bits;
int connection_window_bits; int connection_window_bits;
uint16_t port; uint16_t port;

View File

@ -124,6 +124,11 @@ Options:
--no-tls Disable SSL/TLS. --no-tls Disable SSL/TLS.
-c, --header-table-size=<SIZE> -c, --header-table-size=<SIZE>
Specify decoder header table size. Specify decoder header table size.
--encoder-header-table-size=<SIZE>
Specify encoder header table size. The decoder (client)
specifies the maximum dynamic table size it accepts.
Then the negotiated dynamic table size is the minimum of
this option value and the value which client specified.
--color Force colored log output. --color Force colored log output.
-p, --push=<PATH>=<PUSH_PATH,...> -p, --push=<PATH>=<PUSH_PATH,...>
Push resources <PUSH_PATH>s when <PATH> is requested. Push resources <PUSH_PATH>s when <PATH> is requested.
@ -219,6 +224,7 @@ int main(int argc, char **argv) {
{"echo-upload", no_argument, &flag, 8}, {"echo-upload", no_argument, &flag, 8},
{"mime-types-file", required_argument, &flag, 9}, {"mime-types-file", required_argument, &flag, 9},
{"no-content-length", no_argument, &flag, 10}, {"no-content-length", no_argument, &flag, 10},
{"encoder-header-table-size", required_argument, &flag, 11},
{nullptr, 0, nullptr, 0}}; {nullptr, 0, nullptr, 0}};
int option_index = 0; int option_index = 0;
int c = getopt_long(argc, argv, "DVb:c:d:ehm:n:p:va:w:W:", long_options, int c = getopt_long(argc, argv, "DVb:c:d:ehm:n:p:va:w:W:", long_options,
@ -375,6 +381,23 @@ int main(int argc, char **argv) {
// no-content-length option // no-content-length option
config.no_content_length = true; config.no_content_length = true;
break; break;
case 11: {
// encoder-header-table-size option
auto n = util::parse_uint_with_unit(optarg);
if (n == -1) {
std::cerr << "--encoder-header-table-size: Bad option value: "
<< optarg << std::endl;
exit(EXIT_FAILURE);
}
if (n > std::numeric_limits<uint32_t>::max()) {
std::cerr << "--encoder-header-table-size: Value too large. It "
"should be less than or equal to "
<< std::numeric_limits<uint32_t>::max() << std::endl;
exit(EXIT_FAILURE);
}
config.encoder_header_table_size = n;
break;
}
} }
break; break;
default: default: