add HTTP response headers

2013-05-12 Thread pille
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


Re: add HTTP response headers

2013-05-12 Thread Eric Wong
pille pille+unicorn+mailingl...@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


Re: add HTTP response headers

2013-05-12 Thread pille
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


Re: add HTTP response headers

2013-05-12 Thread Alejandro Riera
Wow! Awesome answer, you rock!

Enviado desde el movil

El 12/05/2013, a las 21:20, Eric Wong normalper...@yhbt.net escribió:

 pille pille+unicorn+mailingl...@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