nghttpx: Use StringAdaptor for Config::server_name
This commit is contained in:
parent
2c7ed01f0c
commit
d16ff1f519
|
@ -1039,7 +1039,7 @@ void fill_default_config() {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void print_version(std::ostream &out) {
|
void print_version(std::ostream &out) {
|
||||||
out << get_config()->server_name << std::endl;
|
out << get_config()->server_name.c_str() << std::endl;
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
|
@ -311,6 +311,7 @@ struct Config {
|
||||||
// string is provided.
|
// string is provided.
|
||||||
std::string forwarded_for_obfuscated;
|
std::string forwarded_for_obfuscated;
|
||||||
std::string backend_tls_sni_name;
|
std::string backend_tls_sni_name;
|
||||||
|
StringAdaptor server_name;
|
||||||
std::chrono::seconds tls_session_timeout;
|
std::chrono::seconds tls_session_timeout;
|
||||||
ev_tstamp http2_upstream_read_timeout;
|
ev_tstamp http2_upstream_read_timeout;
|
||||||
ev_tstamp upstream_read_timeout;
|
ev_tstamp upstream_read_timeout;
|
||||||
|
@ -363,7 +364,6 @@ struct Config {
|
||||||
nghttp2_option *http2_option;
|
nghttp2_option *http2_option;
|
||||||
nghttp2_option *http2_client_option;
|
nghttp2_option *http2_client_option;
|
||||||
const EVP_CIPHER *tls_ticket_key_cipher;
|
const EVP_CIPHER *tls_ticket_key_cipher;
|
||||||
const char *server_name;
|
|
||||||
char **original_argv;
|
char **original_argv;
|
||||||
char **argv;
|
char **argv;
|
||||||
char *cwd;
|
char *cwd;
|
||||||
|
|
|
@ -44,7 +44,8 @@ std::string create_error_html(unsigned int status_code) {
|
||||||
res += "</title><body><h1>";
|
res += "</title><body><h1>";
|
||||||
res += status;
|
res += status;
|
||||||
res += "</h1><footer>";
|
res += "</h1><footer>";
|
||||||
res += get_config()->server_name;
|
const auto &server_name = get_config()->server_name;
|
||||||
|
res.append(server_name.c_str(), server_name.size());
|
||||||
res += " at port ";
|
res += " at port ";
|
||||||
res += util::utos(get_config()->port);
|
res += util::utos(get_config()->port);
|
||||||
res += "</footer></body></html>";
|
res += "</footer></body></html>";
|
||||||
|
|
|
@ -1337,7 +1337,7 @@ int Http2Upstream::send_reply(Downstream *downstream, const uint8_t *body,
|
||||||
|
|
||||||
if (!resp.fs.header(http2::HD_SERVER)) {
|
if (!resp.fs.header(http2::HD_SERVER)) {
|
||||||
nva.push_back(
|
nva.push_back(
|
||||||
http2::make_nv_lc_nocopy("server", get_config()->server_name));
|
http2::make_nv_ls_nocopy("server", get_config()->server_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = nghttp2_submit_response(session_, downstream->get_stream_id(),
|
rv = nghttp2_submit_response(session_, downstream->get_stream_id(),
|
||||||
|
@ -1386,7 +1386,7 @@ int Http2Upstream::error_reply(Downstream *downstream,
|
||||||
: http2::make_nv_ls(":status",
|
: http2::make_nv_ls(":status",
|
||||||
(status_code_str = util::utos(status_code))),
|
(status_code_str = util::utos(status_code))),
|
||||||
http2::make_nv_ll("content-type", "text/html; charset=UTF-8"),
|
http2::make_nv_ll("content-type", "text/html; charset=UTF-8"),
|
||||||
http2::make_nv_lc_nocopy("server", get_config()->server_name),
|
http2::make_nv_ls_nocopy("server", get_config()->server_name),
|
||||||
http2::make_nv_ls("content-length", content_length),
|
http2::make_nv_ls("content-length", content_length),
|
||||||
http2::make_nv_ls("date", lgconf->time_http_str));
|
http2::make_nv_ls("date", lgconf->time_http_str));
|
||||||
|
|
||||||
|
@ -1507,7 +1507,7 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) {
|
||||||
|
|
||||||
if (!get_config()->http2_proxy && !get_config()->client_proxy) {
|
if (!get_config()->http2_proxy && !get_config()->client_proxy) {
|
||||||
nva.push_back(
|
nva.push_back(
|
||||||
http2::make_nv_lc_nocopy("server", get_config()->server_name));
|
http2::make_nv_ls_nocopy("server", get_config()->server_name));
|
||||||
} else {
|
} else {
|
||||||
auto server = resp.fs.header(http2::HD_SERVER);
|
auto server = resp.fs.header(http2::HD_SERVER);
|
||||||
if (server) {
|
if (server) {
|
||||||
|
|
|
@ -802,8 +802,8 @@ int HttpsUpstream::send_reply(Downstream *downstream, const uint8_t *body,
|
||||||
|
|
||||||
if (!resp.fs.header(http2::HD_SERVER)) {
|
if (!resp.fs.header(http2::HD_SERVER)) {
|
||||||
output->append("Server: ");
|
output->append("Server: ");
|
||||||
output->append(get_config()->server_name,
|
const auto &server_name = get_config()->server_name;
|
||||||
strlen(get_config()->server_name));
|
output->append(server_name.c_str(), server_name.size());
|
||||||
output->append("\r\n");
|
output->append("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -840,7 +840,8 @@ void HttpsUpstream::error_reply(unsigned int status_code) {
|
||||||
auto status_str = http2::get_status_string(status_code);
|
auto status_str = http2::get_status_string(status_code);
|
||||||
output->append(status_str.c_str(), status_str.size());
|
output->append(status_str.c_str(), status_str.size());
|
||||||
output->append("\r\nServer: ");
|
output->append("\r\nServer: ");
|
||||||
output->append(get_config()->server_name, strlen(get_config()->server_name));
|
const auto &server_name = get_config()->server_name;
|
||||||
|
output->append(server_name.c_str(), server_name.size());
|
||||||
output->append("\r\nContent-Length: ");
|
output->append("\r\nContent-Length: ");
|
||||||
auto cl = util::utos(html.size());
|
auto cl = util::utos(html.size());
|
||||||
output->append(cl.c_str(), cl.size());
|
output->append(cl.c_str(), cl.size());
|
||||||
|
@ -999,7 +1000,8 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream) {
|
||||||
|
|
||||||
if (!get_config()->http2_proxy && !get_config()->client_proxy) {
|
if (!get_config()->http2_proxy && !get_config()->client_proxy) {
|
||||||
buf->append("Server: ");
|
buf->append("Server: ");
|
||||||
buf->append(get_config()->server_name, strlen(get_config()->server_name));
|
const auto &server_name = get_config()->server_name;
|
||||||
|
buf->append(server_name.c_str(), server_name.size());
|
||||||
buf->append("\r\n");
|
buf->append("\r\n");
|
||||||
} else {
|
} else {
|
||||||
auto server = resp.fs.header(http2::HD_SERVER);
|
auto server = resp.fs.header(http2::HD_SERVER);
|
||||||
|
|
|
@ -875,7 +875,7 @@ int SpdyUpstream::send_reply(Downstream *downstream, const uint8_t *body,
|
||||||
|
|
||||||
if (!resp.fs.header(http2::HD_SERVER)) {
|
if (!resp.fs.header(http2::HD_SERVER)) {
|
||||||
nva.push_back("server");
|
nva.push_back("server");
|
||||||
nva.push_back(get_config()->server_name);
|
nva.push_back(get_config()->server_name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
nva.push_back(nullptr);
|
nva.push_back(nullptr);
|
||||||
|
@ -919,7 +919,7 @@ int SpdyUpstream::error_reply(Downstream *downstream,
|
||||||
std::string status_string = http2::get_status_string(status_code);
|
std::string status_string = http2::get_status_string(status_code);
|
||||||
const char *nv[] = {":status", status_string.c_str(), ":version", "http/1.1",
|
const char *nv[] = {":status", status_string.c_str(), ":version", "http/1.1",
|
||||||
"content-type", "text/html; charset=UTF-8", "server",
|
"content-type", "text/html; charset=UTF-8", "server",
|
||||||
get_config()->server_name, "content-length",
|
get_config()->server_name.c_str(), "content-length",
|
||||||
content_length.c_str(), "date",
|
content_length.c_str(), "date",
|
||||||
lgconf->time_http_str.c_str(), nullptr};
|
lgconf->time_http_str.c_str(), nullptr};
|
||||||
|
|
||||||
|
@ -1034,7 +1034,7 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream) {
|
||||||
|
|
||||||
if (!get_config()->http2_proxy && !get_config()->client_proxy) {
|
if (!get_config()->http2_proxy && !get_config()->client_proxy) {
|
||||||
nv[hdidx++] = "server";
|
nv[hdidx++] = "server";
|
||||||
nv[hdidx++] = get_config()->server_name;
|
nv[hdidx++] = get_config()->server_name.c_str();
|
||||||
} else {
|
} else {
|
||||||
auto server = resp.fs.header(http2::HD_SERVER);
|
auto server = resp.fs.header(http2::HD_SERVER);
|
||||||
if (server) {
|
if (server) {
|
||||||
|
|
|
@ -227,9 +227,11 @@ struct VString {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StringAdaptor {
|
struct StringAdaptor {
|
||||||
|
StringAdaptor() : base(""), len(0) {}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
StringAdaptor(const T &s)
|
StringAdaptor(const T &s)
|
||||||
: base(s.c_str()), len(s.size()) {}
|
: base(s.c_str()), len(s.size()) {}
|
||||||
|
StringAdaptor(const char *s) : base(s), len(strlen(s)) {}
|
||||||
|
|
||||||
const char *c_str() const { return base; }
|
const char *c_str() const { return base; }
|
||||||
size_t size() const { return len; }
|
size_t size() const { return len; }
|
||||||
|
|
Loading…
Reference in New Issue