nghttpx: Fix location rewrite does not work

This commit is contained in:
Tatsuhiro Tsujikawa 2015-02-08 18:54:24 +09:00
parent 7b81136bb3
commit 807d39abe3
7 changed files with 29 additions and 10 deletions

View File

@ -55,6 +55,7 @@ int main(int argc, char *argv[]) {
SSL_library_init();
shrpx::create_config();
shrpx::mod_config()->no_host_rewrite = true;
// initialize the CUnit test registry
if (CUE_SUCCESS != CU_initialize_registry())

View File

@ -548,6 +548,7 @@ Downstream::rewrite_location_response_header(const std::string &upstream_scheme,
return;
}
std::string new_uri;
if (get_config()->no_host_rewrite) {
if (!request_http2_authority_.empty()) {
new_uri =
http2::rewrite_location_uri((*hd).value, u, request_http2_authority_,
@ -561,6 +562,13 @@ Downstream::rewrite_location_response_header(const std::string &upstream_scheme,
new_uri = http2::rewrite_location_uri((*hd).value, u, (*host).value,
upstream_scheme, upstream_port);
}
} else {
assert(dconn_);
auto request_host =
get_config()->downstream_addrs[dconn_->get_addr_idx()].host.get();
new_uri = http2::rewrite_location_uri((*hd).value, u, request_host,
upstream_scheme, upstream_port);
}
if (!new_uri.empty()) {
auto idx = response_hdidx_[http2::HD_LOCATION];
response_headers_[idx].value = std::move(new_uri);

View File

@ -58,6 +58,8 @@ public:
virtual void on_upstream_change(Upstream *uptream) = 0;
virtual int on_priority_change(int32_t pri) = 0;
virtual size_t get_addr_idx() const = 0;
void set_client_handler(ClientHandler *client_handler);
ClientHandler *get_client_handler();
Downstream *get_downstream();

View File

@ -578,4 +578,6 @@ int Http2DownstreamConnection::on_timeout() {
return submit_rst_stream(downstream_, NGHTTP2_NO_ERROR);
}
size_t Http2DownstreamConnection::get_addr_idx() const { return 0; }
} // namespace shrpx

View File

@ -62,6 +62,8 @@ public:
virtual void on_upstream_change(Upstream *upstream) {}
virtual int on_priority_change(int32_t pri);
virtual size_t get_addr_idx() const;
int send();
void attach_stream_data(StreamData *sd);

View File

@ -767,4 +767,6 @@ void HttpDownstreamConnection::on_upstream_change(Upstream *upstream) {}
void HttpDownstreamConnection::signal_write() { conn_.wlimit.startw(); }
size_t HttpDownstreamConnection::get_addr_idx() const { return addr_idx_; }
} // namespace shrpx

View File

@ -59,6 +59,8 @@ public:
virtual void on_upstream_change(Upstream *upstream);
virtual int on_priority_change(int32_t pri) { return 0; }
virtual size_t get_addr_idx() const;
int on_connect();
void signal_write();