Skip to content

Instantly share code, notes, and snippets.

@unixmonkey
Last active December 18, 2015 21:59
Show Gist options
  • Save unixmonkey/5850988 to your computer and use it in GitHub Desktop.
Save unixmonkey/5850988 to your computer and use it in GitHub Desktop.
Rack middleware to take all of the server output and condense it down to a single line of html source.
module Rack
class JoinHtmlOutput
def initialize(app)
@app = app
end
def call(env)
# get the original repsonse
status, headers, response = @app.call(env)
# response could be an empty array, like for a 304 not-modified or a chunked response
# Modify response chunks
response.each do |chunk|
chunk.gsub!(/[\r\n]+/, '').gsub!(/>\s+/, '>').gsub!(/\s+</, '<')
end
# return the modified server response
[status, headers, response]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment