RenderBinary() disables CompressFilter
mikyk10 opened this issue · comments
I am trying to output a CSV file without using buffer nor creating a temporary file.
I used RenderBinary
for that purpose and it works but the response header does not contain Content-Encoding: gzip
while the app.conf has results.compressed = true
. Compression seems working unless RenderBinary
is used.
Here's the code I am working on so far.
Is there something I am missing or revel does not support compression in this case?
Code
func (c App) Test() revel.Result {
pr, pw := io.Pipe()
csvw := csv.NewWriter(pw)
go func() {
pw.Write([]byte{0xEF, 0xBB, 0xBF})
csvw.Write([]string{"aaaa", "bbbb", "cccc", "dddd"})
for i := 0; i < 10000; i++ {
csvw.Write([]string{"1111", "2222", "3333\n4444\n5555", "6666"})
csvw.Flush()
}
pw.Close()
}()
c.Response.ContentType = "text/csv"
return c.RenderBinary(pr, "test.csv", revel.Attachment, time.Now())
}
Expected Behavior
Successfully downloaded a CSV file while creating it simultaneously.
HTTP Response header contains Content-Encoding: gzip
(transferred with gzip compression)
Actual Behavior
Successfully downloaded a CSV file while creating it simultaneously.
HTTP Response header DOES NOT contain Content-Encoding: gzip
(not compressed)
I found some MIME types are not gzip-supported by the following hard-coded configuration.
I will create a PR to support text/csv
for now.
revel@v1.0.0/compress.go L21
var compressableMimes = [...]string{
"text/plain",
"text/html",
"text/xml",
"text/css",
"application/json",
"application/xml",
"application/xhtml+xml",
"application/rss+xml",
"application/javascript",
"application/x-javascript",
}
Thanks ~ Merge your request