Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion compress files?

View parsed - Show only message text

Received: by 10.141.34.12 with SMTP id m12mr194380rvj.0.1213214238809;
        Wed, 11 Jun 2008 12:57:18 -0700 (PDT)
Return-Path: <a...@heroku.com>
Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.154])
        by mx.google.com with ESMTP id 39si377578yxd.0.2008.06.11.12.57.18;
        Wed, 11 Jun 2008 12:57:18 -0700 (PDT)
Received-SPF: neutral (google.com: 72.14.220.154 is neither permitted nor denied by best guess record for domain of a...@heroku.com) client-ip=72.14.220.154;
Authentication-Results: mx.google.com; spf=neutral (google.com: 72.14.220.154 is neither permitted nor denied by best guess record for domain of a...@heroku.com) smtp.mail=a...@heroku.com
Received: by fg-out-1718.google.com with SMTP id l27so3709052fgb.43
        for <rack-devel@googlegroups.com>; Wed, 11 Jun 2008 12:57:18 -0700 (PDT)
Received: by 10.82.181.8 with SMTP id d8mr16519buf.54.1213214237788;
        Wed, 11 Jun 2008 12:57:17 -0700 (PDT)
Received: by 10.82.160.13 with HTTP; Wed, 11 Jun 2008 12:57:17 -0700 (PDT)
Message-ID: <d248b4c80806111257o4f403d75m40ebc5e637de116e@mail.gmail.com>
Date: Wed, 11 Jun 2008 12:57:17 -0700
From: "Adam Wiggins" <a...@heroku.com>
To: rack-devel@googlegroups.com
Subject: Re: compress files?
In-Reply-To: <2be104a5-4449-4ae0-90b1-a97393ca3b0e@e53g2000hsa.googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
References: <2be104a5-4449-4ae0-90b1-a97393ca3b0e@e53g2000hsa.googlegroups.com>

On Wed, Jun 11, 2008 at 8:30 AM, spicyj <spicyjalap...@gmail.com> wrote:
> Anyone know how to write a Rack middleware to serve static files as
> gzipped?

How about:

class GzipOutputFilter
	def initialize(app)
		@app = app
	end

	def call(env)
		out = @app.call(env)

		gzip = IO.popen('gzip', 'r+')
		gzip.write out[2]    # handles String only, would be nice to check
for IO object too
		gzip.close_write

		out[1]['Content-encoding'] = 'gzip'
		out[2] = gzip

		out
	end
end

class HelloHandler
	def call(env)
		[ 200, { 'Content-type' => 'text/plain' }, 'hello, world' ]
	end
end

use Rack::Lint
use GzipOutputFilter
run HelloHandler.new


Adam

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google