Skip to content

Instantly share code, notes, and snippets.

@tobynet
Forked from hitode909/negaproxy.rb
Created June 12, 2011 15:34
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 tobynet/1021674 to your computer and use it in GitHub Desktop.
Save tobynet/1021674 to your computer and use it in GitHub Desktop.
oquno化プロキシ
#!/usr/bin/env ruby
require 'webrick'
require 'webrick/httpproxy'
require 'RMagick'
# curl -o files/oquno-c.png http://si1.twimg.com/profile_images/96741059/oquno-c.png
handler = Proc.new() { |req,res|
if res['content-type'] =~ /png/
begin
img = Magick::Image.from_blob(res.body).first
res.body = Magick::Image.read("files/oquno-c.png").first.resize(img.columns, img.rows).to_blob
res.content_length = res.body.size
res['cache-control'] = 'no-cache'
rescue
end
end
}
s = WEBrick::HTTPProxyServer.new(
:BindAddress => '127.0.0.1',
:Port => 5462,
: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