Last active
December 18, 2015 21:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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