Strip Request Path

702 views
Skip to first unread message

Gregory Harris

unread,
Dec 17, 2015, 5:32:49 PM12/17/15
to Kong
Hi,

I'm obviously confused as to what the Strip Request Path is doing, since I don't detect any difference when enabling it.

I'm running Kong version: 0.5.4.

I have a simple service running locally to echo the request URL.  e.g.

  • curl -i -X GET echo.nw:8091/customer/fred/eric/3

->

(I didn't bother with the port)


So I configure an API on a local Kong instance as follows:


echo

AttributeValue
request_hostecho.nw
request_path/echo
upstream_urlhttp://echo.nw:8091
strip_request_pathfalse
preserve_host

I make my request:

  • curl -i -X GET echo.nw:8000/echo/customer/fred/eric/3

and get back:


All as expected, but now I decide to turn on strip_request_path (thinking it should remove the '/echo') and restart kong.


Make my request:

  • curl -i -X GET echo.nw:8000/echo/customer/fred/eric/3

and get back:

Which is exactly the same value as before.


Am I missing something here?


Sincerely,


Greg Harris

Thibault Charbonnier

unread,
Dec 17, 2015, 6:54:11 PM12/17/15
to Kong
strip_request_path should indeed remove the "/echo" part. Can you make sure the strip_request_path property is indeed set to true by querying the API from the Admin API, since you could have run into this issue: https://github.com/Mashape/kong/issues/765

Gregory Harris

unread,
Dec 17, 2015, 8:48:37 PM12/17/15
to Kong
Here's the output from Postman (because it formats it a little nicer):

{
  "upstream_url": "http://echo.nw:8091",
  "request_path": "/echo",
  "id": "c45ac301-445a-4296-c251-540db18d937b",
  "strip_request_path": true,
  "name": "echo",
  "created_at": 1450386775000,
  "request_host": "echo.nw"

Thibault Charbonnier

unread,
Dec 19, 2015, 5:03:48 AM12/19/15
to Kong
I just ran Kong 0.5.4 with the following:

http :8001/apis upstream_url=http://httpbin.org request_path=/httpbin
HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
Server: kong/0.5.4

{
    "created_at": 1450519058000,
    "id": "da28f722-495e-4a9c-cab7-0ff0b69a9373",
    "name": "httpbin",
    "request_path": "/httpbin",
    "upstream_url": "http://httpbin.org"
}


As expected, the upstream URL is invalid from httpbin's POV:

http :8000/httpbin/get
HTTP/1.1 404 NOT FOUND
Content-Length: 233
Content-Type: text/html; charset=UTF-8
Server: nginx
Via: kong/0.5.4

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>

Once updated, and the cache clear (60s or kong reload):

http PATCH :8001/apis/httpbin strip_request_path=true
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Server: kong/0.5.4

{
    "created_at": 1450519058000,
    "id": "da28f722-495e-4a9c-cab7-0ff0b69a9373",
    "name": "httpbin",
    "request_path": "/httpbin",
    "strip_request_path": true,
    "upstream_url": "http://httpbin.org"
}

The upstream URL is stripped from the request_path and thus, correct:

http :8000/httpbin/get
HTTP/1.1 200 OK
Content-Length: 239
Content-Type: application/json
Server: nginx
Via: kong/0.5.4

{
    "args": {},
    "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate",
        "Host": "httpbin.org",
        "User-Agent": "HTTPie/0.9.2"
    },
    "origin": "127.0.0.1, 73.241.244.85",
    "url": "http://httpbin.org/get"
}

joe.an...@gmail.com

unread,
Dec 28, 2015, 11:35:22 PM12/28/15
to Kong
I had the same problem as OP.

Few things:

KONG_IP: 1.2.3.4
myapp.com: A Record KONG_IP

Configuration:
{"upstream_url": "http://internal-app/","request_path": "/foobar","id": "02e10318-2ee1-48dc-c8e3-5ced48127efb","strip_request_path": true,"name": "myapp","created_at": 1451362467000,"request_host": "myapp.com"},

I tried accessing via (myapp.com/foobar) and it didn't strip the path. (http://internal-app/foobar).

I tried accessing via (http://KONG_IP/foobar) and it appropriately stripped the path. (http://internal-app/).


I was able to get it to work with myapp.com/foobar if I created without the request_host:

{"upstream_url": "http://internal-app/","request_path": "/foobar","id": "00010318-2ee1-48dc-c8e3-5ced48127efb","strip_request_path": true,"name": "myapp","created_at": 1451312367000
}

Thibault Charbonnier

unread,
Dec 29, 2015, 5:01:21 AM12/29/15
to joe.an...@gmail.com, Kong
strip_request_path only has influence of the request was proxies by request_path (as per name). However, request_host has priority over request_path. If you define your API with a host and if that is how Kong proxies it, then strip_request_path will not apply. 
--
You received this message because you are subscribed to the Google Groups "Kong" group.
To unsubscribe from this group and stop receiving emails from it, send an email to konglayer+...@googlegroups.com.
To post to this group, send email to kong...@googlegroups.com.
Visit this group at https://groups.google.com/group/konglayer.
To view this discussion on the web visit https://groups.google.com/d/msgid/konglayer/cd343b10-d2a6-48d9-af1b-48a6f24218ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

joe.an...@gmail.com

unread,
Dec 29, 2015, 9:33:06 AM12/29/15
to Kong, joe.an...@gmail.com
The documentation here uses both request_path and request_host but doesn't explain how they relate or precedence.


It may be helpful to update the documentation to distinguish how to use one over the other or both.
To unsubscribe from this group and stop receiving emails from it, send an email to konglayer+unsubscribe@googlegroups.com.

Thibault Charbonnier

unread,
Jan 5, 2016, 11:14:13 PM1/5/16
to Kong, joe.an...@gmail.com
Added a note to this document here: https://github.com/Mashape/getkong.org/pull/190
Reply all
Reply to author
Forward
0 new messages