Skip to content

Instantly share code, notes, and snippets.

@collin
Created July 16, 2009 10:35
Show Gist options
  • Select an option

  • Save collin/148344 to your computer and use it in GitHub Desktop.

Select an option

Save collin/148344 to your computer and use it in GitHub Desktop.
class Rack::Request
def forward_to target, &block
curl = Curl::Easy.new(target)
case
when get?
curl.http_get
when post?
curl.http_post body
when put?
curl.http_put body
when delete?
curl.http_delete
else
raise "Unimplemented HTTP methof for Rack::Request#forward"
end
headers = {}
curl.header_str.split("\r\n")[1..-1].each do |item|
k,v = item.split(": ")
headers[k] = v
headers
end
headers.delete "Vary"
headers.delete "Transfer-Encoding"
headers.delete "Date"
[curl.response_code, headers, yield(curl.body_str)]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment