Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add cookie support to Transport::Http.

  • Loading branch information...
commit 7a08b405f880476fd12e48fa7811a550d947c519 1 parent 20b41fa
@jcoglan jcoglan authored
View
1  faye.gemspec
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
s.require_paths = %w[lib]
+ s.add_dependency "cookiejar", ">= 0.3.0"
s.add_dependency "eventmachine", "~> 0.12.0"
s.add_dependency "em-http-request", "~> 0.3"
s.add_dependency "em-hiredis", ">= 0.0.1"
View
1  lib/faye/protocol/client.rb
@@ -16,6 +16,7 @@ class Client
CONNECTION_TIMEOUT = 60.0
+ attr_accessor :cookies
attr_reader :endpoint, :client_id
def initialize(endpoint = nil, options = {})
View
13 lib/faye/transport/http.rb
@@ -1,3 +1,4 @@
+require 'cookiejar'
require 'em-http'
require 'em-http/version'
@@ -11,12 +12,16 @@ def self.usable?(endpoint, &callback)
def request(message, timeout)
retry_block = retry_block(message, timeout)
+ @client.cookies ||= CookieJar::Jar.new
+ cookies = @client.cookies.get_cookies(@endpoint)
+
content = JSON.unparse(message)
params = {
:head => {
+ 'Content-Length' => content.length,
'Content-Type' => 'application/json',
- 'host' => URI.parse(@endpoint).host,
- 'Content-Length' => content.length
+ 'Cookie' => cookies * '; ',
+ 'Host' => URI.parse(@endpoint).host
},
:body => content,
:timeout => -1 # for em-http-request < 1.0
@@ -31,6 +36,10 @@ def request(message, timeout)
end
request.callback do
begin
+ cookies = [request.response_header['SET_COOKIE']].flatten.compact
+ cookies.each do |cookie|
+ @client.cookies.set_cookie(@endpoint, cookie)
+ end
receive(JSON.parse(request.response))
rescue
retry_block.call
Please sign in to comment.
Something went wrong with that request. Please try again.