Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for excluding body in validation-POST #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ $ curl -X POST http://kong:8001/apis/{api}/plugins \
<td></td>
<td>Keepalive time (miliseconds) for the request to the URL specified above. Default value is 60000.</td>
</tr>
<tr>
<td><code>config.include_body</code></td>
<td></td>
<td>Include body in request. Default value is true.</td>
</tr>
</tbody></table>

Middleman will execute a JSON <code>POST</code> request to the specified <code>url</code> with the following body:
Expand All @@ -91,7 +96,7 @@ Middleman will execute a JSON <code>POST</code> request to the specified <code>u
<th>Description</th>
</tr>
<tr>
<td><code>body_data</code></td>
<td><code>body_data (optional)</code></td>
<td><small>The body of the original request</small></td>
</tr>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions middleman-0.1.1-1.rockspec → middleman-0.2.1-1.rockspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package = "middleman"

version = "0.1.1-1"
version = "0.2.1-1"

-- The version '0.1.1' is the source code version, the trailing '1' is the version of this rockspec.
-- The version '0.2.1' is the source code version, the trailing '1' is the version of this rockspec.
-- whenever the source version changes, the rockspec should be reset to 1. The rockspec version is only
-- updated (incremented) when this file changes, but the source remains the same.

Expand Down
13 changes: 10 additions & 3 deletions src/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function _M.execute(conf)
local parsed_url = parse_url(conf.url)
local host = parsed_url.host
local port = tonumber(parsed_url.port)
local payload = _M.compose_payload(parsed_url)
local payload = _M.compose_payload(parsed_url, conf)

local sock = ngx.socket.tcp()
sock:settimeout(conf.timeout)
Expand Down Expand Up @@ -120,7 +120,7 @@ function _M.execute(conf)

end

function _M.compose_payload(parsed_url)
function _M.compose_payload(parsed_url, conf)
local headers = get_headers()
local uri_args = get_uri_args()
local next = next
Expand Down Expand Up @@ -150,7 +150,14 @@ function _M.compose_payload(parsed_url)
raw_json_uri_args = "{}"
end

local payload_body = [[{"headers":]] .. raw_json_headers .. [[,"uri_args":]] .. raw_json_uri_args.. [[,"body_data":]] .. raw_json_body_data .. [[}]]
local payload_body = [[{"headers":]] .. raw_json_headers .. [[,"uri_args":]] .. raw_json_uri_args

-- add the payload
if conf.include_body then
payload_body = payload_body .. [[,"body_data":]] .. raw_json_body_data
end

payload_body = payload_body .. [[}]]

local payload_headers = string_format(
"POST %s HTTP/1.1\r\nHost: %s\r\nConnection: Keep-Alive\r\nContent-Type: application/json\r\nContent-Length: %s\r\n",
Expand Down
5 changes: 3 additions & 2 deletions src/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ return {
url = {required = true, type = "string"},
response = { required = true, default = "table", type = "string", enum = {"table", "string"}},
timeout = { default = 10000, type = "number" },
keepalive = { default = 60000, type = "number" }
keepalive = { default = 60000, type = "number" },
include_body = { default = true, type = "boolean" }
}
}
}