nghttpx: Convert UpstreamAltMode to enum class
This commit is contained in:
parent
b0eb68ee9e
commit
f2159bc2c1
|
@ -952,10 +952,12 @@ ClientHandler::get_downstream_connection(int &err, Downstream *downstream,
|
|||
err = 0;
|
||||
|
||||
switch (faddr_->alt_mode) {
|
||||
case ALTMODE_API:
|
||||
case UpstreamAltMode::API:
|
||||
return std::make_unique<APIDownstreamConnection>(worker_);
|
||||
case ALTMODE_HEALTHMON:
|
||||
case UpstreamAltMode::HEALTHMON:
|
||||
return std::make_unique<HealthMonitorDownstreamConnection>();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
auto &balloc = downstream->get_block_allocator();
|
||||
|
|
|
@ -756,7 +756,7 @@ int parse_memcached_connection_params(MemcachedConnectionParams &out,
|
|||
} // namespace
|
||||
|
||||
struct UpstreamParams {
|
||||
int alt_mode;
|
||||
UpstreamAltMode alt_mode;
|
||||
bool tls;
|
||||
bool sni_fwd;
|
||||
bool proxyproto;
|
||||
|
@ -779,17 +779,19 @@ 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)) {
|
||||
if (out.alt_mode && out.alt_mode != ALTMODE_API) {
|
||||
if (out.alt_mode != UpstreamAltMode::NONE &&
|
||||
out.alt_mode != UpstreamAltMode::API) {
|
||||
LOG(ERROR) << "frontend: api and healthmon are mutually exclusive";
|
||||
return -1;
|
||||
}
|
||||
out.alt_mode = ALTMODE_API;
|
||||
out.alt_mode = UpstreamAltMode::API;
|
||||
} else if (util::strieq_l("healthmon", param)) {
|
||||
if (out.alt_mode && out.alt_mode != ALTMODE_HEALTHMON) {
|
||||
if (out.alt_mode != UpstreamAltMode::NONE &&
|
||||
out.alt_mode != UpstreamAltMode::HEALTHMON) {
|
||||
LOG(ERROR) << "frontend: api and healthmon are mutually exclusive";
|
||||
return -1;
|
||||
}
|
||||
out.alt_mode = ALTMODE_HEALTHMON;
|
||||
out.alt_mode = UpstreamAltMode::HEALTHMON;
|
||||
} else if (util::strieq_l("proxyproto", param)) {
|
||||
out.proxyproto = true;
|
||||
} else if (!param.empty()) {
|
||||
|
@ -2572,7 +2574,7 @@ int parse_config(Config *config, int optid, const StringRef &opt,
|
|||
addr.alt_mode = params.alt_mode;
|
||||
addr.accept_proxy_protocol = params.proxyproto;
|
||||
|
||||
if (addr.alt_mode == ALTMODE_API) {
|
||||
if (addr.alt_mode == UpstreamAltMode::API) {
|
||||
apiconf.enabled = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -420,13 +420,13 @@ struct AltSvc {
|
|||
uint16_t port;
|
||||
};
|
||||
|
||||
enum UpstreamAltMode {
|
||||
enum class UpstreamAltMode {
|
||||
// No alternative mode
|
||||
ALTMODE_NONE,
|
||||
NONE,
|
||||
// API processing mode
|
||||
ALTMODE_API,
|
||||
API,
|
||||
// Health monitor mode
|
||||
ALTMODE_HEALTHMON,
|
||||
HEALTHMON,
|
||||
};
|
||||
|
||||
struct UpstreamAddr {
|
||||
|
@ -444,7 +444,7 @@ struct UpstreamAddr {
|
|||
// domain socket, this is 0.
|
||||
int family;
|
||||
// Alternate mode
|
||||
int alt_mode;
|
||||
UpstreamAltMode alt_mode;
|
||||
// true if |host| contains UNIX domain socket path.
|
||||
bool host_unix;
|
||||
// true if TLS is enabled.
|
||||
|
|
|
@ -407,7 +407,7 @@ int ConnectionHandler::handle_connection(int fd, sockaddr *addr, int addrlen,
|
|||
|
||||
Worker *worker;
|
||||
|
||||
if (faddr->alt_mode == ALTMODE_API) {
|
||||
if (faddr->alt_mode == UpstreamAltMode::API) {
|
||||
worker = workers_[0].get();
|
||||
|
||||
if (LOG_ENABLED(INFO)) {
|
||||
|
|
|
@ -610,7 +610,7 @@ bool Downstream::request_buf_full() {
|
|||
auto worker = handler->get_worker();
|
||||
|
||||
// We don't check buffer size here for API endpoint.
|
||||
if (faddr->alt_mode == ALTMODE_API) {
|
||||
if (faddr->alt_mode == UpstreamAltMode::API) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -358,8 +358,8 @@ int Http2Upstream::on_request_headers(Downstream *downstream,
|
|||
auto faddr = handler_->get_upstream_addr();
|
||||
|
||||
// For HTTP/2 proxy, we require :authority.
|
||||
if (method_token != HTTP_CONNECT && config->http2_proxy && !faddr->alt_mode &&
|
||||
!authority) {
|
||||
if (method_token != HTTP_CONNECT && config->http2_proxy &&
|
||||
faddr->alt_mode == UpstreamAltMode::NONE && !authority) {
|
||||
rst_stream(downstream, NGHTTP2_PROTOCOL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
@ -383,7 +383,8 @@ int Http2Upstream::on_request_headers(Downstream *downstream,
|
|||
if (method_token == HTTP_OPTIONS &&
|
||||
path->value == StringRef::from_lit("*")) {
|
||||
// Server-wide OPTIONS request. Path is empty.
|
||||
} else if (config->http2_proxy && !faddr->alt_mode) {
|
||||
} else if (config->http2_proxy &&
|
||||
faddr->alt_mode == UpstreamAltMode::NONE) {
|
||||
req.path = path->value;
|
||||
} else {
|
||||
req.path = http2::rewrite_clean_path(downstream->get_block_allocator(),
|
||||
|
@ -1026,10 +1027,11 @@ Http2Upstream::Http2Upstream(ClientHandler *handler)
|
|||
|
||||
auto faddr = handler_->get_upstream_addr();
|
||||
|
||||
rv = nghttp2_session_server_new2(
|
||||
&session_, http2conf.upstream.callbacks, this,
|
||||
faddr->alt_mode ? http2conf.upstream.alt_mode_option
|
||||
: http2conf.upstream.option);
|
||||
rv =
|
||||
nghttp2_session_server_new2(&session_, http2conf.upstream.callbacks, this,
|
||||
faddr->alt_mode != UpstreamAltMode::NONE
|
||||
? http2conf.upstream.alt_mode_option
|
||||
: http2conf.upstream.option);
|
||||
|
||||
assert(rv == 0);
|
||||
|
||||
|
@ -1043,7 +1045,7 @@ Http2Upstream::Http2Upstream(ClientHandler *handler)
|
|||
entry[0].value = http2conf.upstream.max_concurrent_streams;
|
||||
|
||||
entry[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE;
|
||||
if (faddr->alt_mode) {
|
||||
if (faddr->alt_mode != UpstreamAltMode::NONE) {
|
||||
entry[1].value = (1u << 31) - 1;
|
||||
} else {
|
||||
entry[1].value = http2conf.upstream.window_size;
|
||||
|
@ -1070,7 +1072,7 @@ Http2Upstream::Http2Upstream(ClientHandler *handler)
|
|||
}
|
||||
|
||||
auto window_size =
|
||||
faddr->alt_mode
|
||||
faddr->alt_mode != UpstreamAltMode::NONE
|
||||
? std::numeric_limits<int32_t>::max()
|
||||
: http2conf.upstream.optimize_window_size
|
||||
? std::min(http2conf.upstream.connection_window_size,
|
||||
|
@ -1186,7 +1188,7 @@ int Http2Upstream::on_write() {
|
|||
|
||||
if (http2conf.upstream.optimize_window_size) {
|
||||
auto faddr = handler_->get_upstream_addr();
|
||||
if (!faddr->alt_mode) {
|
||||
if (faddr->alt_mode == UpstreamAltMode::NONE) {
|
||||
auto window_size = std::min(http2conf.upstream.connection_window_size,
|
||||
static_cast<int32_t>(hint.rwin * 2));
|
||||
|
||||
|
@ -1980,7 +1982,7 @@ int Http2Upstream::consume(int32_t stream_id, size_t len) {
|
|||
|
||||
auto faddr = handler_->get_upstream_addr();
|
||||
|
||||
if (faddr->alt_mode) {
|
||||
if (faddr->alt_mode != UpstreamAltMode::NONE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -413,7 +413,8 @@ int htp_hdrs_completecb(http_parser *htp) {
|
|||
|
||||
// mruby hook may change method value
|
||||
|
||||
if (req.no_authority && config->http2_proxy && !faddr->alt_mode) {
|
||||
if (req.no_authority && config->http2_proxy &&
|
||||
faddr->alt_mode == UpstreamAltMode::NONE) {
|
||||
// Request URI should be absolute-form for client proxy mode
|
||||
return -1;
|
||||
}
|
||||
|
@ -464,7 +465,7 @@ int htp_hdrs_completecb(http_parser *htp) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (faddr->alt_mode) {
|
||||
if (faddr->alt_mode != UpstreamAltMode::NONE) {
|
||||
// Normally, we forward expect: 100-continue to backend server,
|
||||
// and let them decide whether responds with 100 Continue or not.
|
||||
// For alternative mode, we have no backend, so just send 100
|
||||
|
|
Loading…
Reference in New Issue