Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some bugs that download response instead of showing result #6 #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"time"

"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin.v1"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work, github.com/gin-gonic/gin is correct.

)

func main() {
Expand Down
5 changes: 3 additions & 2 deletions gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"sync"

"github.com/gin-gonic/gin"
"gopkg.in/gin-gonic/gin.v1"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are moving everything back to github.com/gin-gonic/gin in the time of dependency managers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so what happens if we use gin.v1 in our project ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should replace it with github.com/gin-gonic/gin.

)

const (
Expand Down Expand Up @@ -37,6 +37,7 @@ func Gzip(level int) gin.HandlerFunc {
gz.Reset(c.Writer)

c.Header("Content-Encoding", "gzip")
c.Header("Content-Type", "text/html; charset=UTF-8")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And how do you know that HTML should be returned?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default content type is x-gizp and this encoding download the response html !

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But who say that you are using gzip only for html?

c.Header("Vary", "Accept-Encoding")
c.Writer = &gzipWriter{c.Writer, gz}
defer func() {
Expand Down Expand Up @@ -70,7 +71,7 @@ func shouldCompress(req *http.Request) bool {
}

switch extension {
case ".png", ".gif", ".jpeg", ".jpg":
case ".png", ".gif", ".jpeg", ".jpg", ".css", ".js":
return false
default:
return true
Expand Down