Kevin Clark | 74df0bf | 2008-06-18 01:00:33 +0000 | [diff] [blame] | 1 | require 'thrift/transport' |
| 2 | |
| 3 | require 'net/http' |
| 4 | require 'uri' |
| 5 | require 'stringio' |
| 6 | |
| 7 | ## Very simple HTTP client |
| 8 | module Thrift |
| 9 | class HTTPClient < Transport |
| 10 | def initialize(url) |
| 11 | @url = URI url |
| 12 | @outbuf = "" |
| 13 | end |
| 14 | |
| 15 | def open?; true end |
| 16 | def read(sz); @inbuf.read sz end |
| 17 | def write(buf); @outbuf << buf end |
| 18 | def flush |
| 19 | http = Net::HTTP.new @url.host, @url.port |
| 20 | resp, data = http.post(@url.path, @outbuf) |
| 21 | @inbuf = StringIO.new data |
| 22 | @outbuf = "" |
| 23 | end |
| 24 | end |
| 25 | deprecate_class! :THttpClient => HTTPClient |
| 26 | end |