Url rewrite is not updating the host header for full host rewrites

I am trying out the rewrite feature.

The goal here is to cature everything begin with /sdf/(.*) and request to another upstream provider.

And in the gateway logs, I am seeing:

gateway_1    | time="Mar  1 06:59:18" level=debug msg="Rewriter active"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="/sdf/2/"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="Inbound path: /sdf/2/"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="Rewriter checking matches, len is: 1"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="[[/sdf/2/ 2/]]"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="[[$1]]"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="Replacing: $1"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="URL Re-written from: /sdf/2/"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="URL Re-written to: http://httpbin.org/get?q=2/"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="Detected a host rewrite in pattern!"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="Started proxy"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="Stripping: /"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="Upstream Path is: get"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="Serving Multi-target..."
gateway_1    | time="Mar  1 06:59:18" level=debug msg="UPSTREAM REQUEST URL: http://httpbin.org/get?q=2/"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="Detected host rewrite, notifying director"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="Detected host rewrite, overriding target"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="Outbound Request: http://httpbin.org/get?q=2/"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="Upstream request took (ms): 321.94604699999996"

However, the response I am getting back from the gateway is:

curl -v http://tyk.api.com:8080/sdf/2/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to tyk.api.com (127.0.0.1) port 8080 (#0)
> GET /sdf/2/ HTTP/1.1
> Host: tyk.api.com:8080
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< Connection: close
< Content-Type: text/html
< Date: Thu, 01 Mar 2018 07:04:09 GMT
< Server: meinheld/0.6.1
< Via: 1.1 vegur
< X-Ratelimit-Limit: 0
< X-Ratelimit-Remaining: 0
< X-Ratelimit-Reset: 1519887859
< Content-Length: 84
<
* Closing connection 0
<html><head><title>Bad Request</title></head><body><p>Bad Request.</p></body></html>

I even tried to rewrite the header value with the proper Host value, but that is not working as well.

Hello!

Seems like issue happens because of the not encoded “/” symbol, can you confirm that without “/” it works?

Also do you have “skip_target_path_escaping” in your config, and what is its value?

Thank you.

I removed the / from /sdf/(.*), so now it is sdf/(.*) (following the hint from the input virtual/(.*)/(d+))

However, I am still seeing the same behaviour.

I do not have the skip_target_path_escaping option. tyk.conf for that section looks like:

  "http_server_options": {
    "enable_websockets": true
  },

I am happy to post the full API definition if needed. I suspect it is a Host header issue since in the gateway’s debug log we are seeing the proper url being formed.

gateway_1    | time="Mar  1 06:59:18" level=debug msg="URL Re-written from: /sdf/2/"
gateway_1    | time="Mar  1 06:59:18" level=debug msg="URL Re-written to: http://httpbin.org/get?q=2/"