Request Transformer --- Why the curl terminal command output results are different from FireFox?

Configure a Service in Kong
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/services/ \
--data 'name=country' \
--data 'url=http://contoso.com/v1/countries'

HTTP/1.1 201 Created
Date: Thu, 24 May 2018 00:51:42 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "host": "contoso.com", 
    "created_at": 1527094302, 
    "connect_timeout": 60000, 
    "id": "f45e19af-5528-45c9-af4c-96f3030a3af9", 
    "protocol": "http", 
    "name": "country", 
    "read_timeout": 60000, 
    "port": 80, 
    "path": "/v1/countries", 
    "updated_at": 1527094302, 
    "retries": 5, 
    "write_timeout": 60000
}



Add a Route to expose the Service
URL Format http://localhost:8001/services/{name of servie}/routes
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/services/country/routes \
--data 'paths[]=/v1/countries'

HTTP/1.1 201 Created
Date: Thu, 24 May 2018 00:52:03 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1527094323, 
    "strip_path": true, 
    "hosts": null, 
    "preserve_host": false, 
    "regex_priority": 0, 
    "updated_at": 1527094323, 
    "paths": [
        "/v1/countries"
    ], 
    "service": {
        "id": "f45e19af-5528-45c9-af4c-96f3030a3af9"
    }, 
    "methods": null, 
    "protocols": [
        "http", 
        "https"
    ], 
    "id": "0f896042-b496-4cc9-b5a5-cc17f4cf9cb7"   // {route_id} = id
}


===========================================================
ThinkPHP 5.1  Restful api
/home/myth/www/bookstore/application/api/controller/v1/Country.php
    public function getCountries() {
        return json([
            'RequestHeader'=>[
                'h1'=>request()->header('h1'),'h2'=>request()->header('h2'),
             ],
	    'p1'=>request()->param('p1'),
            'p2'=>request()->param('p2'),
            'p3'=>request()->param('p3'),
            'ResponseHeader'=>[
		'h1'=>response()->getHeader('h1'),'h2'=>response()->getHeader('h2'),
	     ],
	]);
        // $countries = Db::table('countries')->paginate(10,false,['query'=>request()->param('page')]);
        // return json($countries);
    }

/home/myth/www/bookstore/route/route.php
Route::get(':version/countries', 'api/:version.Country/getCountries')->header(['X-RateLimit-Limit-countries'=>'countries=3']);           

===============================================
Append multiple headers and remove a body parameter for the country service plugin:
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/services/country/plugins \
--header 'content-type: application/json' \
--data '{"name": "request-transformer", "config": {"append": {"headers": ["h1:v2", "h2:v1"]}, "remove": {"body": ["p1"]}}}'

HTTP/1.1 201 Created
Date: Thu, 24 May 2018 06:44:47 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1527144288000, 
    "config": {
        "remove": {
            "querystring": { }, 
            "headers": { }, 
            "body": [
                "p1"
            ]
        }, 
        "append": {
            "querystring": { }, 
            "headers": [
                "h1:v2", 
                "h2:v1"
            ], 
            "body": { }
        }, 
        "replace": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "add": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "rename": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }
    }, 
    "id": "51c85309-1db3-4f5b-8ef8-b498752c3536", 
    "enabled": true, 
    "service_id": "f45e19af-5528-45c9-af4c-96f3030a3af9", 
    "name": "request-transformer"
}

Append multiple headers and remove a body parameter for the country route plugin:
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/routes/0f896042-b496-4cc9-b5a5-cc17f4cf9cb7/plugins \
--header 'content-type: application/json' \
--data '{"name": "request-transformer", "config": {"append": {"headers": ["h1:v2", "h2:v1"]}, "remove": {"body": ["p1"]}}}'

HTTP/1.1 201 Created
Date: Thu, 24 May 2018 06:45:42 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1527144342000, 
    "config": {
        "remove": {
            "querystring": { }, 
            "headers": { }, 
            "body": [
                "p1"
            ]
        }, 
        "append": {
            "querystring": { }, 
            "headers": [
                "h1:v2", 
                "h2:v1"
            ], 
            "body": { }
        }, 
        "replace": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "add": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "rename": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }
    }, 
    "id": "1eef48e8-11b0-4179-b061-ae40ef619a50", 
    "enabled": true, 
    "route_id": "0f896042-b496-4cc9-b5a5-cc17f4cf9cb7", 
    "name": "request-transformer"
}

===========================================

Testing to check if header parameter and body parameter is valid
[root@contoso ~]# curl -i -X GET http://contoso.org:8000/v1/countries?page=5&p1=v1&p2=v1
[1] 69832
[2] 69833
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 108
Connection: keep-alive
Date: Thu, 24 May 2018 11:45:30 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.1.13
X-Powered-By: PHP/7.1.13
X-RateLimit-Limit-countries: countries=3
X-Kong-Upstream-Latency: 17
X-Kong-Proxy-Latency: 0
Via: kong/0.13.1

{"RequestHeader":{"h1":"v2","h2":"v1"},"p1":null,"p2":null,"p3":null,"ResponseHeader":{"h1":null,"h2":null}}  //Enter to continue
[1]-  Done                    curl -i -X GET http://contoso.org:8000/v1/countries?page=5
[2]+  Done                    p1=v1
 

Testing to check if header parameter and body parameter is valid
[root@contoso ~]# curl -i -X GET http://contoso.org:8000/v1/countries?page=5&p2=v1
[1] 72191
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 108
Connection: keep-alive
Date: Thu, 24 May 2018 11:54:17 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.1.13
X-Powered-By: PHP/7.1.13
X-RateLimit-Limit-countries: countries=3
X-Kong-Upstream-Latency: 18
X-Kong-Proxy-Latency: 0
Via: kong/0.13.1

{"RequestHeader":{"h1":"v2","h2":"v1"},"p1":null,"p2":null,"p3":null,"ResponseHeader":{"h1":null,"h2":null}}  //Enter to continue
[1]+  Done                    curl -i -X GET http://contoso.org:8000/v1/countries?page=5



Hello zigoodb,

First of all, please make sure it is not a problem of cache. You could try a different browser, clearing the cache, or a url with an extra random field, like this:

If you determine the cache is the issue, you might want to modify your bookstore service so that it adds a Cache-Control header, with either no-cache or with some other value.

If the cache is not the issue, it might be that there is some difference between the query sent by Firefox and the one sent by curl. Please try the following on Firefox:

  • Open developer tools (View / Developer / Developer Tools)
  • Open the Network tab
  • Visit http://contoso.org:8000/v1/countries?page=5&p1=v1&p2=v1 by pasting it on the address bar
  • The request should appear on the network tab. Click on it to see details. In particular, see which headers are sent, and try to see if there’s some header that should not be there.

it’s nothing to cache of browser, I’m sure


My Chinese Blog: https://blog.csdn.net/zhengzizhi/article/details/80409448

I might be mistaken, but perhaps this is caused by expecting the removal of the body but passing in a querystring value? In your examples, I don’t see body data being passed, but I do see p1 set as a querystring parameter.