Skip to content

Commit

Permalink
hotfix(log-serializer) avoid redundant request.request_* properties
Browse files Browse the repository at this point in the history
Reflecting back on #2445, the chosen names feel very redundant when
accessed from a queryable interface. The same way, `upstream_uri` seems
to have been wrongly added under the `request` scope, where it doesn't
belong.

This solution has the benefit of being less breaking as well. (Only one
field gets renamed).

From #3098
  • Loading branch information
thibaultcha authored Dec 15, 2017
1 parent ceab1d9 commit 94940ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions kong/plugins/log-serializers/basic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ function _M.serialize(ngx)

return {
request = {
request_uri = ngx.var.request_uri,
upstream_uri = ngx.var.upstream_uri,
request_url = ngx.var.scheme .. "://" .. ngx.var.host .. ":" .. ngx.var.server_port .. ngx.var.request_uri,
uri = ngx.var.request_uri,
url = ngx.var.scheme .. "://" .. ngx.var.host .. ":" .. ngx.var.server_port .. ngx.var.request_uri,
querystring = ngx.req.get_uri_args(), -- parameters, as a table
method = ngx.req.get_method(), -- http method
headers = ngx.req.get_headers(),
size = ngx.var.request_length
},
upstream_uri = ngx.var.upstream_uri,
response = {
status = ngx.status,
headers = ngx.resp.get_headers(),
Expand All @@ -45,4 +45,4 @@ function _M.serialize(ngx)
}
end

return _M
return _M
8 changes: 4 additions & 4 deletions spec/01-unit/012-log_serializer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ describe("Log Serializer", function()
assert.same({"header1", "header2"}, res.request.headers)
assert.equal("POST", res.request.method)
assert.same({"arg1", "arg2"}, res.request.querystring)
assert.equal("http://test.com:80/request_uri", res.request.request_url)
assert.equal("/upstream_uri", res.request.upstream_uri)
assert.equal("http://test.com:80/request_uri", res.request.url)
assert.equal("/upstream_uri", res.upstream_uri)
assert.equal(200, res.request.size)
assert.equal("/request_uri", res.request.request_uri)
assert.equal("/request_uri", res.request.uri)

-- Response
assert.is_table(res.response)
Expand Down Expand Up @@ -147,4 +147,4 @@ describe("Log Serializer", function()
assert.is_nil(res.tries)
end)
end)
end)
end)

0 comments on commit 94940ab

Please sign in to comment.