Commit ef5d981a authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttpx: Simplify

parent d5efab49
......@@ -165,6 +165,7 @@ template <typename Memchunk> struct Memchunks {
return append(s, N - 1);
}
size_t append(const std::string &s) { return append(s.c_str(), s.size()); }
size_t append(const StringRef &s) { return append(s.c_str(), s.size()); }
size_t remove(void *dest, size_t count) {
if (!tail || count == 0) {
return 0;
......
......@@ -334,18 +334,15 @@ int Http2Session::initiate_connection() {
conn_.set_ssl(ssl);
}
const char *sni_name = nullptr;
if (!get_config()->backend_tls_sni_name.empty()) {
sni_name = get_config()->backend_tls_sni_name.c_str();
} else {
sni_name = downstream_addr.host.c_str();
}
StringRef sni_name = !get_config()->backend_tls_sni_name.empty()
? get_config()->backend_tls_sni_name
: downstream_addr.host;
if (sni_name && !util::numeric_host(sni_name)) {
if (!util::numeric_host(sni_name.c_str())) {
// TLS extensions: SNI. There is no documentation about the return
// code for this function (actually this is macro wrapping SSL_ctrl
// at the time of this writing).
SSL_set_tlsext_host_name(conn_.tls.ssl, sni_name);
SSL_set_tlsext_host_name(conn_.tls.ssl, sni_name.c_str());
}
// If state_ == PROXY_CONNECTED, we has connected to the proxy
// using conn_.fd and tunnel has been established.
......
......@@ -1365,7 +1365,7 @@ int Http2Upstream::error_reply(Downstream *downstream,
auto html = http::create_error_html(status_code);
resp.http_status = status_code;
auto body = downstream->get_response_buf();
body->append(html.c_str(), html.size());
body->append(html);
downstream->set_response_state(Downstream::MSG_COMPLETE);
nghttp2_data_provider data_prd;
......
......@@ -238,14 +238,14 @@ int HttpDownstreamConnection::push_request_headers() {
buf->append(" ");
if (connect_method) {
buf->append(authority.c_str(), authority.size());
buf->append(authority);
} else if (get_config()->http2_proxy || get_config()->client_proxy) {
// Construct absolute-form request target because we are going to
// send a request to a HTTP/1 proxy.
assert(!req.scheme.empty());
buf->append(req.scheme);
buf->append("://");
buf->append(authority.c_str(), authority.size());
buf->append(authority);
buf->append(req.path);
} else if (req.method == HTTP_OPTIONS && req.path.empty()) {
// Server-wide OPTIONS
......@@ -254,7 +254,7 @@ int HttpDownstreamConnection::push_request_headers() {
buf->append(req.path);
}
buf->append(" HTTP/1.1\r\nHost: ");
buf->append(authority.c_str(), authority.size());
buf->append(authority);
buf->append("\r\n");
http2::build_http1_headers_from_headers(buf, req.fs.headers());
......@@ -402,7 +402,7 @@ int HttpDownstreamConnection::push_upload_data_chunk(const uint8_t *data,
if (chunked) {
auto chunk_size_hex = util::utox(datalen);
output->append(chunk_size_hex.c_str(), chunk_size_hex.size());
output->append(chunk_size_hex);
output->append("\r\n");
}
......
......@@ -802,8 +802,7 @@ int HttpsUpstream::send_reply(Downstream *downstream, const uint8_t *body,
if (!resp.fs.header(http2::HD_SERVER)) {
output->append("Server: ");
const auto &server_name = get_config()->server_name;
output->append(server_name.c_str(), server_name.size());
output->append(get_config()->server_name);
output->append("\r\n");
}
......@@ -838,21 +837,21 @@ void HttpsUpstream::error_reply(unsigned int status_code) {
output->append("HTTP/1.1 ");
auto status_str = http2::get_status_string(status_code);
output->append(status_str.c_str(), status_str.size());
output->append(status_str);
output->append("\r\nServer: ");
const auto &server_name = get_config()->server_name;
output->append(server_name.c_str(), server_name.size());
output->append(server_name);
output->append("\r\nContent-Length: ");
auto cl = util::utos(html.size());
output->append(cl.c_str(), cl.size());
output->append(cl);
output->append("\r\nDate: ");
auto lgconf = log_config();
lgconf->update_tstamp(std::chrono::system_clock::now());
auto &date = lgconf->time_http_str;
output->append(date.c_str(), date.size());
output->append(date);
output->append("\r\nContent-Type: text/html; "
"charset=UTF-8\r\nConnection: close\r\n\r\n");
output->append(html.c_str(), html.size());
output->append(html);
downstream->response_sent_body_length += html.size();
downstream->set_response_state(Downstream::MSG_COMPLETE);
......@@ -1000,8 +999,7 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream) {
if (!get_config()->http2_proxy && !get_config()->client_proxy) {
buf->append("Server: ");
const auto &server_name = get_config()->server_name;
buf->append(server_name.c_str(), server_name.size());
buf->append(get_config()->server_name);
buf->append("\r\n");
} else {
auto server = resp.fs.header(http2::HD_SERVER);
......@@ -1054,10 +1052,8 @@ int HttpsUpstream::on_downstream_body(Downstream *downstream,
}
auto output = downstream->get_response_buf();
if (downstream->get_chunked_response()) {
auto chunk_size_hex = util::utox(len);
chunk_size_hex += "\r\n";
output->append(chunk_size_hex.c_str(), chunk_size_hex.size());
output->append(util::utox(len));
output->append("\r\n");
}
output->append(data, len);
......
......@@ -905,7 +905,7 @@ int SpdyUpstream::error_reply(Downstream *downstream,
auto html = http::create_error_html(status_code);
resp.http_status = status_code;
auto body = downstream->get_response_buf();
body->append(html.c_str(), html.size());
body->append(html);
downstream->set_response_state(Downstream::MSG_COMPLETE);
spdylay_data_provider data_prd;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment