应用程序收到的每个 post 响应都经过 gzip 压缩 JSON::ParserError - 意外令牌位于

Every post response the app gets is gzip compressed JSON::ParserError - unexpected token at

环境

jruby 9.0.5.0 (2.2.3) 2016-01-26 7bee00d Java HotSpot(TM) 64 位服务器 VM 25.72-b15 on 1.8.0_72-b15 +jit [darwin-x86_64]

Rails 3.2.13

rack-1.4.7

问题

我正在使用 jruby,似乎我的服务器发出的每个 post 请求都会得到一个 gzip 响应。它曾经工作得很好;我在那里和那里进行了一些 gem 更新,现在问题似乎遍及整个应用程序。

相关问题

在这个相关问题中,我尝试用猴子补丁解决它,但问题似乎比看起来更深。

https://github.com/zquestz/omniauth-google-oauth2/issues/229

如何强制我的应用程序自动解压缩所有 GZip 响应?

我尝试使用 Rack::Deflater 中间件,但没有成功。

我正在考虑为 ActionDispatch 创建一个猴子补丁。

有什么建议吗?

Gemfile.lock

GIT
  remote: git://github.com/aaronvegh/phone.git
  revision: 4c92d7ee2eef67ab9eef0700907d0af9b51e0173
  specs:
    phone (0.9.9.3)

GIT
  remote: git://github.com/devbbq/browser.git
  revision: 5e36c9ac3ebfcd252d53f378dac8a1327e5e0242
  specs:
    browser (0.1.6)

GIT
  remote: git://github.com/kml/quartz-jruby.git
  revision: c63bfafaad2b7fd159abffbb84abdd3ad833154f
  specs:
    quartz-jruby (0.2.2)

GIT
  remote: git@github.com:devbbq/restforce.git
  revision: aa77cb06ddd0c67cc2843b341e0286a6844b733c
  branch: feature/gemspec-upgrade
  specs:
    restforce (1.4.3)
      faraday (~> 0.9.0)
      faraday_middleware (>= 0.8.8)
      hashie (~> 3.2.0)
      json (>= 1.7.5, < 1.9.0)

GIT
  remote: https://github.com/aaronvegh/max_mind.git
  revision: 07753b9e492954aaea19d4975a1581d599fd8ee4
  specs:
    max_mind (1.0.0)

GIT
  remote: https://github.com/stripe/stripe-ruby
  revision: 24632af95aaa46f0a35b7cf939332bd49ee1eb36
  specs:
    stripe (1.36.0)
      rest-client (~> 1.4)

