Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Send no-cache, no-store cache-control headers on JSON-P responses, an…

…d remove the nocache param on JSON-P requests.
  • Loading branch information...
commit d6a292be9704ec0df2096d6203c34897b3658fe7 1 parent 92fc39d
@jcoglan jcoglan authored
View
5 javascript/adapters/node_adapter.js
@@ -183,7 +183,10 @@ Faye.NodeAdapter = Faye.Class({
head = Faye.extend({}, type),
origin = request.headers.origin;
- if (isGet) body = jsonp + '(' + body + ');';
+ if (isGet) {
+ body = jsonp + '(' + body + ');';
+ head['Cache-Control'] = 'no-cache, no-store';
+ }
if (origin) head['Access-Control-Allow-Origin'] = origin;
this.debug('Returning ?', body);
View
1  javascript/transport/jsonp.js
@@ -26,7 +26,6 @@ Faye.Transport.JSONP = Faye.extend(Faye.Class(Faye.Transport, {
self.request(message, 2 * timeout);
}, 1000 * timeout);
- location.params.nocache = new Date().getTime() + Math.round(Math.random() * 1000);
location.params.jsonp = callbackName;
script.type = 'text/javascript';
script.src = location.toURL();
View
1  lib/faye/adapters/rack_adapter.rb
@@ -94,6 +94,7 @@ def handle_request(request)
@server.flush_connection(message) if request.get?
head['Access-Control-Allow-Origin'] = origin if origin
+ head['Cache-Control'] = 'no-cache, no-store' if request.get?
callback.call [200, head, body]
@server.process(message, false) do |replies|
View
11 spec/javascript/node_adapter_spec.js
@@ -76,6 +76,11 @@ JS.ENV.NodeAdapterSteps = JS.Test.asyncSteps({
resume()
},
+ check_cache_control: function(value, resume) {
+ this.assertEqual(value, this._response.headers["cache-control"])
+ resume()
+ },
+
check_content_type: function(type, resume) {
this.assertEqual(type, this._response.headers["content-type"])
resume()
@@ -232,6 +237,12 @@ JS.ENV.NodeAdapterSpec = JS.Test.describe("NodeAdapter", function() { with(this)
check_content_type("text/javascript")
check_body('callback([{"channel":"/meta/handshake"}]);')
}})
+
+ it("does not let the client cache the response", function() { with(this) {
+ stub(server, "process").yields([[{channel: "/meta/handshake"}]])
+ get("/bayeux", params)
+ check_cache_control("no-cache, no-store")
+ }})
}})
describe("missing jsonp", function() { with(this) {
View
7 spec/ruby/rack_adapter_spec.rb
@@ -11,6 +11,7 @@
after { app.stop }
let(:content_type) { last_response["Content-Type"] }
+ let(:cache_control) { last_response["Cache-Control"] }
let(:access_control_origin) { last_response["Access-Control-Allow-Origin"] }
let(:json) { JSON.parse(body) }
let(:body) { last_response.body }
@@ -162,6 +163,12 @@
content_type.should == "text/javascript"
body.should == 'callback([{"channel":"/meta/handshake"}]);'
end
+
+ it "does not let the client cache the response" do
+ server.stub(:process).and_yield ["channel" => "/meta/handshake"]
+ get "/bayeux", params
+ cache_control.should == "no-cache, no-store"
+ end
end
describe "with an unknown path" do
Please sign in to comment.
Something went wrong with that request. Please try again.