Class: EventMachine::Protocols::HttpClient2

### Home Classes Methods

### In Files

- lib/em/protocols/httpclient2.rb

### Parent

EventMachine::Connection

### Namespace

- CLASS EventMachine::Protocols::HttpClient2::Request

### Methods

- ::connect
- ::new
- #connection_completed
- #get
- #pop_request
- #post
- #post_init
- #receive_binary_data
- #receive_line
- #request
- #set_default_host_header
- #unbind

### Included Modules

- EventMachine::Protocols::LineText2

### Files

- ChangeLog
- DEFERRABLES
- EPOLL
- INSTALL
- KEYBOARD
- LEGAL
- LIGHTWEIGHT_CONCURRENCY
- PURE_RUBY
- RELEASE_NOTES
- SMTP
- SPAWNED_PROCESSES
- TODO

### Class/Module Index

Quicksearch

- EventMachine
- EventMachine
- EventMachine::Channel
- EventMachine::Completion
- EventMachine::Connection
- EventMachine::DNS
- EventMachine::DNS::Request
- EventMachine::DNS::RequestIdAlreadyUsed
- EventMachine::DNS::Resolver
- EventMachine::DNS::Socket
- EventMachine::DatagramObject
- EventMachine::DefaultDeferrable
- EventMachine::Deferrable
- EventMachine::DeferrableChildProcess
- EventMachine::Error
- EventMachine::EvmaKeyboard
- EventMachine::EvmaTCPClient
- EventMachine::EvmaTCPServer
- EventMachine::EvmaUDPSocket
- EventMachine::EvmaUNIXClient
- EventMachine::EvmaUNIXServer
- EventMachine::FileNotFoundException
- EventMachine::FileStreamer
- EventMachine::FileWatch
- EventMachine::Iterator
- EventMachine::LoopbreakReader
- EventMachine::PeriodicTimer
- EventMachine::Pool
- EventMachine::ProcessWatch
- EventMachine::Protocols
- EventMachine::Protocols
- EventMachine::Protocols::HeaderAndContentProtocol
- EventMachine::Protocols::HttpClient
- EventMachine::Protocols::HttpClient2
- EventMachine::Protocols::HttpClient2::Request
- EventMachine::Protocols::LineAndTextProtocol
- EventMachine::Protocols::LineProtocol
- EventMachine::Protocols::LineText2
- EventMachine::Protocols::Memcache
- EventMachine::Protocols::Memcache::ParserError
- EventMachine::Protocols::ObjectProtocol
- EventMachine::Protocols::Postgres3
- EventMachine::Protocols::SASLauth
- EventMachine::Protocols::SASLauthclient
- EventMachine::Protocols::SmtpClient
- EventMachine::Protocols::SmtpServer
- EventMachine::Protocols::Socks4
- EventMachine::Protocols::Stomp
- EventMachine::Protocols::Stomp::Message
- EventMachine::Protocols::TcpConnectTester
- EventMachine::Queue
- EventMachine::Reactor
- EventMachine::Selectable
- EventMachine::SpawnedProcess
- EventMachine::StreamObject
- EventMachine::SystemCmd
- EventMachine::ThreadedResource
- EventMachine::TickLoop
- EventMachine::Timer
- EventMachine::UuidGenerator
- EventMachine::YieldBlockFromSpawnedProcess
- Object
- Object::EM
- Object::P
- BufferedTokenizer
- IO
- StringIO
- TestConnection

No matching classes.

# EventMachine::Protocols::HttpClient2

Note: This class is deprecated and will be removed. Please use EM-HTTP-Request instead.

### Usage

    EM.run{
      conn = EM::Protocols::HttpClient2.connect 'google.com', 80

      req = conn.get('/')
      req.callback{ |response|
        p(response.status)
        p(response.headers)
        p(response.content)
      }
    }

### Public Class Methods

connect(*args) click to toggle source

Make a connection to a remote HTTP server. Can take either a pair of arguments (which will be interpreted as a hostname/ip-address and a port), or a hash. If the arguments are a hash, then supported values include:

    :host => a hostname or ip-address
    :port => a port number
    :ssl => true to enable ssl

    # File lib/em/protocols/httpclient2.rb, line 246
    def self.connect *args
      if args.length == 2
        args = {:host=>args[0], :port=>args[1]}
      else
        args = args.first
      end

      h,prt,ssl = args[:host], Integer(args[:port]), (args[:tls] || args[:ssl])
      conn = EM.connect( h, prt, self )
      conn.start_tls if ssl
      conn.set_default_host_header( h, prt, ssl )
      conn
    end

new() click to toggle source

    # File lib/em/protocols/httpclient2.rb, line 46
    def initialize
      warn "HttpClient2 is deprecated and will be removed. EM-Http-Request should be used instead."

      @authorization = nil
      @closed = nil
      @requests = nil
    end

### Public Instance Methods

connection_completed() click to toggle source

@private

    # File lib/em/protocols/httpclient2.rb, line 309
    def connection_completed
      super
      @connected.succeed
    end

get(args) click to toggle source

Get a url

    req = conn.get(:uri => '/')
    req.callback{|response| puts response.content }

    # File lib/em/protocols/httpclient2.rb, line 265
    def get args
      if args.is_a?(String)
        args = {:uri=>args}
      end
      args[:verb] = "GET"
      request args
    end

pop_request() click to toggle source

    # File lib/em/protocols/httpclient2.rb, line 366
    def pop_request
      @requests.pop
    end

post(args) click to toggle source

Post to a url

    req = conn.post('/data')
    req.callback{|response| puts response.content }

    # File lib/em/protocols/httpclient2.rb, line 279
    def post args
      if args.is_a?(String)
        args = {:uri=>args}
      end
      args[:verb] = "POST"
      request args
    end

post_init() click to toggle source

@private

    # File lib/em/protocols/httpclient2.rb, line 303
    def post_init
      super
      @connected = EM::DefaultDeferrable.new
    end

receive_binary_data(text) click to toggle source

@private

    # File lib/em/protocols/httpclient2.rb, line 358
    def receive_binary_data text
      @requests.last.receive_text text
    end

receive_line(ln) click to toggle source

@private

    # File lib/em/protocols/httpclient2.rb, line 348
    def receive_line ln
      if req = @requests.last
        req.receive_line ln
      else
        p "??????????"
        p ln
      end
    end

request(args) click to toggle source

@private

    # File lib/em/protocols/httpclient2.rb, line 334
    def request args
      args[:host_header] = @host_header unless args.has_key?(:host_header)
      args[:authorization] = @authorization unless args.has_key?(:authorization)
      r = Request.new self, args
      if @closed
        r.fail
      else
        (@requests ||= []).unshift r
        @connected.callback {r.send_request}
      end
      r
    end

set_default_host_header(host, port, ssl) click to toggle source

    # File lib/em/protocols/httpclient2.rb, line 293
    def set_default_host_header host, port, ssl
      if (ssl and port != 443) or (!ssl and port != 80)
        @host_header = "#{host}:#{port}"
      else
        @host_header = host
      end
    end

unbind() click to toggle source

    # File lib/em/protocols/httpclient2.rb, line 327
    def unbind
      super
      @closed = true
      (@requests || []).each {|r| r.fail}
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.