Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Include the Accept header with value text/event-stream by default.

This a requirement for some EventSource API. It should not break existing ones.

Signed-off-by: François de Metz <francois@stormz.me>
  • Loading branch information...
commit b5ad982b2ba63b38ea04e7afbe355588226b153a 1 parent 38d4329
@francois2metz francois2metz authored
Showing with 8 additions and 3 deletions.
  1. +1 −1  lib/em-eventsource.rb
  2. +7 −2 spec/em-eventsource_spec.rb
View
2  lib/em-eventsource.rb
@@ -184,7 +184,7 @@ def prepare_request
block = middleware.pop
conn.use *middleware, &block
}
- headers = @headers.merge({'Cache-Control' => 'no-cache'})
+ headers = @headers.merge({'Cache-Control' => 'no-cache', 'Accept' => 'text/event-stream'})
headers.merge!({'Last-Event-Id' => @last_event_id }) if not @last_event_id.nil?
[conn, conn.get({ :query => @query,
:head => headers})]
View
9 spec/em-eventsource_spec.rb
@@ -29,7 +29,8 @@ def create_response_headers(status, content_type="", other={})
req.url.must_equal "http://example.com/streaming"
req.opts[:inactivity_timeout].must_equal 60
req.get_args[0].must_equal({ :query => {},
- :head => {"Cache-Control" => "no-cache"} })
+ :head => {"Cache-Control" => "no-cache",
+ "Accept" => "text/event-stream"} })
EM.stop
end
end
@@ -38,7 +39,9 @@ def create_response_headers(status, content_type="", other={})
start_source "http://example.net/streaming", {:chuck => "norris"}, {"DNT" => 1} do |source, req|
req.url.must_equal "http://example.net/streaming"
req.get_args[0].must_equal({ :query => {:chuck => "norris"},
- :head => {"DNT" => 1, "Cache-Control" => "no-cache"} })
+ :head => {"DNT" => 1,
+ "Cache-Control" => "no-cache",
+ "Accept" => "text/event-stream"} })
EM.stop
end
end
@@ -145,6 +148,7 @@ def create_response_headers(status, content_type="", other={})
refute_same(req2, req)
source.last_event_id.must_equal "roger"
req2.get_args[0].must_equal({ :head => { "Last-Event-Id" => "roger",
+ "Accept" => "text/event-stream",
"Cache-Control" => "no-cache" },
:query => {} })
EM.stop
@@ -165,6 +169,7 @@ def create_response_headers(status, content_type="", other={})
refute_same(req2, req)
source.last_event_id.must_equal "roger"
req2.get_args[0].must_equal({ :head => { "Last-Event-Id" => "roger",
+ "Accept" => "text/event-stream",
"Cache-Control" => "no-cache" },
:query => {} })
EM.stop
Please sign in to comment.
Something went wrong with that request. Please try again.