Created
February 6, 2013 14:49
-
-
Save track8/4723000 to your computer and use it in GitHub Desktop.
>> rackup
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
# config.ru | |
require 'rack' | |
require 'gdk_pixbuf2' | |
class AvatarClone | |
def call(env) | |
request = Rack::Request.new(env) | |
case request.request_method | |
when 'GET' | |
begin | |
filename = "./avatar/#{request.path.split('/')[1]}.jpg" | |
return [200, | |
{'Content-type' => 'image/jpeg'}, | |
[Gdk::Pixbuf.new(filename).scale(80, 80).save_to_buffer("jpeg")]] | |
rescue | |
Rack::Response.new("Not Found", 404) | |
end | |
else | |
Rack::Response.new("Bad Request", 400) | |
end | |
end | |
end | |
run AvatarClone.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment