about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-11-13 10:54:53 -0800
committerEric Wong <normalperson@yhbt.net>2009-11-13 10:55:40 -0800
commit73ebdaf0445beb90a8397ca4a3ac05885b6b89fc (patch)
tree38710018019076defb7ccadce76db6f7fe2bba30
parent474f31b22bdc90a1baf0cc5cc5e5a0cf22f5710a (diff)
downloadupr-73ebdaf0445beb90a8397ca4a3ac05885b6b89fc.tar.gz
JSON: set no-transform in headers
We can't have Rack::Deflater compressing long-pulling JS
-rw-r--r--examples/rails_app-2.3.4/app/controllers/progress_controller.rb1
-rw-r--r--examples/rails_app-2.3.4/config.ru3
-rw-r--r--lib/upr/json.rb12
3 files changed, 12 insertions, 4 deletions
diff --git a/examples/rails_app-2.3.4/app/controllers/progress_controller.rb b/examples/rails_app-2.3.4/app/controllers/progress_controller.rb
index b3d91f3..c3dddda 100644
--- a/examples/rails_app-2.3.4/app/controllers/progress_controller.rb
+++ b/examples/rails_app-2.3.4/app/controllers/progress_controller.rb
@@ -5,6 +5,7 @@ class ProgressController < ApplicationController
       :frequency => 0.5,
       :env => request.env,
     }
+    response.headers.update(Upr::JSON::RESPONSE_HEADERS)
     render(Upr::JSON.new(opt).rails_render_options)
   end
 end
diff --git a/examples/rails_app-2.3.4/config.ru b/examples/rails_app-2.3.4/config.ru
index d51b6b2..4597926 100644
--- a/examples/rails_app-2.3.4/config.ru
+++ b/examples/rails_app-2.3.4/config.ru
@@ -1,3 +1,6 @@
 require 'config/environment'
+use Rack::ContentLength
+use Rack::Chunked
+use Rack::Deflater
 use Rails::Rack::Static
 run ActionController::Dispatcher.new
diff --git a/lib/upr/json.rb b/lib/upr/json.rb
index 6c03b6b..9f78d54 100644
--- a/lib/upr/json.rb
+++ b/lib/upr/json.rb
@@ -19,9 +19,13 @@ module Upr
 
     SLEEP_CLASS = defined?(Actor) ? Actor : Kernel
 
-    RESP_HEADERS = {
+    # our default response headers, we need to set no-transform to
+    # prevent deflaters from compressing our already-small small input
+    # and also to prevent buffering/corking of the response inside
+    # deflater buffers.
+    RESPONSE_HEADERS = {
       'Content-Type' => 'application/json',
-      'Cache-Control' => 'no-cache',
+      'Cache-Control' => 'no-cache, no-transform',
     }
 
     def initialize(options = {})
@@ -82,7 +86,7 @@ module Upr
       if uid = extract_upload_id(env)
         _wrap(env, uid)
       else
-        [ 400, RESP_HEADERS.dup, [ _error_msg("upload_id not given") ] ]
+        [ 400, RESPONSE_HEADERS.dup, [ _error_msg("upload_id not given") ] ]
       end
     end
 
@@ -116,7 +120,7 @@ module Upr
     def _wrap(env, uid)
       _self = dup
       _self.upload_id = uid
-      [ 200, RESP_HEADERS.dup, _self ]
+      [ 200, RESPONSE_HEADERS.dup, _self ]
     end
 
     def _error_msg(msg)