You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.6 KiB

#!/usr/bin/env ruby
require "webrick"
require "net/http"
require "uri"
$replacements = {
"e621.net" => "e621.fuwwy.ch", # Replace this with your domain/subdomain obviously
">e621<" => ">e621.fuwwy.ch<", # This basically just changes the title shown on the main page
"https:" => "http:" # only needed if your nginx backend doesn't have SSL yet
}
class MyProxy < WEBrick::HTTPServlet::AbstractServlet
HOST = "e621.net" # set host to proxy duh
def do_GET(request, response)
uri = request.unparsed_uri
proxy_request(request, response, Net::HTTP::Get.new(uri, {"User-Agent" => "amongus happy meal guys this is crazy i ordered an amogus happy meal at 3am hugy wugy came and sucked my dick this is so scary"}))
end
def do_POST(request, response)
uri = request.unparsed_uri
proxy_request(request, response, Net::HTTP::Post.new(uri, {"User-Agent" => "amongus happy meal guys this is crazy i ordered an amogus happy meal at 3am hugy wugy came and sucked my dick this is so scary"}), request.body)
end
def proxy_request(request, response, http_request, body = nil)
http = Net::HTTP.new(HOST, 443)
http.use_ssl = true
http_request.body = body if body
resp = http.request(http_request)
body = resp.body
response.content_type = resp["content-type"]
$replacements.each { |k,v|
body = body.gsub(k,v)
}
response.body = body
end
end
server = WEBrick::HTTPServer.new(:Port => ENV["PORT"] || 8000) # define port on which the proxy runs ... so this would be localhost:8000
server.mount "/", MyProxy
trap("INT"){ server.shutdown }
server.start