Grails &引用;内容编码错误“;当我尝试gzip输出时

Grails &引用;内容编码错误“;当我尝试gzip输出时,grails,gzip,Grails,Gzip,我正在尝试gzip控制器操作的输出以节省一些带宽: new ByteArrayOutputStream().withStream{ baos -> new GZIPOutputStream( baos ).withWriter{ it << m.text.bytes } //def gzip = baos.toByteArray().encodeBase64() def gzip = new String( baos.toByteArray() ) respon

我正在尝试gzip控制器操作的输出以节省一些带宽:

new ByteArrayOutputStream().withStream{ baos ->
  new GZIPOutputStream( baos ).withWriter{ it << m.text.bytes }
  //def gzip = baos.toByteArray().encodeBase64()
  def gzip = new String( baos.toByteArray() )
  response.setHeader 'Content-Type', 'application/x-javascript'
  response.setHeader 'Content-Encoding', 'x-gzip'
  response.outputStream.withStream{ it << gzip }
}
newbytearrayoutputstream().withStream{baos->
新的GZIPOutputStream(baos).withWriter{it
def index(){
response.setHeader“内容类型”、“应用程序/x-javascript”
response.setHeader“内容编码”,“x-gzip”

新的GZIPOutputStream(response.outputStream)。使用writer{你可以检查你是否没有用utf-8 BOM保存文件吗?()你需要一个好的编辑器来注意差异。另外,如果启用了php错误报告,这可能会产生问题。不,没有BOM问题,它与php无关
    def index() {
            response.setHeader 'Content-Type', 'application/x-javascript'
            response.setHeader 'Content-Encoding', 'x-gzip'
            new GZIPOutputStream(response.outputStream).withWriter{ it << "Content comes here" }
    }