nghttpx: Per-pattern not per-backend

This commit is contained in:
Tatsuhiro Tsujikawa 2018-08-28 17:50:01 +09:00
parent 2d1a981c81
commit 7417fd71a4
5 changed files with 31 additions and 29 deletions

View File

@ -300,15 +300,16 @@ HTTP variables, like authority or request path, and even return custom
response without forwarding request to backend servers. response without forwarding request to backend servers.
There are 2 levels of mruby script invocations: global and There are 2 levels of mruby script invocations: global and
per-backend. The global mruby script is set by :option:`--mruby-file` per-pattern. The global mruby script is set by :option:`--mruby-file`
option and is called for all requests. The per-backend mruby script option and is called for all requests. The per-pattern mruby script
is set by "mruby" parameter in :option:`-b` option. It is invoked for is set by "mruby" parameter in :option:`-b` option. It is invoked for
a request which is forwarded to the particular backend. The order of a request which matches the particular pattern. The order of hook
hook invocation is: global request phase hook, per-backend request invocation is: global request phase hook, per-pattern request phase
phase hook, per-backend response phase hook, and finally global hook, per-pattern response phase hook, and finally global response
response phase hook. If a hook returns a response, any later hooks phase hook. If a hook returns a response, any later hooks are not
are not invoked. The global request hook is invoked before selecting invoked. The global request hook is invoked before the pattern
backend, and changing request path may affect the backend selection. matching is made and changing request path may affect the pattern
matching.
The all mruby script will be evaluated once per thread on startup, and The all mruby script will be evaluated once per thread on startup, and
it must instantiate object and evaluate it as the return value (e.g., it must instantiate object and evaluate it as the return value (e.g.,

View File

@ -169,7 +169,7 @@ OPTIONS = [
"ocsp-startup", "ocsp-startup",
"no-verify-ocsp", "no-verify-ocsp",
"verify-client-tolerate-expired", "verify-client-tolerate-expired",
"ignore-per-backend-mruby-error", "ignore-per-pattern-mruby-error",
] ]
LOGVARS = [ LOGVARS = [

View File

@ -1829,8 +1829,9 @@ Connections:
field on TLS encrypted connection. field on TLS encrypted connection.
"mruby=<PATH>" parameter specifies a path to mruby "mruby=<PATH>" parameter specifies a path to mruby
script file which is invoked when this backend is script file which is invoked when this pattern is
selected. matched. All backends which share the same pattern must
have the same mruby path.
Since ";" and ":" are used as delimiter, <PATTERN> must Since ";" and ":" are used as delimiter, <PATTERN> must
not contain these characters. Since ";" has special not contain these characters. Since ";" has special
@ -2754,10 +2755,10 @@ Process:
Scripting: Scripting:
--mruby-file=<PATH> --mruby-file=<PATH>
Set mruby script file Set mruby script file
--ignore-per-backend-mruby-error --ignore-per-pattern-mruby-error
Ignore mruby compile error for per-backend mruby script Ignore mruby compile error for per-pattern mruby script
file. If error occurred, it is treated as if no mruby file. If error occurred, it is treated as if no mruby
file were specified for the backend. file were specified for the pattern.
Misc: Misc:
--conf=<PATH> --conf=<PATH>
@ -3433,7 +3434,7 @@ int main(int argc, char **argv) {
{SHRPX_OPT_SINGLE_PROCESS.c_str(), no_argument, &flag, 159}, {SHRPX_OPT_SINGLE_PROCESS.c_str(), no_argument, &flag, 159},
{SHRPX_OPT_VERIFY_CLIENT_TOLERATE_EXPIRED.c_str(), no_argument, &flag, {SHRPX_OPT_VERIFY_CLIENT_TOLERATE_EXPIRED.c_str(), no_argument, &flag,
160}, 160},
{SHRPX_OPT_IGNORE_PER_BACKEND_MRUBY_ERROR.c_str(), no_argument, &flag, {SHRPX_OPT_IGNORE_PER_PATTERN_MRUBY_ERROR.c_str(), no_argument, &flag,
161}, 161},
{nullptr, 0, nullptr, 0}}; {nullptr, 0, nullptr, 0}};
@ -4202,8 +4203,8 @@ int main(int argc, char **argv) {
StringRef::from_lit("yes")); StringRef::from_lit("yes"));
break; break;
case 161: case 161:
// --ignore-per-backend-mruby-error // --ignore-per-pattern-mruby-error
cmdcfgs.emplace_back(SHRPX_OPT_IGNORE_PER_BACKEND_MRUBY_ERROR, cmdcfgs.emplace_back(SHRPX_OPT_IGNORE_PER_PATTERN_MRUBY_ERROR,
StringRef::from_lit("yes")); StringRef::from_lit("yes"));
break; break;
default: default:

View File

@ -2199,8 +2199,8 @@ int option_lookup_token(const char *name, size_t namelen) {
} }
break; break;
case 'r': case 'r':
if (util::strieq_l("ignore-per-backend-mruby-erro", name, 29)) { if (util::strieq_l("ignore-per-pattern-mruby-erro", name, 29)) {
return SHRPX_OPTID_IGNORE_PER_BACKEND_MRUBY_ERROR; return SHRPX_OPTID_IGNORE_PER_PATTERN_MRUBY_ERROR;
} }
if (util::strieq_l("strip-incoming-x-forwarded-fo", name, 29)) { if (util::strieq_l("strip-incoming-x-forwarded-fo", name, 29)) {
return SHRPX_OPTID_STRIP_INCOMING_X_FORWARDED_FOR; return SHRPX_OPTID_STRIP_INCOMING_X_FORWARDED_FOR;
@ -3587,8 +3587,8 @@ int parse_config(Config *config, int optid, const StringRef &opt,
config->tls.client_verify.tolerate_expired = util::strieq_l("yes", optarg); config->tls.client_verify.tolerate_expired = util::strieq_l("yes", optarg);
return 0; return 0;
case SHRPX_OPTID_IGNORE_PER_BACKEND_MRUBY_ERROR: case SHRPX_OPTID_IGNORE_PER_PATTERN_MRUBY_ERROR:
config->ignore_per_backend_mruby_error = util::strieq_l("yes", optarg); config->ignore_per_pattern_mruby_error = util::strieq_l("yes", optarg);
return 0; return 0;
case SHRPX_OPTID_CONF: case SHRPX_OPTID_CONF:
@ -3885,10 +3885,10 @@ int configure_downstream_group(Config *config, bool http2_proxy,
// Try compile mruby script and catch compile error early. // Try compile mruby script and catch compile error early.
if (!g.mruby_file.empty()) { if (!g.mruby_file.empty()) {
if (mruby::create_mruby_context(g.mruby_file) == nullptr) { if (mruby::create_mruby_context(g.mruby_file) == nullptr) {
LOG(config->ignore_per_backend_mruby_error ? ERROR : FATAL) LOG(config->ignore_per_pattern_mruby_error ? ERROR : FATAL)
<< "backend: Could not compile mruby flie for pattern " << "backend: Could not compile mruby flie for pattern "
<< g.pattern; << g.pattern;
if (!config->ignore_per_backend_mruby_error) { if (!config->ignore_per_pattern_mruby_error) {
return -1; return -1;
} }
g.mruby_file = StringRef{}; g.mruby_file = StringRef{};

View File

@ -345,8 +345,8 @@ constexpr auto SHRPX_OPT_OCSP_STARTUP = StringRef::from_lit("ocsp-startup");
constexpr auto SHRPX_OPT_NO_VERIFY_OCSP = StringRef::from_lit("no-verify-ocsp"); constexpr auto SHRPX_OPT_NO_VERIFY_OCSP = StringRef::from_lit("no-verify-ocsp");
constexpr auto SHRPX_OPT_VERIFY_CLIENT_TOLERATE_EXPIRED = constexpr auto SHRPX_OPT_VERIFY_CLIENT_TOLERATE_EXPIRED =
StringRef::from_lit("verify-client-tolerate-expired"); StringRef::from_lit("verify-client-tolerate-expired");
constexpr auto SHRPX_OPT_IGNORE_PER_BACKEND_MRUBY_ERROR = constexpr auto SHRPX_OPT_IGNORE_PER_PATTERN_MRUBY_ERROR =
StringRef::from_lit("ignore-per-backend-mruby-error"); StringRef::from_lit("ignore-per-pattern-mruby-error");
constexpr size_t SHRPX_OBFUSCATED_NODE_LENGTH = 8; constexpr size_t SHRPX_OBFUSCATED_NODE_LENGTH = 8;
@ -918,7 +918,7 @@ struct Config {
http2_proxy{false}, http2_proxy{false},
single_process{false}, single_process{false},
single_thread{false}, single_thread{false},
ignore_per_backend_mruby_error{false}, ignore_per_pattern_mruby_error{false},
ev_loop_flags{0} {} ev_loop_flags{0} {}
~Config(); ~Config();
@ -963,8 +963,8 @@ struct Config {
// handling is omitted. // handling is omitted.
bool single_process; bool single_process;
bool single_thread; bool single_thread;
// Ignore mruby compile error for per-backend mruby script. // Ignore mruby compile error for per-pattern mruby script.
bool ignore_per_backend_mruby_error; bool ignore_per_pattern_mruby_error;
// flags passed to ev_default_loop() and ev_loop_new() // flags passed to ev_default_loop() and ev_loop_new()
int ev_loop_flags; int ev_loop_flags;
}; };
@ -1069,7 +1069,7 @@ enum {
SHRPX_OPTID_HTTP2_MAX_CONCURRENT_STREAMS, SHRPX_OPTID_HTTP2_MAX_CONCURRENT_STREAMS,
SHRPX_OPTID_HTTP2_NO_COOKIE_CRUMBLING, SHRPX_OPTID_HTTP2_NO_COOKIE_CRUMBLING,
SHRPX_OPTID_HTTP2_PROXY, SHRPX_OPTID_HTTP2_PROXY,
SHRPX_OPTID_IGNORE_PER_BACKEND_MRUBY_ERROR, SHRPX_OPTID_IGNORE_PER_PATTERN_MRUBY_ERROR,
SHRPX_OPTID_INCLUDE, SHRPX_OPTID_INCLUDE,
SHRPX_OPTID_INSECURE, SHRPX_OPTID_INSECURE,
SHRPX_OPTID_LISTENER_DISABLE_TIMEOUT, SHRPX_OPTID_LISTENER_DISABLE_TIMEOUT,