Skip to content

Commit

Permalink
Merge branch 'hotfix/plugins-httplog' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Feb 1, 2016
2 parents ad22cd0 + 23fa8cd commit 4ad5ab2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion kong/plugins/http-log/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ local function log(premature, conf, message)
end
end

ok, err = sock:send(generate_post_payload(conf.method, parsed_url, message).."\r\n")
ok, err = sock:send(generate_post_payload(conf.method, parsed_url, message))
if not ok then
ngx.log(ngx.ERR, "[http-log] failed to send data to "..host..":"..tostring(port)..": ", err)
end
Expand Down
24 changes: 15 additions & 9 deletions spec/plugins/logging_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("Logging Plugins #ci", function()
{name = "tcp-log", config = {host = "127.0.0.1", port = TCP_PORT}, __api = 1},
{name = "tcp-log", config = {host = "127.0.0.1", port = TCP_PORT}, __api = 2},
{name = "udp-log", config = {host = "127.0.0.1", port = UDP_PORT}, __api = 3},
{name = "http-log", config = {http_endpoint = "http://localhost:"..HTTP_PORT.."/"}, __api = 4},
{name = "http-log", config = {http_endpoint = "http://mockbin.org/bin/"..mock_bin}, __api = 4},
{name = "http-log", config = {http_endpoint = "https://mockbin.org/bin/"..mock_bin}, __api = 5},
{name = "file-log", config = {path = FILE_LOG_PATH }, __api = 6}
}
Expand Down Expand Up @@ -109,20 +109,26 @@ describe("Logging Plugins #ci", function()
end)

it("should log to HTTP", function()
local thread = spec_helper.start_http_server(HTTP_PORT) -- Starting the mock TCP server

-- Making the request
local _, status = http_client.get(STUB_GET_URL, nil, { host = "http_logging.com" })
assert.equal(200, status)

-- Getting back the TCP server input
local ok, res = thread:join()
assert.truthy(ok)
assert.truthy(res)
local total_time = 0
local res, status, body
repeat
assert.truthy(total_time <= 10) -- Fail after 10 seconds
res, status = http_client.get("http://mockbin.org/bin/"..mock_bin.."/log", nil, { accept = "application/json" })
assert.equal(200, status)
body = cjson.decode(res)
local wait = 1
os.execute("sleep "..tostring(wait))
total_time = total_time + wait
until(#body.log.entries > 0)

assert.equal(1, #body.log.entries)
local log_message = cjson.decode(body.log.entries[1].request.postData.text)

-- Making sure it's alright
assert.same("POST / HTTP/1.1", res[1])
local log_message = cjson.decode(res[7])
assert.same("127.0.0.1", log_message.client_ip)
end)

Expand Down

0 comments on commit 4ad5ab2

Please sign in to comment.