From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS33070 50.56.128.0/17 X-Spam-Status: No, score=0.5 required=5.0 tests=AWL,RDNS_NONE shortcircuit=no autolearn=no version=3.3.2 X-Original-To: archivist@yhbt.net Delivered-To: archivist@dcvr.yhbt.net Received: from rubyforge.org (unknown [50.56.192.79]) by dcvr.yhbt.net (Postfix) with ESMTP id B5C6E1F487 for ; Sun, 12 May 2013 19:21:01 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id 2FA782E0F3; Sun, 12 May 2013 19:21:02 +0000 (UTC) X-Original-To: mongrel-unicorn@rubyforge.org Delivered-To: mongrel-unicorn@rubyforge.org Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by rubyforge.org (Postfix) with ESMTP id 3349E2E0F2 for ; Sun, 12 May 2013 19:20:57 +0000 (UTC) Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 190E01F42E; Sun, 12 May 2013 19:20:55 +0000 (UTC) Date: Sun, 12 May 2013 19:20:54 +0000 From: Eric Wong To: unicorn list Subject: Re: add HTTP response headers Message-ID: <20130512192054.GA18231@dcvr.yhbt.net> References: <518FDB98.8080402@struction.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <518FDB98.8080402@struction.de> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: pille X-BeenThere: mongrel-unicorn@rubyforge.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: mongrel-unicorn-bounces@rubyforge.org Errors-To: mongrel-unicorn-bounces@rubyforge.org pille 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