Skip to content

verify faye url #211

wants to merge 0 commits into from

2 participants

mvj3 commented Mar 29, 2013

if endpoint is a URI instance, it'll raise nil error.

jcoglan commented May 8, 2013

I'm always a little suspicious of this sort of defensive programming. What problem did you run into that required this fix?

mvj3 commented Jun 19, 2013

@jcoglan Sorry for late reply, here's the code and error log :)

LOCAL_IP = Socket.ip_address_list.detect{|intf| intf.ipv4_private?}.ip_address
LOCAL_FAYE_URI = URI.parse("http://#{LOCAL_IP}:#{ENV['FAYE_PORT'] || 9292}/faye")
client =
client.handshake { sleep 1 }
NoMethodError: undefined method `gsub' for #<URI::HTTP:0x000001011f6ce0 URL:>
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/faye-0.8.9/lib/faye/transport/web_socket.rb:52:in `connect'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/faye-0.8.9/lib/faye/transport/web_socket.rb:26:in `usable?'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/faye-0.8.9/lib/faye/transport/web_socket.rb:11:in `usable?'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/faye-0.8.9/lib/faye/transport/transport.rb:86:in `block in get'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/faye-0.8.9/lib/faye.rb:103:in `call'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/faye-0.8.9/lib/faye.rb:103:in `block in async_each'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/faye-0.8.9/lib/faye.rb:110:in `call'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/faye-0.8.9/lib/faye.rb:110:in `block in async_each'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/faye-0.8.9/lib/faye.rb:117:in `call'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/faye-0.8.9/lib/faye.rb:117:in `block in async_each'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/faye-0.8.9/lib/faye.rb:119:in `call'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/faye-0.8.9/lib/faye.rb:119:in `async_each'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/faye-0.8.9/lib/faye/transport/transport.rb:101:in `get'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/faye-0.8.9/lib/faye/protocol/client.rb:309:in `select_transport'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/faye-0.8.9/lib/faye/protocol/client.rb:91:in `handshake'
jcoglan commented Jun 19, 2013

Seems to me that if you give the client a structured representation of the URI rather than a string, it should use that rather than throwing information away by blindly calling to_s on whatever is passed it. It will have to re-parse this string when it connects to the server anyway.

mvj3 commented Jun 19, 2013

I see,


@socket =^http(s?):/, 'ws\1:')) 

failed, it'll raise undefined method `gsub' error, or raise nil error in the other part of connecting session.

I think using URI instance as params should be another valid option, so maybe the above code could add to_s, e.g.

@socket =^http(s?):/, 'ws\1:'))
jcoglan commented Jun 19, 2013

It would be safer to do this, but the idea's the same:

u = uri.dup
u.scheme = (u.scheme == 'https') ? 'wss' : 'ws'
mvj3 commented Jun 20, 2013

Yep, so maybe we could convert a URI instance to String instance when we initialize a Faye::Client instance, and convert it to URI instance when manipulate a URI structure?

mvj3 commented Jun 26, 2013

I canceled the commit.

@mvj3 mvj3 closed this Jun 26, 2013
jcoglan commented Jul 10, 2013

I've just pushed a change to master to allow Faye::Client to be instantiated with a URI.

mvj3 commented Jul 11, 2013


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.