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

Removing additional \r\n at the end of the HTTP body #926

Merged
merged 1 commit into from
Feb 1, 2016
Merged
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
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