GEM
  remote: http://rubygems.org/
  specs:
    ParseUserAgent (0.1.0)
    actionmailer (3.2.13)
      actionpack (= 3.2.13)
      mail (~> 2.5.3)
    actionpack (3.2.13)
      activemodel (= 3.2.13)
      activesupport (= 3.2.13)
      builder (~> 3.0.0)
      erubis (~> 2.7.0)
      journey (~> 1.0.4)
      rack (~> 1.4.5)
      rack-cache (~> 1.2)
      rack-test (~> 0.6.1)
      sprockets (~> 2.2.1)
    active_record_query_trace (1.5.3)
    activemodel (3.2.13)
      activesupport (= 3.2.13)
      builder (~> 3.0.0)
    activerecord (3.2.13)
      activemodel (= 3.2.13)
      activesupport (= 3.2.13)
      arel (~> 3.0.2)
      tzinfo (~> 0.3.29)
    activerecord-jdbc-adapter (1.2.9.1)
    activerecord-jdbcmysql-adapter (1.2.9)
      activerecord-jdbc-adapter (~> 1.2.9)
      jdbc-mysql (~> 5.1.0)
    activeresource (3.2.13)
      activemodel (= 3.2.13)
      activesupport (= 3.2.13)
    activesupport (3.2.13)
      i18n (= 0.6.1)
      multi_json (~> 1.0)
    addressable (2.4.0)
    ansi (1.5.0)
    arel (3.0.3)
    authlogic (3.4.6)
      activerecord (>= 3.2)
      activesupport (>= 3.2)
      request_store (~> 1.0)
      scrypt (>= 1.2, < 3.0)
    awesome_print (1.6.1)
    bcrypt (3.1.11-java)
    builder (3.0.4)
    bullet (5.0.0)
      activesupport (>= 3.0.0)
      uniform_notifier (~> 1.9.0)
    callsite (0.0.11)
    capistrano (2.15.7)
      highline
      net-scp (>= 1.0.0)
      net-sftp (>= 2.0.0)
      net-ssh (>= 2.0.14)
      net-ssh-gateway (>= 1.1.0)
    capybara (2.2.1)
      mime-types (>= 1.16)
      nokogiri (>= 1.3.3)
      rack (>= 1.0.0)
      rack-test (>= 0.5.4)
      xpath (~> 2.0)
    celluloid (0.17.3)
      celluloid-essentials
      celluloid-extras
      celluloid-fsm
      celluloid-pool
      celluloid-supervision
      timers (>= 4.1.1)
    celluloid-essentials (0.20.5)
      timers (>= 4.1.1)
    celluloid-extras (0.20.5)
      timers (>= 4.1.1)
    celluloid-fsm (0.20.5)
      timers (>= 4.1.1)
    celluloid-pool (0.20.5)
      timers (>= 4.1.1)
    celluloid-supervision (0.20.5)
      timers (>= 4.1.1)
    chronic (0.10.2)
    class_logger (1.1)
    climate_control (0.0.3)
      activesupport (>= 3.0)
    cocaine (0.5.8)
      climate_control (>= 0.0.3, < 1.0)
    coderay (1.1.1)
    coffee-rails (3.2.2)
      coffee-script (>= 2.2.0)
      railties (~> 3.2.0)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.10.0)
    colorize (0.7.7)
    columnize (0.9.0)
    concurrent-ruby (1.0.1-java)
    connection_pool (2.2.0)
    cookiejar (0.3.0)
    countries (1.2.5)
      currencies (~> 0.4.2)
      i18n_data (~> 0.7.0)
    currencies (0.4.2)
    daemons (1.2.3)
    database_cleaner (1.5.1)
    databasedotcom (1.3.3)
      activesupport
      json
      multipart-post (~> 2.0.0)
    databasedotcom-oauth2 (0.2.1)
      addressable
      databasedotcom
      gibberish
      hashie
      oauth2
    databasedotcom-rails (1.1.0)
      databasedotcom
    delayed_job (4.1.1)
      activesupport (>= 3.0, < 5.0)
    delayed_job_active_record (4.1.0)
      activerecord (>= 3.0, < 5)
      delayed_job (>= 3.0, < 5)
    devise (3.2.4)
      bcrypt (~> 3.0)
      orm_adapter (~> 0.1)
      railties (>= 3.2.6, < 5)
      thread_safe (~> 0.1)
      warden (~> 1.2.3)
    diff-lcs (1.2.5)
    doorkeeper (1.3.1)
      railties (>= 3.1)
    dotenv (2.0.2)
    em-http-request (1.1.3)
      addressable (>= 2.3.4)
      cookiejar (<= 0.3.0)
      em-socksify (>= 0.3)
      eventmachine (>= 1.0.3)
      http_parser.rb (>= 0.6.0)
    em-socksify (0.3.1)
      eventmachine (>= 1.0.0.beta.4)
    engineyard (3.2.1)
      engineyard-cloud-client (~> 2.1)
      engineyard-serverside-adapter (~> 2.2)
      escape (~> 0.0.4)
      highline (~> 1.6.1)
      launchy (~> 2.1)
      net-ssh (~> 2.7)
    engineyard-cloud-client (2.1.0)
      multi_json (~> 1.6)
      rest-client (~> 1.6.1)
    engineyard-serverside-adapter (2.4.0)
      escape (~> 0.0.4)
      multi_json (~> 1.6)
    erubis (2.7.0)
    escape (0.0.4)
    eventmachine (1.0.9.1-java)
    exception_notification_rails3 (1.2.0)
    execjs (2.6.0)
    factory_girl (4.5.0)
      activesupport (>= 3.0.0)
    factory_girl_rails (4.6.0)
      factory_girl (~> 4.5.0)
      railties (>= 3.0.0)
    faraday (0.9.2)
      multipart-post (>= 1.2, < 3)
    faraday_middleware (0.10.0)
      faraday (>= 0.7.4, < 0.10)
    fastercsv (1.5.5)
    faye (1.0.3)
      cookiejar (>= 0.3.0)
      em-http-request (>= 0.3.0)
      eventmachine (>= 0.12.0)
      faye-websocket (>= 0.7.0)
      multi_json (>= 1.0.0)
      rack (>= 1.0.0)
      websocket-driver (>= 0.3.0)
    faye-websocket (0.10.3)
      eventmachine (>= 0.12.0)
      websocket-driver (>= 0.5.1)
    ffi (1.9.10-java)
    ffi-compiler (0.1.3)
      ffi (>= 1.0.0)
      rake
    font-awesome-rails (4.5.0.1)
      railties (>= 3.2, < 5.1)
    geoip (1.6.1)
    gibberish (2.0.0)
    git-version-bump (0.15.1)
    globalize (3.1.0)
      activemodel (>= 3.1.0, < 4.0.0)
      activerecord (>= 3.1.0, < 4.0.0)
    google-api-client (0.9)
      activesupport (>= 3.2)
      addressable (~> 2.3)
      googleauth (~> 0.5)
      httpclient (~> 2.7)
      hurley (~> 0.1)
      memoist (~> 0.11)
      mime-types (>= 1.6)
      multi_json (~> 1.11)
      representable (~> 2.3.0)
      retriable (~> 2.0)
      thor (~> 0.19)
    google-qr (0.2.2)
    google_url_shortener (1.0.0)
      json (>= 1.4.6)
      rest-client (>= 1.6.7)
      trollop (= 1.16.2)
    googleauth (0.5.1)
      faraday (~> 0.9)
      jwt (~> 1.4)
      logging (~> 2.0)
      memoist (~> 0.12)
      multi_json (~> 1.11)
      os (~> 0.9)
      signet (~> 0.7)
    hashie (3.2.0)
    highline (1.6.21)
    hike (1.2.3)
    hitimes (1.2.3-java)
    http_parser.rb (0.6.0-java)
    httparty (0.11.0)
      multi_json (~> 1.0)
      multi_xml (>= 0.5.2)
    httpclient (2.7.1)
    hurley (0.2)
    i18n (0.6.1)
    i18n_data (0.7.0)
    jdbc-mysql (5.1.38)
    journey (1.0.4)
    jquery-rails (3.1.4)
      railties (>= 3.0, < 5.0)
      thor (>= 0.14, < 2.0)
    jruby-jars (1.7.12)
    jruby-lint (0.4.1)
      jruby-openssl
      nokogiri (>= 1.5.0.beta.4)
      term-ansicolor
    jruby-openssl (0.9.15-java)
    jruby-rack (1.1.20)
    jruby-rack-worker (0.10.1)
      jruby-rack (~> 1.1.10)
    json (1.8.3-java)
    jwt (1.5.1)
    km (1.1.3)
    kramdown (1.10.0)
    launchy (2.4.3-java)
      addressable (~> 2.3)
      spoon (~> 0.0.1)
    linecache (1.3.1-java)
    little-plugger (1.1.4)
    log4jruby (1.0.0-java)
    logging (2.0.0)
      little-plugger (~> 1.1)
      multi_json (~> 1.10)
    mail (2.5.4)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    memoist (0.14.0)
    meta_request (0.4.0)
      callsite (~> 0.0, >= 0.0.11)
      rack-contrib (~> 1.1)
      railties (>= 3.0.0, < 5.1.0)
    method_source (0.8.2)
    mime-types (1.25.1)
    mini_exiftool (2.5.1)
    mini_exiftool_vendored (9.2.7.v1)
      mini_exiftool (>= 1.6.0)
    minitest (4.7.5)
    multi_json (1.11.2)
    multi_xml (0.5.5)
    multipart-post (2.0.0)
    mush (0.3.0)
      httparty (>= 0.6.1)
    net-scp (1.2.1)
      net-ssh (>= 2.6.5)
    net-sftp (2.1.2)
      net-ssh (>= 2.6.5)
    net-ssh (2.9.4)
    net-ssh-gateway (1.2.0)
      net-ssh (>= 2.6.5)
    newrelic_rpm (3.15.0.314)
    nokogiri (1.6.7.2-java)
    oauth (0.5.1)
    oauth2 (1.1.0)
      faraday (>= 0.8, < 0.10)
      jwt (~> 1.0, < 1.5.2)
      multi_json (~> 1.3)
      multi_xml (~> 0.5)
      rack (>= 1.2, < 3)
    omniauth (1.3.1)
      hashie (>= 1.2, < 4)
      rack (>= 1.0, < 3)
    omniauth-google-oauth2 (0.3.1)
      jwt (~> 1.0)
      multi_json (~> 1.3)
      omniauth (>= 1.1.1)
      omniauth-oauth2 (>= 1.3.1)
    omniauth-oauth2 (1.4.0)
      oauth2 (~> 1.0)
      omniauth (~> 1.2)
    orm_adapter (0.5.0)
    os (0.9.6)
    paperclip (3.5.4)
      activemodel (>= 3.0.0)
      activesupport (>= 3.0.0)
      cocaine (~> 0.5.3)
      mime-types
    pdfkit (0.8.2)
    polyglot (0.3.5)
    power_assert (0.2.7)
    pry (0.9.12.6-java)
      coderay (~> 1.0)
      method_source (~> 0.8)
      slop (~> 3.4)
      spoon (~> 0.0)
    pry-rails (0.3.4)
      pry (>= 0.9.10)
    pry_debug (0.1.0)
      pry (~> 0.9.0)
    puma (3.0.2-java)
    rack (1.4.7)
    rack-cache (1.6.1)
      rack (>= 0.4)
    rack-contrib (1.4.0)
      git-version-bump (~> 0.15)
      rack (~> 1.4)
    rack-ssl (1.3.4)
      rack
    rack-test (0.6.3)
      rack (>= 1.0)
    rails (3.2.13)
      actionmailer (= 3.2.13)
      actionpack (= 3.2.13)
      activerecord (= 3.2.13)
      activeresource (= 3.2.13)
      activesupport (= 3.2.13)
      bundler (~> 1.0)
      railties (= 3.2.13)
    rails-footnotes (4.1.8)
      rails (>= 3.2)
    rails_12factor (0.0.3)
      rails_serve_static_assets
      rails_stdout_logging
    rails_serve_static_assets (0.0.5)
    rails_stdout_logging (0.0.4)
    railties (3.2.13)
      actionpack (= 3.2.13)
      activesupport (= 3.2.13)
      rack-ssl (~> 1.3.2)
      rake (>= 0.8.7)
      rdoc (~> 3.4)
      thor (>= 0.14.6, < 2.0)
    rake (11.0.1)
    rdoc (3.12.2)
      json (~> 1.4)
    redis (3.2.2)
    remotipart (1.2.1)
    representable (2.3.0)
      uber (~> 0.0.7)
    request_store (1.3.0)
    rest-client (1.6.9)
      mime-types (~> 1.16)
    retriable (2.1.0)
    rollbar (2.8.2)
      multi_json
    rspec-core (3.0.4)
      rspec-support (~> 3.0.0)
    rspec-expectations (3.0.4)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.0.0)
    rspec-mocks (3.0.4)
      rspec-support (~> 3.0.0)
    rspec-rails (3.0.2)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-core (~> 3.0.0)
      rspec-expectations (~> 3.0.0)
      rspec-mocks (~> 3.0.0)
      rspec-support (~> 3.0.0)
    rspec-support (3.0.4)
    ruby-debug (0.10.6)
      columnize (>= 0.1)
      linecache (~> 1.3.1)
      ruby-debug-base (~> 0.10.6.0)
    ruby-debug-base (0.10.6-java)
    rubyzip (0.9.9)
    rvm-capistrano (1.5.6)
      capistrano (~> 2.15.4)
    sass (3.4.21)
    sass-rails (3.2.6)
      railties (~> 3.2.0)
      sass (>= 3.1.10)
      tilt (~> 1.3)
    scrypt (2.1.1)
      ffi-compiler (>= 0.0.2)
      rake
    sidekiq (4.1.0)
      concurrent-ruby (~> 1.0)
      connection_pool (~> 2.2, >= 2.2.0)
      redis (~> 3.2, >= 3.2.1)
    signet (0.7.2)
      addressable (~> 2.3)
      faraday (~> 0.9)
      jwt (~> 1.5)
      multi_json (~> 1.10)
    slop (3.6.0)
    smarter_csv (1.0.19)
    spoon (0.0.4)
      ffi
    sprockets (2.2.3)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sucker_punch (1.6.0)
      celluloid (~> 0.17.2)
    term-ansicolor (1.3.2)
      tins (~> 1.0)
    test-unit (3.1.7)
      power_assert
    therubyrhino (2.0.4)
      therubyrhino_jar (>= 1.7.3)
    therubyrhino_jar (1.7.6)
    thor (0.19.1)
    thread_safe (0.3.5-java)
    tilt (1.4.1)
    timecop (0.8.0)
    timers (4.1.1)
      hitimes
    tins (1.8.2)
    treetop (1.4.15)
      polyglot
      polyglot (>= 0.3.1)
    trinidad (1.4.6)
      jruby-rack (~> 1.1.13)
      trinidad_jars (>= 1.3.0, < 1.5.0)
    trinidad_diagnostics_extension (0.1.0)
      jruby-lint (>= 0.3.0)
      trinidad
    trinidad_jars (1.4.2)
    trollop (1.16.2)
    turn (0.9.7)
      ansi
      minitest (~> 4)
    tzinfo (0.3.46)
    uber (0.0.15)
    uglifier (2.7.2)
      execjs (>= 0.3.0)
      json (>= 1.8.0)
    uniform_notifier (1.9.0)
    url_safe_base64 (0.2.2)
    useragent (0.16.5)
    uuidtools (2.1.5)
    validates_email_format_of (1.6.3)
      i18n
    vero (0.9.1)
      json
      rest-client
      sucker_punch (~> 1.6.0)
    warbler (1.4.9)
      jruby-jars (>= 1.5.6, < 2.0)
      jruby-rack (>= 1.1.1, < 1.3)
      rake (>= 0.9.6)
      rubyzip (>= 0.9, < 1.2)
    warden (1.2.6)
      rack (>= 1.0)
    websocket-driver (0.6.3-java)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.2)
    whenever (0.9.4)
      chronic (>= 0.6.3)
    whois (3.6.5)
      activesupport (>= 3)
    will_paginate (3.1.0)
    will_paginate-foundation (5.3.4)
      will_paginate (>= 3.0.3)
    xml-simple (1.1.5)
    xpath (2.0.0)
      nokogiri (~> 1.3)
    yard (0.8.7.6)

