-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pdk) implement kong.response.get_path_with_query()
When the path + querystring is needed, this prevents having to manually check wether the querystring is present and concatenating the path + "?" + the query string every time. From #3842 Signed-off-by: Thibault Charbonnier <[email protected]>
- Loading branch information
1 parent
5f6a1d3
commit 68af538
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use strict; | ||
use warnings FATAL => 'all'; | ||
use Test::Nginx::Socket::Lua; | ||
use t::Util; | ||
|
||
plan tests => repeat_each() * (blocks() * 3); | ||
|
||
run_tests(); | ||
|
||
__DATA__ | ||
=== TEST 1: request.get_path_with_query() returns the path if no querystring | ||
--- http_config eval: $t::Util::HttpConfig | ||
--- config | ||
location = /t { | ||
access_by_lua_block { | ||
local PDK = require "kong.pdk" | ||
local pdk = PDK.new() | ||
local path_and_querystring = pdk.request.get_path_with_query() | ||
ngx.say("path_and_querystring=", path_and_querystring) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
path_and_querystring=/t | ||
--- no_error_log | ||
[error] | ||
=== TEST 2: request.get_path_with_query() returns path + ? + querystring | ||
--- http_config eval: $t::Util::HttpConfig | ||
--- config | ||
location = /t { | ||
access_by_lua_block { | ||
local PDK = require "kong.pdk" | ||
local pdk = PDK.new() | ||
local path_and_querystring = pdk.request.get_path_with_query() | ||
ngx.say("path_and_querystring=", path_and_querystring) | ||
} | ||
} | ||
--- request | ||
GET /t?foo=1&bar=2 | ||
--- response_body | ||
path_and_querystring=/t?foo=1&bar=2 | ||
--- no_error_log | ||
[error] |