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

Added add_headers() method to request objects #543

Open
wants to merge 3 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
1 change: 1 addition & 0 deletions docs/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ Additionally the request object has the following methods:
* `url_for(route, params, ...)` -- get the URL for a named route, or object
* `build_url(path, params)` -- build a fully qualified URL from a path and parameters
* `html(fn)` -- generate a string using the HTML builder syntax
* `add_headers(headers)` -- Adds response headers

### @req

Expand Down
1 change: 0 additions & 1 deletion lapis/nginx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ build_response = function()
self.headers[k] = v
elseif "table" == _exp_0 then
old[#old + 1] = v
self.headers[k] = old
else
self.headers[k] = {
old,
Expand Down
1 change: 0 additions & 1 deletion lapis/nginx.moon
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ build_response = ->
@headers[k] = v
when "table"
old[#old + 1] = v
@headers[k] = old
else
@headers[k] = {old, v}

Expand Down
5 changes: 5 additions & 0 deletions lapis/request.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ do
self.buffer = { }
self.params = { }
self.options = { }
self.add_headers = function(self, headers)
for k, v in pairs(headers) do
self.res:add_header(k, v)
end
end
self.__class.support.load_cookies(self)
return self.__class.support.load_session(self)
end,
Expand Down
3 changes: 3 additions & 0 deletions lapis/request.moon
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ class Request
@buffer = {} -- output buffer
@params = {}
@options = {}
@add_headers = (headers) =>
for k,v in pairs headers
@res\add_header k,v

@@support.load_cookies @
@@support.load_session @
Expand Down