【问题标题】:Cordova GZip decompression doesn't workCordova GZip 解压缩不起作用
【发布时间】:2015-07-29 09:47:05
【问题描述】:

我尝试启用 GZip 压缩以提高客户端和服务器之间的连接性能,但 WebView 似乎没有解压缩 GZip 响应。

响应标头(来自服务器)包含: 内容编码:gzip 内容类型:application/gzip

正文包含压缩的 JSON

在桌面浏览器上一切正常, 但如果它是 Chrome DevTools 中的 android 设备,我会看到压缩体。 移动应用不解压缩响应正文。

创建问题https://issues.apache.org/jira/browse/CB-9427

【问题讨论】:

  • android 移动 webview 和浏览器远不及桌面浏览器,他们可能只是不支持它。我不确定,但这是我最好的猜测。这就是为什么在 android 上我使用人行横道构建所有应用程序的原因。支持一切,性能飙升:crosswalk-project.org

标签: android cordova http gzip ionic


【解决方案1】:

当我将内容类型更改为“应用程序/json”时,问题就解决了。

Grape 框架应用的示例:

module App
  class Users < API

    resource :users do
      format :json
      content_type :txt, "application/json"
      parser :json, nil

      desc "Get users"
      params do
        optional :role, type: String, desc: "User's role"
      end

      get '/all' do
        users = User.all
        path = "#{Rails.root.to_s}/tmp/user_response.gz"
        FileUtils.rm_rf(path, secure: true)
        Zlib::GzipWriter.open(path){|gz| gz.write(users.to_json) }
        content_type "application/json"
        header['Content-Encoding'] = 'gzip';
        env['api.format'] = :json
        File.open(path).read
      end
    end
  end
end

问题https://issues.apache.org/jira/browse/CB-9427 已关闭。

感谢科尔多瓦支持团队!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-20
    • 2018-04-19
    • 2015-10-10
    • 1970-01-01
    • 1970-01-01
    • 2017-03-26
    • 2022-01-20
    相关资源
    最近更新 更多