diff --git a/src/shrpx.cc b/src/shrpx.cc index 605f77ec..cd456934 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -1843,12 +1843,13 @@ HTTP: towards this number. Default: )" << get_config()->http.max_response_header_fields << R"( - --error-page== + --error-page=(|*)= Set file path to custom error page served when nghttpx originally generates HTTP error status code . must be greater than or equal to 400, and at most - 599. If error status code comes from backend server, - the custom error pages are not used. + 599. If "*" is used instead of , it matches all + HTTP status code. If error status code comes from + backend server, the custom error pages are not used. Debug: --frontend-http2-dump-request-header= diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index 867ed620..985b8d4b 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -715,11 +715,19 @@ int parse_error_page(std::vector &error_pages, const char *opt, } auto codestr = StringRef{std::begin(arg), eq}; - auto code = util::parse_uint(codestr); + unsigned int code; - if (code == -1 || code < 400 || code > 599) { - LOG(ERROR) << opt << ": bad code: '" << codestr << "'"; - return -1; + if (codestr == "*") { + code = 0; + } else { + auto n = util::parse_uint(codestr); + + if (n == -1 || n < 400 || n > 599) { + LOG(ERROR) << opt << ": bad code: '" << codestr << "'"; + return -1; + } + + code = static_cast(n); } auto path = StringRef{eq + 1, std::end(arg)}; @@ -748,8 +756,7 @@ int parse_error_page(std::vector &error_pages, const char *opt, content.insert(std::end(content), std::begin(buf), std::begin(buf) + n); } - error_pages.push_back( - ErrorPage{std::move(content), static_cast(code)}); + error_pages.push_back(ErrorPage{std::move(content), code}); return 0; } diff --git a/src/shrpx_config.h b/src/shrpx_config.h index 2dc23da8..0d0b6c8e 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -443,6 +443,7 @@ struct TLSConfig { struct ErrorPage { // not NULL-terminated std::vector content; + // 0 is special value, and it matches all HTTP status code. unsigned int http_status; }; diff --git a/src/shrpx_http.cc b/src/shrpx_http.cc index 4d483312..8f1bc751 100644 --- a/src/shrpx_http.cc +++ b/src/shrpx_http.cc @@ -40,7 +40,7 @@ StringRef create_error_html(BlockAllocator &balloc, unsigned int http_status) { const auto &error_pages = httpconf.error_pages; for (const auto &page : error_pages) { - if (page.http_status == http_status) { + if (page.http_status == 0 || page.http_status == http_status) { return StringRef{std::begin(page.content), std::end(page.content)}; } }