Class: Faye::HttpTransport

Inherits:
Transport show all
Defined in:
lib/faye/network/transport.rb

Constant Summary

Constants included from Logging

Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS

Instance Attribute Summary

Attributes included from Logging

#log_level

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Transport

#connection_type, get, #initialize, #receive, register, #retry_block, #send, supported_connection_types

Methods included from Logging

#log

Constructor Details

This class inherits a constructor from Faye::Transport

Class Method Details

.usable?(endpoint) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/faye/network/transport.rb', line 70

def self.usable?(endpoint)
  endpoint.is_a?(String)
end

Instance Method Details

#request(message, timeout) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/faye/network/transport.rb', line 74

def request(message, timeout)
  retry_block = retry_block(message, timeout)
  
  content = JSON.unparse(message)
  params = {
    :head => {
      'Content-Type'    => 'application/json',
      'host'            => URI.parse(@endpoint).host,
      'Content-Length'  => content.length
    },
    :body    => content,
    :timeout => -1
  }
  request = EventMachine::HttpRequest.new(@endpoint).post(params)
  request.callback do
    begin
      receive(JSON.parse(request.response))
    rescue
      retry_block.call
    end
  end
  request.errback { retry_block.call }
end