Skip to content

Instantly share code, notes, and snippets.

@stevenabrooks
Last active December 18, 2015 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenabrooks/5830914 to your computer and use it in GitHub Desktop.
Save stevenabrooks/5830914 to your computer and use it in GitHub Desktop.
class MyApp
def call(env)
puts "hello from MyApp"
[200, {}, ["Hello"]]
end
end
class ContentType
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
headers["Content-Type"] = "text/html"
[status, headers, body]
end
end
class FinishSentence
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
body << " world!"
[status, headers, [body]]
end
# Kirin used something like this:
# def call(env)
# status, headers, response = @app.call(env)
#
# response_body = ""
# response.each {|part| response_body += part}
# response_body += " World!"
#
# headers["Content-Length"] = response_body.length.to_s
#
# [status, headers, [response_body]]
# end
end
use ContentType
use FinishSentence
run MyApp.new
# new charatcer length update missing? #
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment