-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2489 from traPtitech/revert/fix/gzip_middleware
Revert "Merge pull request #2473 from traPtitech/fix/gzip_middleware"
- Loading branch information
Showing
4 changed files
with
41 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package middlewares | ||
|
||
import ( | ||
"compress/gzip" | ||
"net/http" | ||
|
||
"github.com/NYTimes/gziphandler" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
// Gzip Gzipミドルウェア | ||
func Gzip() echo.MiddlewareFunc { | ||
gzh, _ := gziphandler.GzipHandlerWithOpts( | ||
gziphandler.ContentTypes([]string{ | ||
"application/javascript", | ||
"application/json", | ||
"image/svg+xml", | ||
"text/css", | ||
"text/html", | ||
"text/plain", | ||
"text/xml", | ||
}), | ||
gziphandler.CompressionLevel(gzip.BestSpeed), | ||
) | ||
return func(next echo.HandlerFunc) echo.HandlerFunc { | ||
return func(c echo.Context) (err error) { | ||
gzh(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
c.SetRequest(r) | ||
c.Response().Writer = w | ||
if err := next(c); err != nil { | ||
c.Error(err) | ||
} | ||
})).ServeHTTP(c.Response().Writer, c.Request()) | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters