Skip to content

Instantly share code, notes, and snippets.

@postmodern
Created March 22, 2010 03:04
Show Gist options
  • Save postmodern/339764 to your computer and use it in GitHub Desktop.
Save postmodern/339764 to your computer and use it in GitHub Desktop.
Please stop writing your own HTTP parsers, consider Rack next time.
#!/usr/bin/env ruby
require 'rack'
FILES = {
'/index.html' => 'index.html'
}
Rack::Handler.get('Thin').run proc { |env|
path = env['PATH_INFO']
if FILES[path]
[200, {'Content-Type' => 'octet/stream'}, File.new(FILES[path])]
else
[400, {'Content-Type' => 'text/html'}, ['Fail']]
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment