From 73ebdaf0445beb90a8397ca4a3ac05885b6b89fc Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 13 Nov 2009 10:54:53 -0800 Subject: [PATCH] JSON: set no-transform in headers We can't have Rack::Deflater compressing long-pulling JS --- .../rails_app-2.3.4/app/controllers/progress_controller.rb | 1 + examples/rails_app-2.3.4/config.ru | 3 +++ lib/upr/json.rb | 12 ++++++++---- 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) -- 2.11.4.GIT