PLATFORMS
  java

DEPENDENCIES
  ParseUserAgent
  active_record_query_trace
  activerecord-jdbc-adapter (~> 1.2.9)
  activerecord-jdbcmysql-adapter (~> 1.2.9)
  authlogic
  awesome_print
  better_errors
  binding_of_caller
  browser!
  bullet
  capistrano
  capybara (~> 2.2.0)
  class_logger
  coffee-rails (~> 3.2.1)
  colorize
  countries
  daemons
  database_cleaner
  databasedotcom
  databasedotcom-oauth2
  databasedotcom-rails
  debugger
  delayed_job_active_record
  devise (= 3.2.4)
  doorkeeper (= 1.3.1)
  dotenv (~> 2.0.2)
  engineyard
  exception_notification_rails3
  execjs
  factory_girl_rails
  fastercsv
  faye (~> 1.0.1)
  font-awesome-rails
  geoip
  globalize (~> 3.1.0)
  google-api-client (= 0.9)
  google-qr
  google_url_shortener
  httparty (~> 0.11.0)
  jquery-rails
  jruby-jars (>= 1.7.12)
  jruby-lint
  jruby-rack (>= 1.1.14)
  jruby-rack-worker
  json
  km
  kramdown
  log4jruby
  mail
  max_mind!
  meta_request
  mini_exiftool_vendored
  mush
  mysql2
  net-ssh
  newrelic_rpm
  nokogiri
  oauth
  oauth2
  omniauth-google-oauth2
  paperclip (~> 3.0)
  pdfkit
  phone!
  pry
  pry-rails
  pry_debug
  puma
  quartz-jruby!
  rack-test
  rails (= 3.2.13)
  rails-footnotes (>= 3.7.9)
  rails_12factor
  redcarpet
  remotipart
  rest-client (~> 1.6.7)
  restforce!
  rollbar (~> 2.8.0)
  rspec-rails (~> 3.0.0)
  ruby-debug
  rubyzip (~> 0.9.9)
  rvm-capistrano
  sass-rails (~> 3.2.3)
  sidekiq
  smarter_csv (~> 1.0.19)
  stripe!
  test-unit
  therubyracer
  therubyrhino
  thin
  timecop
  trinidad
  trinidad_diagnostics_extension
  turn
  uglifier (>= 1.0.3)
  unicode
  url_safe_base64
  useragent
  uuidtools
  validates_email_format_of
  vero
  warbler
  whenever
  whois
  will_paginate (~> 3.0)
  will_paginate-foundation
  xml-simple
  yard (~> 0.8.7.4)

BUNDLED WITH
   1.11.2

我正在回答我自己的问题,因为我找到了解决方法。

修复:

ruby 2.0 代码在“@decode_content”设置为真之前不会进行 gzip 解码。

如果 ruby 1.9 无法升级到 ruby 2.0,请将该代码添加到您的项目中。

module HTTPResponseDecodeContentOverride
  def initialize(h,c,m)
    super(h,c,m)
    @decode_content = true
  end
  def body
    res = super
    if self['content-length']
      self['content-length']= res.bytesize
    end
    res
  end
end

module Net
  class HTTPResponse
    prepend HTTPResponseDecodeContentOverride
  end
end

找到