Skip to content

Instantly share code, notes, and snippets.

@apostergiou
Created February 2, 2018 00:12
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 apostergiou/a540207fb2cb9d861144630d01bc9de2 to your computer and use it in GitHub Desktop.
Save apostergiou/a540207fb2cb9d861144630d01bc9de2 to your computer and use it in GitHub Desktop.
require 'rack'
class HelloWorldApp
def self.call(env)
# 200 is the HTTP status code
# the second element is the response HTTP header hash
# finally the last element is the response body
['200', {'Content-Type' => 'text/html'}, ['A hello world rack app.']]
end
end
class AddSomeHeaders
def initialize(app)
@app = app
end
def call(env)
@app.call(env).tap { |status, headers, body| headers['X-awesome'] = true }
end
end
class EditSomeHeaders
def initialize(app)
@app = app
end
def call(env)
@app.call(env).tap do |status, headers, body|
headers.delete('X-awesome')
headers['X-double-awesome'] = 'true'
end
end
end
app = Rack::Builder.new do
use EditSomeHeaders
use AddSomeHeaders
run HelloWorldApp
end
Rack::Handler::WEBrick.run app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment