nghttpx: Make API processing one of alternative mode

This commit is contained in:
Tatsuhiro Tsujikawa 2016-06-16 23:30:35 +09:00
parent af4e262d47
commit af9662f971
9 changed files with 29 additions and 20 deletions

View File

@ -1109,8 +1109,8 @@ void fill_default_config() {
// For API endpoint, we enable automatic window update. This is
// because we are a sink.
nghttp2_option_new(&upstreamconf.api_option);
nghttp2_option_set_no_recv_client_magic(upstreamconf.api_option, 1);
nghttp2_option_new(&upstreamconf.alt_mode_option);
nghttp2_option_set_no_recv_client_magic(upstreamconf.alt_mode_option, 1);
}
{

View File

@ -896,7 +896,8 @@ ClientHandler::get_downstream_connection(Downstream *downstream) {
const auto &req = downstream->request();
if (faddr_->api) {
switch (faddr_->alt_mode) {
case ALTMODE_API:
return make_unique<APIDownstreamConnection>(worker_);
}

View File

@ -610,8 +610,8 @@ int parse_memcached_connection_params(MemcachedConnectionParams &out,
} // namespace
struct UpstreamParams {
int alt_mode;
bool tls;
bool api;
};
namespace {
@ -629,7 +629,7 @@ int parse_upstream_params(UpstreamParams &out, const StringRef &src_params) {
} else if (util::strieq_l("no-tls", param)) {
out.tls = false;
} else if (util::strieq_l("api", param)) {
out.api = true;
out.alt_mode = ALTMODE_API;
} else if (!param.empty()) {
LOG(ERROR) << "frontend: " << param << ": unknown keyword";
return -1;
@ -1736,9 +1736,9 @@ int parse_config(Config *config, int optid, const StringRef &opt,
UpstreamAddr addr{};
addr.fd = -1;
addr.tls = params.tls;
addr.api = params.api;
addr.alt_mode = params.alt_mode;
if (addr.api) {
if (addr.alt_mode == ALTMODE_API) {
listenerconf.api = true;
}

View File

@ -316,6 +316,13 @@ struct AltSvc {
uint16_t port;
};
enum UpstreamAltMode {
// No alternative mode
ALTMODE_NONE,
// API processing mode
ALTMODE_API,
};
struct UpstreamAddr {
// The frontend address (e.g., FQDN, hostname, IP address). If
// |host_unix| is true, this is UNIX domain socket path.
@ -329,12 +336,12 @@ struct UpstreamAddr {
// For TCP socket, this is either AF_INET or AF_INET6. For UNIX
// domain socket, this is 0.
int family;
// Alternate mode
int alt_mode;
// true if |host| contains UNIX domain socket path.
bool host_unix;
// true if TLS is enabled.
bool tls;
// true if this is an API endpoint.
bool api;
int fd;
};
@ -554,7 +561,7 @@ struct Http2Config {
ev_tstamp settings;
} timeout;
nghttp2_option *option;
nghttp2_option *api_option;
nghttp2_option *alt_mode_option;
nghttp2_session_callbacks *callbacks;
size_t window_bits;
size_t connection_window_bits;

View File

@ -393,7 +393,7 @@ int ConnectionHandler::handle_connection(int fd, sockaddr *addr, int addrlen,
Worker *worker;
if (faddr->api) {
if (faddr->alt_mode == ALTMODE_API) {
worker = workers_[0].get();
if (LOG_ENABLED(INFO)) {

View File

@ -505,7 +505,7 @@ bool Downstream::request_buf_full() {
auto worker = handler->get_worker();
// We don't check buffer size here for API endpoint.
if (faddr->api) {
if (faddr->alt_mode == ALTMODE_API) {
return false;
}

View File

@ -879,7 +879,8 @@ Http2Upstream::Http2Upstream(ClientHandler *handler)
rv = nghttp2_session_server_new2(
&session_, http2conf.upstream.callbacks, this,
faddr->api ? http2conf.upstream.api_option : http2conf.upstream.option);
faddr->alt_mode ? http2conf.upstream.alt_mode_option
: http2conf.upstream.option);
assert(rv == 0);
@ -891,7 +892,7 @@ Http2Upstream::Http2Upstream(ClientHandler *handler)
entry[0].value = http2conf.upstream.max_concurrent_streams;
entry[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE;
if (faddr->api) {
if (faddr->alt_mode) {
entry[1].value = (1u << 31) - 1;
} else {
entry[1].value = (1 << http2conf.upstream.window_bits) - 1;
@ -905,7 +906,7 @@ Http2Upstream::Http2Upstream(ClientHandler *handler)
}
int32_t window_bits =
faddr->api ? 31 : http2conf.upstream.connection_window_bits;
faddr->alt_mode ? 31 : http2conf.upstream.connection_window_bits;
if (window_bits != 16) {
int32_t window_size = (1u << window_bits) - 1;
@ -1701,7 +1702,7 @@ int Http2Upstream::consume(int32_t stream_id, size_t len) {
auto faddr = handler_->get_upstream_addr();
if (faddr->api) {
if (faddr->alt_mode) {
return 0;
}

View File

@ -413,11 +413,11 @@ int htp_hdrs_completecb(http_parser *htp) {
auto faddr = handler->get_upstream_addr();
if (faddr->api) {
if (faddr->alt_mode) {
// Normally, we forward expect: 100-continue to backend server,
// and let them decide whether responds with 100 Continue or not.
// For API endpoint, we have no backend, so just send 100 Continue
// here to make the client happy.
// For alternative mode, we have no backend, so just send 100
// Continue here to make the client happy.
auto expect = req.fs.header(http2::HD_EXPECT);
if (expect &&
util::strieq(expect->value, StringRef::from_lit("100-continue"))) {

View File

@ -565,7 +565,7 @@ SpdyUpstream::SpdyUpstream(uint16_t version, ClientHandler *handler)
// going to be deprecated in the future, and the default stream
// window is large enough for API request body (64KiB), we don't
// expand window size depending on the options.
if (version >= SPDYLAY_PROTO_SPDY3 && !faddr->api) {
if (version >= SPDYLAY_PROTO_SPDY3 && !faddr->alt_mode) {
int val = 1;
flow_control_ = true;
initial_window_size_ = 1 << http2conf.upstream.window_bits;