Skip to content

Instantly share code, notes, and snippets.

@youpy
Created April 26, 2010 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save youpy/378892 to your computer and use it in GitHub Desktop.
Save youpy/378892 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'ubygems'
require 'webrick'
require 'webrick/httpproxy'
require 'RMagick'
q = {}
handler = Proc.new() do |req,res|
if res.content_type =~ /jpeg/
q[req.request_uri] ||= 100
image = Magick::Image.from_blob(res.body)[0]
res.body = image.to_blob do
self.quality = q[req.request_uri] -= (q[req.request_uri] > 20 ? 10 : 0)
end
res['cache-control'] = 'no-cache'
end
end
s = WEBrick::HTTPProxyServer.new(
:BindAddress => '0.0.0.0',
:Port => 8080,
:ProxyContentHandler => handler
)
Signal.trap('INT') do
s.shutdown
end
s.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment