* add HTTP response headers
@ 2013-05-12 18:12 pille
2013-05-12 19:20 ` Eric Wong
0 siblings, 1 reply; 4+ messages in thread
From: pille @ 2013-05-12 18:12 UTC (permalink / raw)
To: mongrel-unicorn
hi,
is it possible to add static and dynamic HTTP response headers in
unicorn.conf.rb?
i'd like to add the hostname of the worker for debugging and a
timestamp, when the request was worked on.
currently this is done in nginx, which should be stripped from the stack.
i'd like to keep it out of the webapp itself, because it's infrastructure.
cheers
pille
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: add HTTP response headers
2013-05-12 18:12 add HTTP response headers pille
@ 2013-05-12 19:20 ` Eric Wong
2013-05-12 20:25 ` pille
2013-05-12 21:37 ` Alejandro Riera
0 siblings, 2 replies; 4+ messages in thread
From: Eric Wong @ 2013-05-12 19:20 UTC (permalink / raw)
To: unicorn list; +Cc: pille
pille <pille+unicorn+mailinglist@struction.de> wrote:
> hi,
>
> is it possible to add static and dynamic HTTP response headers in
> unicorn.conf.rb?
No, but it is easily possible with a Rack config.ru
> i'd like to add the hostname of the worker for debugging and a
> timestamp, when the request was worked on.
>
> currently this is done in nginx, which should be stripped from the stack.
> i'd like to keep it out of the webapp itself, because it's infrastructure.
Can you consider config.ru infrastructure? unicorn tries to do as
much generically via Rack as possible.
The following (totally untested) middleware should work:
------------------------8<------------------------
require 'time'
require 'socket'
require 'rack/utils'
# Usage (in config.ru)
# require 'name/of/this/file'
# use ExtraHeaders
# # other middlewares ...
# run YourApp.new
class ExtraHeaders
def initialize(app)
@app = app
end
def call(env)
start = Time.now.httpdate
status, headers, body = @app.call(env)
headers = Rack::Utils::HeaderHash.new(headers)
headers["X-Hostname"] = Socket.gethostname
headers["X-Start"] = start
[ status, headers, body ]
end
end
------------------------8<------------------------
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: add HTTP response headers
2013-05-12 19:20 ` Eric Wong
@ 2013-05-12 20:25 ` pille
2013-05-12 21:37 ` Alejandro Riera
1 sibling, 0 replies; 4+ messages in thread
From: pille @ 2013-05-12 20:25 UTC (permalink / raw)
To: unicorn list
eric, thanks for your comprehensive help!
pille
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: add HTTP response headers
2013-05-12 19:20 ` Eric Wong
2013-05-12 20:25 ` pille
@ 2013-05-12 21:37 ` Alejandro Riera
1 sibling, 0 replies; 4+ messages in thread
From: Alejandro Riera @ 2013-05-12 21:37 UTC (permalink / raw)
To: unicorn list; +Cc: unicorn list, pille
Wow! Awesome answer, you rock!
Enviado desde el movil
El 12/05/2013, a las 21:20, Eric Wong <normalperson@yhbt.net> escribió:
> pille <pille+unicorn+mailinglist@struction.de> wrote:
>> hi,
>>
>> is it possible to add static and dynamic HTTP response headers in
>> unicorn.conf.rb?
>
> No, but it is easily possible with a Rack config.ru
>
>> i'd like to add the hostname of the worker for debugging and a
>> timestamp, when the request was worked on.
>>
>> currently this is done in nginx, which should be stripped from the stack.
>> i'd like to keep it out of the webapp itself, because it's infrastructure.
>
> Can you consider config.ru infrastructure? unicorn tries to do as
> much generically via Rack as possible.
>
> The following (totally untested) middleware should work:
> ------------------------8<------------------------
> require 'time'
> require 'socket'
> require 'rack/utils'
>
> # Usage (in config.ru)
> # require 'name/of/this/file'
> # use ExtraHeaders
> # # other middlewares ...
> # run YourApp.new
> class ExtraHeaders
> def initialize(app)
> @app = app
> end
>
> def call(env)
> start = Time.now.httpdate
> status, headers, body = @app.call(env)
> headers = Rack::Utils::HeaderHash.new(headers)
> headers["X-Hostname"] = Socket.gethostname
> headers["X-Start"] = start
> [ status, headers, body ]
> end
> end
> ------------------------8<------------------------
> _______________________________________________
> Unicorn mailing list - mongrel-unicorn@rubyforge.org
> http://rubyforge.org/mailman/listinfo/mongrel-unicorn
> Do not quote signatures (like this one) or top post when replying
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-05-12 22:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-12 18:12 add HTTP response headers pille
2013-05-12 19:20 ` Eric Wong
2013-05-12 20:25 ` pille
2013-05-12 21:37 ` Alejandro Riera
Code repositories for project(s) associated with this public inbox
https://yhbt.net/unicorn.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).