Sha256: d3331cbb6206750d6c848ba43b2b73be5998386d5f644da27dbf0a6915bcb52f

Contents?: true

Size: 739 Bytes

Versions: 5

Compression:

Stored size: 739 Bytes

Contents

require File.dirname(__FILE__) + '/../lib/rev'

class MyHttpClient < Rev::HttpClient
  def on_connect
    super
    STDERR.puts "Connected to #{remote_host}:#{remote_port}"
  end

  def on_connect_failed
    super
    STDERR.puts "Connection failed"
  end

  def on_response_header(header)
    STDERR.puts "Response: #{header.http_version} #{header.status} #{header.http_reason}"
  end

  def on_body_data(data)
    STDOUT.write data
    STDOUT.flush
  end

  def on_request_complete
    STDERR.puts "Request complete!"
  end

  def on_error(reason)
    STDERR.puts "Error: #{reason}"
  end
end

l = Rev::Loop.default
c = MyHttpClient.connect("www.google.com", 80).attach(l)
c.request('GET', '/search', :query => { :q => 'foobar' })
l.run

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rev-0.3.2 examples/httpclient.rb
rev-0.3.1 examples/httpclient.rb
rev-0.3.0 examples/httpclient.rb
rev-0.2.3 examples/httpclient.rb
rev-0.2.4 examples/httpclient.rb