From ada85dbaa98efc7d238f90d53f1d4978be8800ee Mon Sep 17 00:00:00 2001 From: Ingvi Rafn Date: Mon, 13 Apr 2020 15:23:24 +0000 Subject: [PATCH 1/4] body can now be excluded from request --- ...n-0.1.1-1.rockspec => middleman-0.2.1-1.rockspec | 4 ++-- src/access.lua | 13 ++++++++++--- src/schema.lua | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) rename middleman-0.1.1-1.rockspec => middleman-0.2.1-1.rockspec (90%) diff --git a/middleman-0.1.1-1.rockspec b/middleman-0.2.1-1.rockspec similarity index 90% rename from middleman-0.1.1-1.rockspec rename to middleman-0.2.1-1.rockspec index a3bdc6f..a070448 100644 --- a/middleman-0.1.1-1.rockspec +++ b/middleman-0.2.1-1.rockspec @@ -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. diff --git a/src/access.lua b/src/access.lua index f55f6a7..f16e235 100644 --- a/src/access.lua +++ b/src/access.lua @@ -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) @@ -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 @@ -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", diff --git a/src/schema.lua b/src/schema.lua index 946a51a..e771979 100644 --- a/src/schema.lua +++ b/src/schema.lua @@ -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 = "bool" } } } \ No newline at end of file From 505aeece86256f115afeb9264336e80f993fd639 Mon Sep 17 00:00:00 2001 From: Ingvi Rafn Date: Mon, 13 Apr 2020 15:25:00 +0000 Subject: [PATCH 2/4] update readme with include_body --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b94ac43..9e9a12e 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,11 @@ $ curl -X POST http://kong:8001/apis/{api}/plugins \ Keepalive time (miliseconds) for the request to the URL specified above. Default value is 60000. + +config.include_body + +Include body in request. + Middleman will execute a JSON POST request to the specified url with the following body: @@ -91,7 +96,7 @@ Middleman will execute a JSON POST request to the specified u Description - body_data + body_data (optional) The body of the original request From f87250188b313b73e39f9cff988161731e48d3ba Mon Sep 17 00:00:00 2001 From: Ingvi Rafn Date: Mon, 13 Apr 2020 15:26:54 +0000 Subject: [PATCH 3/4] update readme with include_body - default value --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e9a12e..d2216e1 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ $ curl -X POST http://kong:8001/apis/{api}/plugins \ config.include_body -Include body in request. +Include body in request. Default value is true. From 263c131e445eb840d4bf9bd7429baec942ac4058 Mon Sep 17 00:00:00 2001 From: Ingvi Rafn Date: Wed, 15 Apr 2020 11:47:18 +0000 Subject: [PATCH 4/4] bool => boolean --- src/schema.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/schema.lua b/src/schema.lua index e771979..69e50ae 100644 --- a/src/schema.lua +++ b/src/schema.lua @@ -5,6 +5,6 @@ return { response = { required = true, default = "table", type = "string", enum = {"table", "string"}}, timeout = { default = 10000, type = "number" }, keepalive = { default = 60000, type = "number" }, - include_body = { default = true, type = "bool" } + include_body = { default = true, type = "boolean" } } -} \ No newline at end of file +}