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();
|
||||
|
||||
shrpx::create_config();
|
||||
shrpx::mod_config()->no_host_rewrite = true;
|
||||
|
||||
// initialize the CUnit test registry
|
||||
if (CUE_SUCCESS != CU_initialize_registry())
|
||||
|
|
|
@ -548,17 +548,25 @@ Downstream::rewrite_location_response_header(const std::string &upstream_scheme,
|
|||
return;
|
||||
}
|
||||
std::string new_uri;
|
||||
if (!request_http2_authority_.empty()) {
|
||||
new_uri =
|
||||
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;
|
||||
if (get_config()->no_host_rewrite) {
|
||||
if (!request_http2_authority_.empty()) {
|
||||
new_uri =
|
||||
http2::rewrite_location_uri((*hd).value, u, request_http2_authority_,
|
||||
upstream_scheme, upstream_port);
|
||||
}
|
||||
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);
|
||||
}
|
||||
if (!new_uri.empty()) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue