nghttpx: Fix location rewrite does not work
This commit is contained in:
parent
7b81136bb3
commit
807d39abe3
|
@ -55,6 +55,7 @@ int main(int argc, char *argv[]) {
|
||||||
SSL_library_init();
|
SSL_library_init();
|
||||||
|
|
||||||
shrpx::create_config();
|
shrpx::create_config();
|
||||||
|
shrpx::mod_config()->no_host_rewrite = true;
|
||||||
|
|
||||||
// initialize the CUnit test registry
|
// initialize the CUnit test registry
|
||||||
if (CUE_SUCCESS != CU_initialize_registry())
|
if (CUE_SUCCESS != CU_initialize_registry())
|
||||||
|
|
|
@ -548,17 +548,25 @@ Downstream::rewrite_location_response_header(const std::string &upstream_scheme,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::string new_uri;
|
std::string new_uri;
|
||||||
if (!request_http2_authority_.empty()) {
|
if (get_config()->no_host_rewrite) {
|
||||||
new_uri =
|
if (!request_http2_authority_.empty()) {
|
||||||
http2::rewrite_location_uri((*hd).value, u, request_http2_authority_,
|
new_uri =
|
||||||
upstream_scheme, upstream_port);
|
http2::rewrite_location_uri((*hd).value, u, request_http2_authority_,
|
||||||
}
|
upstream_scheme, upstream_port);
|
||||||
if (new_uri.empty()) {
|
|
||||||
auto host = get_request_header(http2::HD_HOST);
|
|
||||||
if (!host) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
new_uri = http2::rewrite_location_uri((*hd).value, u, (*host).value,
|
if (new_uri.empty()) {
|
||||||
|
auto host = get_request_header(http2::HD_HOST);
|
||||||
|
if (!host) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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);
|
upstream_scheme, upstream_port);
|
||||||
}
|
}
|
||||||
if (!new_uri.empty()) {
|
if (!new_uri.empty()) {
|
||||||
|
|
|
@ -58,6 +58,8 @@ public:
|
||||||
virtual void on_upstream_change(Upstream *uptream) = 0;
|
virtual void on_upstream_change(Upstream *uptream) = 0;
|
||||||
virtual int on_priority_change(int32_t pri) = 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);
|
void set_client_handler(ClientHandler *client_handler);
|
||||||
ClientHandler *get_client_handler();
|
ClientHandler *get_client_handler();
|
||||||
Downstream *get_downstream();
|
Downstream *get_downstream();
|
||||||
|
|
|
@ -578,4 +578,6 @@ int Http2DownstreamConnection::on_timeout() {
|
||||||
return submit_rst_stream(downstream_, NGHTTP2_NO_ERROR);
|
return submit_rst_stream(downstream_, NGHTTP2_NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t Http2DownstreamConnection::get_addr_idx() const { return 0; }
|
||||||
|
|
||||||
} // namespace shrpx
|
} // namespace shrpx
|
||||||
|
|
|
@ -62,6 +62,8 @@ public:
|
||||||
virtual void on_upstream_change(Upstream *upstream) {}
|
virtual void on_upstream_change(Upstream *upstream) {}
|
||||||
virtual int on_priority_change(int32_t pri);
|
virtual int on_priority_change(int32_t pri);
|
||||||
|
|
||||||
|
virtual size_t get_addr_idx() const;
|
||||||
|
|
||||||
int send();
|
int send();
|
||||||
|
|
||||||
void attach_stream_data(StreamData *sd);
|
void attach_stream_data(StreamData *sd);
|
||||||
|
|
|
@ -767,4 +767,6 @@ void HttpDownstreamConnection::on_upstream_change(Upstream *upstream) {}
|
||||||
|
|
||||||
void HttpDownstreamConnection::signal_write() { conn_.wlimit.startw(); }
|
void HttpDownstreamConnection::signal_write() { conn_.wlimit.startw(); }
|
||||||
|
|
||||||
|
size_t HttpDownstreamConnection::get_addr_idx() const { return addr_idx_; }
|
||||||
|
|
||||||
} // namespace shrpx
|
} // namespace shrpx
|
||||||
|
|
|
@ -59,6 +59,8 @@ public:
|
||||||
virtual void on_upstream_change(Upstream *upstream);
|
virtual void on_upstream_change(Upstream *upstream);
|
||||||
virtual int on_priority_change(int32_t pri) { return 0; }
|
virtual int on_priority_change(int32_t pri) { return 0; }
|
||||||
|
|
||||||
|
virtual size_t get_addr_idx() const;
|
||||||
|
|
||||||
int on_connect();
|
int on_connect();
|
||||||
void signal_write();
|
void signal_write();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue