MM-26065: Reverts Brotli encoding. (#14834)
* MM-26065: Reverts Brotli encoding. * MM-26065: Removes package reference.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
61ff43aef8
Коммит
2bb6071f73
@@ -6,8 +6,8 @@ package api4
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/NYTimes/gziphandler"
|
||||||
"github.com/mattermost/mattermost-server/v5/web"
|
"github.com/mattermost/mattermost-server/v5/web"
|
||||||
"github.com/mkraft/gziphandler"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Context = web.Context
|
type Context = web.Context
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -4,6 +4,7 @@ go 1.14
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Masterminds/squirrel v1.2.0
|
github.com/Masterminds/squirrel v1.2.0
|
||||||
|
github.com/NYTimes/gziphandler v1.1.1
|
||||||
github.com/RoaringBitmap/roaring v0.4.23 // indirect
|
github.com/RoaringBitmap/roaring v0.4.23 // indirect
|
||||||
github.com/armon/go-metrics v0.3.0 // indirect
|
github.com/armon/go-metrics v0.3.0 // indirect
|
||||||
github.com/avct/uasurfer v0.0.0-20191028135549-26b5daa857f1
|
github.com/avct/uasurfer v0.0.0-20191028135549-26b5daa857f1
|
||||||
@@ -72,7 +73,6 @@ require (
|
|||||||
github.com/minio/minio-go/v6 v6.0.55
|
github.com/minio/minio-go/v6 v6.0.55
|
||||||
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
|
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.2.3 // indirect
|
github.com/mitchellh/mapstructure v1.2.3 // indirect
|
||||||
github.com/mkraft/gziphandler v1.1.2-0.20200509175700-73dc64f3ad90
|
|
||||||
github.com/muesli/smartcrop v0.3.0 // indirect
|
github.com/muesli/smartcrop v0.3.0 // indirect
|
||||||
github.com/oklog/run v1.1.0 // indirect
|
github.com/oklog/run v1.1.0 // indirect
|
||||||
github.com/olekukonko/tablewriter v0.0.4 // indirect
|
github.com/olekukonko/tablewriter v0.0.4 // indirect
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -25,6 +25,8 @@ github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF0
|
|||||||
github.com/Masterminds/squirrel v1.2.0 h1:K1NhbTO21BWG47IVR0OnIZuE0LZcXAYqywrC3Ko53KI=
|
github.com/Masterminds/squirrel v1.2.0 h1:K1NhbTO21BWG47IVR0OnIZuE0LZcXAYqywrC3Ko53KI=
|
||||||
github.com/Masterminds/squirrel v1.2.0/go.mod h1:yaPeOnPG5ZRwL9oKdTsO/prlkPbXWZlRVMQ/gGlzIuA=
|
github.com/Masterminds/squirrel v1.2.0/go.mod h1:yaPeOnPG5ZRwL9oKdTsO/prlkPbXWZlRVMQ/gGlzIuA=
|
||||||
github.com/Masterminds/vcs v1.13.0/go.mod h1:N09YCmOQr6RLxC6UNHzuVwAdodYbbnycGHSmwVJjcKA=
|
github.com/Masterminds/vcs v1.13.0/go.mod h1:N09YCmOQr6RLxC6UNHzuVwAdodYbbnycGHSmwVJjcKA=
|
||||||
|
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
|
||||||
|
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
|
||||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||||
github.com/PaulARoy/azurestoragecache v0.0.0-20170906084534-3c249a3ba788/go.mod h1:lY1dZd8HBzJ10eqKERHn3CU59tfhzcAVb2c0ZhIWSOk=
|
github.com/PaulARoy/azurestoragecache v0.0.0-20170906084534-3c249a3ba788/go.mod h1:lY1dZd8HBzJ10eqKERHn3CU59tfhzcAVb2c0ZhIWSOk=
|
||||||
github.com/RoaringBitmap/roaring v0.4.21 h1:WJ/zIlNX4wQZ9x8Ey33O1UaD9TCTakYsdLFSBcTwH+8=
|
github.com/RoaringBitmap/roaring v0.4.21 h1:WJ/zIlNX4wQZ9x8Ey33O1UaD9TCTakYsdLFSBcTwH+8=
|
||||||
@@ -461,8 +463,6 @@ github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQz
|
|||||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||||
github.com/mitchellh/mapstructure v1.2.3 h1:f/MjBEBDLttYCGfRaKBbKSRVF5aV2O6fnBpzknuE3jU=
|
github.com/mitchellh/mapstructure v1.2.3 h1:f/MjBEBDLttYCGfRaKBbKSRVF5aV2O6fnBpzknuE3jU=
|
||||||
github.com/mitchellh/mapstructure v1.2.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
github.com/mitchellh/mapstructure v1.2.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
github.com/mkraft/gziphandler v1.1.2-0.20200509175700-73dc64f3ad90 h1:qEm+0lDAcdszJkCnYSuP1oITiQf0TzDIAmeD2PlBtZU=
|
|
||||||
github.com/mkraft/gziphandler v1.1.2-0.20200509175700-73dc64f3ad90/go.mod h1:gG8WEPb2aI5MHdmHv83au7bk3molRSZiAjdxYrEMJdQ=
|
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
|||||||
0
vendor/github.com/mkraft/gziphandler/.gitignore → vendor/github.com/NYTimes/gziphandler/.gitignore
сгенерированный
поставляемый
0
vendor/github.com/mkraft/gziphandler/.gitignore → vendor/github.com/NYTimes/gziphandler/.gitignore
сгенерированный
поставляемый
0
vendor/github.com/mkraft/gziphandler/.travis.yml → vendor/github.com/NYTimes/gziphandler/.travis.yml
сгенерированный
поставляемый
0
vendor/github.com/mkraft/gziphandler/.travis.yml → vendor/github.com/NYTimes/gziphandler/.travis.yml
сгенерированный
поставляемый
0
vendor/github.com/mkraft/gziphandler/CODE_OF_CONDUCT.md → vendor/github.com/NYTimes/gziphandler/CODE_OF_CONDUCT.md
сгенерированный
поставляемый
0
vendor/github.com/mkraft/gziphandler/CODE_OF_CONDUCT.md → vendor/github.com/NYTimes/gziphandler/CODE_OF_CONDUCT.md
сгенерированный
поставляемый
0
vendor/github.com/mkraft/gziphandler/CONTRIBUTING.md → vendor/github.com/NYTimes/gziphandler/CONTRIBUTING.md
сгенерированный
поставляемый
0
vendor/github.com/mkraft/gziphandler/CONTRIBUTING.md → vendor/github.com/NYTimes/gziphandler/CONTRIBUTING.md
сгенерированный
поставляемый
0
vendor/github.com/mkraft/gziphandler/LICENSE → vendor/github.com/NYTimes/gziphandler/LICENSE
сгенерированный
поставляемый
0
vendor/github.com/mkraft/gziphandler/LICENSE → vendor/github.com/NYTimes/gziphandler/LICENSE
сгенерированный
поставляемый
0
vendor/github.com/mkraft/gziphandler/README.md → vendor/github.com/NYTimes/gziphandler/README.md
сгенерированный
поставляемый
0
vendor/github.com/mkraft/gziphandler/README.md → vendor/github.com/NYTimes/gziphandler/README.md
сгенерированный
поставляемый
2
vendor/github.com/mkraft/gziphandler/go.mod → vendor/github.com/NYTimes/gziphandler/go.mod
сгенерированный
поставляемый
2
vendor/github.com/mkraft/gziphandler/go.mod → vendor/github.com/NYTimes/gziphandler/go.mod
сгенерированный
поставляемый
@@ -1,4 +1,4 @@
|
|||||||
module github.com/mkraft/gziphandler
|
module github.com/NYTimes/gziphandler
|
||||||
|
|
||||||
go 1.11
|
go 1.11
|
||||||
|
|
||||||
0
vendor/github.com/mkraft/gziphandler/go.sum → vendor/github.com/NYTimes/gziphandler/go.sum
сгенерированный
поставляемый
0
vendor/github.com/mkraft/gziphandler/go.sum → vendor/github.com/NYTimes/gziphandler/go.sum
сгенерированный
поставляемый
91
vendor/github.com/mkraft/gziphandler/gzip.go → vendor/github.com/NYTimes/gziphandler/gzip.go
сгенерированный
поставляемый
91
vendor/github.com/mkraft/gziphandler/gzip.go → vendor/github.com/NYTimes/gziphandler/gzip.go
сгенерированный
поставляемый
@@ -1,4 +1,4 @@
|
|||||||
package gziphandler // import "github.com/mkraft/gziphandler"
|
package gziphandler // import "github.com/NYTimes/gziphandler"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
@@ -81,13 +81,11 @@ type GzipResponseWriter struct {
|
|||||||
|
|
||||||
code int // Saves the WriteHeader value.
|
code int // Saves the WriteHeader value.
|
||||||
|
|
||||||
minSize int // Specifies the minimum response size to gzip. If the response length is bigger than this value, it is compressed.
|
minSize int // Specifed the minimum response size to gzip. If the response length is bigger than this value, it is compressed.
|
||||||
buf []byte // Holds the first part of the write before reaching the minSize or the end of the write.
|
buf []byte // Holds the first part of the write before reaching the minSize or the end of the write.
|
||||||
ignore bool // If true, then we immediately passthru writes to the underlying ResponseWriter.
|
ignore bool // If true, then we immediately passthru writes to the underlying ResponseWriter.
|
||||||
|
|
||||||
contentTypes []parsedContentType // Only compress if the response is one of these content-types. All are accepted if empty.
|
contentTypes []parsedContentType // Only compress if the response is one of these content-types. All are accepted if empty.
|
||||||
|
|
||||||
contentTypeExceptions []parsedContentType // Only compress if the response is not one of these content-types. All are accepted if empty.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type GzipResponseWriterWithCloseNotify struct {
|
type GzipResponseWriterWithCloseNotify struct {
|
||||||
@@ -120,7 +118,7 @@ func (w *GzipResponseWriter) Write(b []byte) (int, error) {
|
|||||||
ce = w.Header().Get(contentEncoding)
|
ce = w.Header().Get(contentEncoding)
|
||||||
)
|
)
|
||||||
// Only continue if they didn't already choose an encoding or a known unhandled content length or type.
|
// Only continue if they didn't already choose an encoding or a known unhandled content length or type.
|
||||||
if ce == "" && (cl == 0 || cl >= w.minSize) && (ct == "" || handleContentType(w.contentTypes, w.contentTypeExceptions, ct)) {
|
if ce == "" && (cl == 0 || cl >= w.minSize) && (ct == "" || handleContentType(w.contentTypes, ct)) {
|
||||||
// If the current buffer is less than minSize and a Content-Length isn't set, then wait until we have more data.
|
// If the current buffer is less than minSize and a Content-Length isn't set, then wait until we have more data.
|
||||||
if len(w.buf) < w.minSize && cl == 0 {
|
if len(w.buf) < w.minSize && cl == 0 {
|
||||||
return len(b), nil
|
return len(b), nil
|
||||||
@@ -133,7 +131,7 @@ func (w *GzipResponseWriter) Write(b []byte) (int, error) {
|
|||||||
w.Header().Set(contentType, ct)
|
w.Header().Set(contentType, ct)
|
||||||
}
|
}
|
||||||
// If the Content-Type is acceptable to GZIP, initialize the GZIP writer.
|
// If the Content-Type is acceptable to GZIP, initialize the GZIP writer.
|
||||||
if handleContentType(w.contentTypes, w.contentTypeExceptions, ct) {
|
if handleContentType(w.contentTypes, ct) {
|
||||||
if err := w.startGzip(); err != nil {
|
if err := w.startGzip(); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@@ -326,11 +324,10 @@ func GzipHandlerWithOpts(opts ...option) (func(http.Handler) http.Handler, error
|
|||||||
w.Header().Add(vary, acceptEncoding)
|
w.Header().Add(vary, acceptEncoding)
|
||||||
if acceptsGzip(r) {
|
if acceptsGzip(r) {
|
||||||
gw := &GzipResponseWriter{
|
gw := &GzipResponseWriter{
|
||||||
ResponseWriter: w,
|
ResponseWriter: w,
|
||||||
index: index,
|
index: index,
|
||||||
minSize: c.minSize,
|
minSize: c.minSize,
|
||||||
contentTypes: c.contentTypes,
|
contentTypes: c.contentTypes,
|
||||||
contentTypeExceptions: c.contentTypeExceptions,
|
|
||||||
}
|
}
|
||||||
defer gw.Close()
|
defer gw.Close()
|
||||||
|
|
||||||
@@ -379,10 +376,9 @@ func (pct parsedContentType) equals(mediaType string, params map[string]string)
|
|||||||
|
|
||||||
// Used for functional configuration.
|
// Used for functional configuration.
|
||||||
type config struct {
|
type config struct {
|
||||||
minSize int
|
minSize int
|
||||||
level int
|
level int
|
||||||
contentTypes []parsedContentType
|
contentTypes []parsedContentType
|
||||||
contentTypeExceptions []parsedContentType
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *config) validate() error {
|
func (c *config) validate() error {
|
||||||
@@ -390,10 +386,6 @@ func (c *config) validate() error {
|
|||||||
return fmt.Errorf("invalid compression level requested: %d", c.level)
|
return fmt.Errorf("invalid compression level requested: %d", c.level)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c.contentTypes) > 0 && len(c.contentTypeExceptions) > 0 {
|
|
||||||
return fmt.Errorf("ContentTypes and ContentTypeExceptions are mutually exclusive")
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.minSize < 0 {
|
if c.minSize < 0 {
|
||||||
return fmt.Errorf("minimum size must be more than zero")
|
return fmt.Errorf("minimum size must be more than zero")
|
||||||
}
|
}
|
||||||
@@ -419,9 +411,6 @@ func CompressionLevel(level int) option {
|
|||||||
// the Content-Type header to before compressing. If none
|
// the Content-Type header to before compressing. If none
|
||||||
// match, the response will be returned as-is.
|
// match, the response will be returned as-is.
|
||||||
//
|
//
|
||||||
// ContentTypes cannot be used with ContentTypeExceptions, the options
|
|
||||||
// are mutually exclusive.
|
|
||||||
//
|
|
||||||
// Content types are compared in a case-insensitive, whitespace-ignored
|
// Content types are compared in a case-insensitive, whitespace-ignored
|
||||||
// manner.
|
// manner.
|
||||||
//
|
//
|
||||||
@@ -448,39 +437,6 @@ func ContentTypes(types []string) option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContentTypeExceptions specifies a list of content types to compare
|
|
||||||
// the Content-Type header to before compressing. If any
|
|
||||||
// match, the response will be returned as-is.
|
|
||||||
//
|
|
||||||
// Content types are compared in a case-insensitive, whitespace-ignored
|
|
||||||
// manner.
|
|
||||||
//
|
|
||||||
// ContentTypeExceptions cannot be used with ContentTypes, the options
|
|
||||||
// are mutually exclusive.
|
|
||||||
//
|
|
||||||
// A MIME type without any other directive will match a content type
|
|
||||||
// that has the same MIME type, regardless of that content type's other
|
|
||||||
// directives. I.e., "text/html" will match both "text/html" and
|
|
||||||
// "text/html; charset=utf-8".
|
|
||||||
//
|
|
||||||
// A MIME type with any other directive will only match a content type
|
|
||||||
// that has the same MIME type and other directives. I.e.,
|
|
||||||
// "text/html; charset=utf-8" will only match "text/html; charset=utf-8".
|
|
||||||
//
|
|
||||||
// By default, responses are gzipped regardless of
|
|
||||||
// Content-Type.
|
|
||||||
func ContentTypeExceptions(types []string) option {
|
|
||||||
return func(c *config) {
|
|
||||||
c.contentTypeExceptions = []parsedContentType{}
|
|
||||||
for _, v := range types {
|
|
||||||
mediaType, params, err := mime.ParseMediaType(v)
|
|
||||||
if err == nil {
|
|
||||||
c.contentTypeExceptions = append(c.contentTypeExceptions, parsedContentType{mediaType, params})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GzipHandler wraps an HTTP handler, to transparently gzip the response body if
|
// GzipHandler wraps an HTTP handler, to transparently gzip the response body if
|
||||||
// the client supports it (via the Accept-Encoding header). This will compress at
|
// the client supports it (via the Accept-Encoding header). This will compress at
|
||||||
// the default compression level.
|
// the default compression level.
|
||||||
@@ -497,11 +453,9 @@ func acceptsGzip(r *http.Request) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returns true if we've been configured to compress the specific content type.
|
// returns true if we've been configured to compress the specific content type.
|
||||||
func handleContentType(whitelist, blacklist []parsedContentType, ct string) bool {
|
func handleContentType(contentTypes []parsedContentType, ct string) bool {
|
||||||
// If whitelist and blacklist are empty we handle all content types.
|
// If contentTypes is empty we handle all content types.
|
||||||
whiteLen := len(whitelist)
|
if len(contentTypes) == 0 {
|
||||||
blackLen := len(blacklist)
|
|
||||||
if whiteLen == 0 && blackLen == 0 {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,24 +464,13 @@ func handleContentType(whitelist, blacklist []parsedContentType, ct string) bool
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
var listToCheck []parsedContentType
|
for _, c := range contentTypes {
|
||||||
var whitelistMode bool
|
|
||||||
|
|
||||||
if whiteLen > 0 {
|
|
||||||
whitelistMode = true
|
|
||||||
listToCheck = whitelist
|
|
||||||
} else {
|
|
||||||
listToCheck = blacklist
|
|
||||||
}
|
|
||||||
|
|
||||||
var isInList bool
|
|
||||||
for _, c := range listToCheck {
|
|
||||||
if c.equals(mediaType, params) {
|
if c.equals(mediaType, params) {
|
||||||
isInList = true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (whitelistMode && isInList) || (!whitelistMode && !isInList)
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseEncodings attempts to parse a list of codings, per RFC 2616, as might
|
// parseEncodings attempts to parse a list of codings, per RFC 2616, as might
|
||||||
0
vendor/github.com/mkraft/gziphandler/gzip_go18.go → vendor/github.com/NYTimes/gziphandler/gzip_go18.go
сгенерированный
поставляемый
0
vendor/github.com/mkraft/gziphandler/gzip_go18.go → vendor/github.com/NYTimes/gziphandler/gzip_go18.go
сгенерированный
поставляемый
6
vendor/modules.txt
поставляемый
6
vendor/modules.txt
поставляемый
@@ -1,6 +1,9 @@
|
|||||||
# github.com/Masterminds/squirrel v1.2.0
|
# github.com/Masterminds/squirrel v1.2.0
|
||||||
## explicit
|
## explicit
|
||||||
github.com/Masterminds/squirrel
|
github.com/Masterminds/squirrel
|
||||||
|
# github.com/NYTimes/gziphandler v1.1.1
|
||||||
|
## explicit
|
||||||
|
github.com/NYTimes/gziphandler
|
||||||
# github.com/RoaringBitmap/roaring v0.4.23
|
# github.com/RoaringBitmap/roaring v0.4.23
|
||||||
## explicit
|
## explicit
|
||||||
github.com/RoaringBitmap/roaring
|
github.com/RoaringBitmap/roaring
|
||||||
@@ -317,9 +320,6 @@ github.com/mitchellh/go-testing-interface
|
|||||||
# github.com/mitchellh/mapstructure v1.2.3
|
# github.com/mitchellh/mapstructure v1.2.3
|
||||||
## explicit
|
## explicit
|
||||||
github.com/mitchellh/mapstructure
|
github.com/mitchellh/mapstructure
|
||||||
# github.com/mkraft/gziphandler v1.1.2-0.20200509175700-73dc64f3ad90
|
|
||||||
## explicit
|
|
||||||
github.com/mkraft/gziphandler
|
|
||||||
# github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
|
# github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
|
||||||
github.com/modern-go/concurrent
|
github.com/modern-go/concurrent
|
||||||
# github.com/modern-go/reflect2 v1.0.1
|
# github.com/modern-go/reflect2 v1.0.1
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mkraft/gziphandler"
|
"github.com/NYTimes/gziphandler"
|
||||||
"github.com/opentracing/opentracing-go"
|
"github.com/opentracing/opentracing-go"
|
||||||
"github.com/opentracing/opentracing-go/ext"
|
"github.com/opentracing/opentracing-go/ext"
|
||||||
spanlog "github.com/opentracing/opentracing-go/log"
|
spanlog "github.com/opentracing/opentracing-go/log"
|
||||||
|
|||||||
@@ -9,23 +9,15 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/NYTimes/gziphandler"
|
||||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||||
"github.com/mattermost/mattermost-server/v5/model"
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
"github.com/mattermost/mattermost-server/v5/utils"
|
"github.com/mattermost/mattermost-server/v5/utils"
|
||||||
"github.com/mattermost/mattermost-server/v5/utils/fileutils"
|
"github.com/mattermost/mattermost-server/v5/utils/fileutils"
|
||||||
"github.com/mkraft/gziphandler"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var robotsTxt = []byte("User-agent: *\nDisallow: /\n")
|
var robotsTxt = []byte("User-agent: *\nDisallow: /\n")
|
||||||
|
|
||||||
// the static content types that are Brotli encoded rather than gzipped.
|
|
||||||
var brotliEncodedContent = map[string]string{
|
|
||||||
"js": "application/javascript",
|
|
||||||
"css": "text/css",
|
|
||||||
}
|
|
||||||
|
|
||||||
var brotliContentTypes []string
|
|
||||||
|
|
||||||
func (w *Web) InitStatic() {
|
func (w *Web) InitStatic() {
|
||||||
if *w.ConfigService.Config().ServiceSettings.WebserverMode != "disabled" {
|
if *w.ConfigService.Config().ServiceSettings.WebserverMode != "disabled" {
|
||||||
if err := utils.UpdateAssetsSubpathFromConfig(w.ConfigService.Config()); err != nil {
|
if err := utils.UpdateAssetsSubpathFromConfig(w.ConfigService.Config()); err != nil {
|
||||||
@@ -37,20 +29,11 @@ func (w *Web) InitStatic() {
|
|||||||
|
|
||||||
subpath, _ := utils.GetSubpathFromConfig(w.ConfigService.Config())
|
subpath, _ := utils.GetSubpathFromConfig(w.ConfigService.Config())
|
||||||
|
|
||||||
staticHandler := brotliFilesHandler(staticFilesHandler(http.StripPrefix(path.Join(subpath, "static"), http.FileServer(http.Dir(staticDir)))))
|
staticHandler := staticFilesHandler(http.StripPrefix(path.Join(subpath, "static"), http.FileServer(http.Dir(staticDir))))
|
||||||
pluginHandler := staticFilesHandler(http.StripPrefix(path.Join(subpath, "static", "plugins"), http.FileServer(http.Dir(*w.ConfigService.Config().PluginSettings.ClientDirectory))))
|
pluginHandler := staticFilesHandler(http.StripPrefix(path.Join(subpath, "static", "plugins"), http.FileServer(http.Dir(*w.ConfigService.Config().PluginSettings.ClientDirectory))))
|
||||||
|
|
||||||
if *w.ConfigService.Config().ServiceSettings.WebserverMode == "gzip" {
|
if *w.ConfigService.Config().ServiceSettings.WebserverMode == "gzip" {
|
||||||
for _, ct := range brotliEncodedContent {
|
staticHandler = gziphandler.GzipHandler(staticHandler)
|
||||||
brotliContentTypes = append(brotliContentTypes, ct)
|
|
||||||
}
|
|
||||||
|
|
||||||
everythingExceptBrotliGzipHandler, err := gziphandler.GzipHandlerWithOpts(gziphandler.ContentTypeExceptions(brotliContentTypes))
|
|
||||||
if err != nil {
|
|
||||||
mlog.Error("Failed to initialize gziphandler", mlog.Err(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
staticHandler = everythingExceptBrotliGzipHandler(staticHandler)
|
|
||||||
pluginHandler = gziphandler.GzipHandler(pluginHandler)
|
pluginHandler = gziphandler.GzipHandler(pluginHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,26 +71,6 @@ func root(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
http.ServeFile(w, r, filepath.Join(staticDir, "root.html"))
|
http.ServeFile(w, r, filepath.Join(staticDir, "root.html"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func acceptsEncodingBrotli(r *http.Request) bool {
|
|
||||||
directives := strings.Fields(r.Header.Get("Accept-Encoding"))
|
|
||||||
for _, directive := range directives {
|
|
||||||
if strings.ToLower(directive) == "br" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func requestingBrotliFileExtension(r *http.Request) (bool, string) {
|
|
||||||
extension := r.URL.Path[strings.LastIndex(r.URL.Path, ".")+1:]
|
|
||||||
for bx, ct := range brotliEncodedContent {
|
|
||||||
if bx == extension {
|
|
||||||
return true, ct
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false, ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func staticFilesHandler(handler http.Handler) http.Handler {
|
func staticFilesHandler(handler http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
//wrap our ResponseWriter with our no-cache 404-handler
|
//wrap our ResponseWriter with our no-cache 404-handler
|
||||||
@@ -124,21 +87,6 @@ func staticFilesHandler(handler http.Handler) http.Handler {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func brotliFilesHandler(handler http.Handler) http.Handler {
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if model.BuildNumber != "dev" {
|
|
||||||
isRequestingBrotliFile, contentType := requestingBrotliFileExtension(r)
|
|
||||||
if isRequestingBrotliFile && acceptsEncodingBrotli(r) {
|
|
||||||
r.URL.Path = r.URL.Path + ".br"
|
|
||||||
w.Header().Set("Content-Encoding", "br")
|
|
||||||
w.Header().Set("Content-Type", contentType)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handler.ServeHTTP(w, r)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
type notFoundNoCacheResponseWriter struct {
|
type notFoundNoCacheResponseWriter struct {
|
||||||
http.ResponseWriter
|
http.ResponseWriter
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
||||||
// See LICENSE.txt for license information.
|
|
||||||
|
|
||||||
package web
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
var tests = []struct {
|
|
||||||
requestURL string
|
|
||||||
requestContentType string
|
|
||||||
requestAcceptEncoding []string
|
|
||||||
expectBrotli bool
|
|
||||||
}{
|
|
||||||
{"http://test.com/foo.js", "application/javascript", []string{"br"}, true},
|
|
||||||
{"http://test.com/foo.css", "text/css", []string{"br"}, true},
|
|
||||||
{"http://test.com/foo.jss", "text/plain; charset=utf-8", []string{"gzip"}, false},
|
|
||||||
{"http://test.com/foo.css", "text/plain; charset=utf-8", []string{"gzip"}, false},
|
|
||||||
{"http://test.com/foo.jsx", "text/plain; charset=utf-8", []string{"br"}, false},
|
|
||||||
{"http://test.com/foo.xcss", "text/plain; charset=utf-8", []string{"gzip"}, false},
|
|
||||||
}
|
|
||||||
|
|
||||||
type mockHandler struct{}
|
|
||||||
|
|
||||||
func (mh mockHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
||||||
fmt.Fprintf(w, "hello")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBrotliFilesHandler(t *testing.T) {
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(fmt.Sprintf("%v", tt), func(t *testing.T) {
|
|
||||||
|
|
||||||
req := httptest.NewRequest("GET", tt.requestURL, nil)
|
|
||||||
req.Header.Set("Accept-Encoding", strings.Join(tt.requestAcceptEncoding, ", "))
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
|
|
||||||
handler := brotliFilesHandler(mockHandler{})
|
|
||||||
handler.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
resp := w.Result()
|
|
||||||
|
|
||||||
require.Equal(t, tt.expectBrotli, resp.Header.Get("Content-Encoding") == "br")
|
|
||||||
if tt.expectBrotli {
|
|
||||||
require.Equal(t, tt.requestURL+".br", req.URL.String())
|
|
||||||
} else {
|
|
||||||
require.Equal(t, tt.requestURL, req.URL.String())
|
|
||||||
}
|
|
||||||
require.Equal(t, tt.requestContentType, resp.Header.Get("Content-Type"))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ссылка в новой задаче
Block a user