mirror of
https://github.com/kataras/iris.git
synced 2026-01-09 04:51:56 +00:00
Release of version 10.4.0 - x8 faster embedded file server | Star and Read HISTORY.md
Former-commit-id: 4f8b8c95c1b107a9be3b1ef6835ece949a75ceb6
This commit is contained in:
@@ -2208,6 +2208,7 @@ var (
|
||||
contentDispositionHeaderKey = "Content-Disposition"
|
||||
cacheControlHeaderKey = "Cache-Control"
|
||||
contentEncodingHeaderKey = "Content-Encoding"
|
||||
gzipHeaderValue = "gzip"
|
||||
acceptEncodingHeaderKey = "Accept-Encoding"
|
||||
varyHeaderKey = "Vary"
|
||||
)
|
||||
@@ -2360,7 +2361,7 @@ func (ctx *context) StreamWriter(writer func(w io.Writer) bool) {
|
||||
func (ctx *context) ClientSupportsGzip() bool {
|
||||
if h := ctx.GetHeader(acceptEncodingHeaderKey); h != "" {
|
||||
for _, v := range strings.Split(h, ";") {
|
||||
if strings.Contains(v, "gzip") { // we do Contains because sometimes browsers has the q=, we don't use it atm. || strings.Contains(v,"deflate"){
|
||||
if strings.Contains(v, gzipHeaderValue) { // we do Contains because sometimes browsers has the q=, we don't use it atm. || strings.Contains(v,"deflate"){
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -2915,8 +2916,10 @@ func (ctx *context) ServeContent(content io.ReadSeeker, filename string, modtime
|
||||
ctx.SetLastModified(modtime)
|
||||
var out io.Writer
|
||||
if gzipCompression && ctx.ClientSupportsGzip() {
|
||||
ctx.writer.Header().Add(varyHeaderKey, acceptEncodingHeaderKey)
|
||||
ctx.Header(contentEncodingHeaderKey, "gzip")
|
||||
AddGzipHeaders(ctx.writer)
|
||||
|
||||
// ctx.writer.Header().Add(varyHeaderKey, acceptEncodingHeaderKey)
|
||||
// ctx.Header(contentEncodingHeaderKey,gzipHeaderValue)
|
||||
|
||||
gzipWriter := acquireGzipWriter(ctx.writer)
|
||||
defer releaseGzipWriter(gzipWriter)
|
||||
@@ -3191,7 +3194,6 @@ func (ctx *context) Exec(method string, path string) {
|
||||
req.RequestURI = path
|
||||
req.URL.Path = path
|
||||
req.Method = method
|
||||
req.Host = req.Host
|
||||
|
||||
// execute the route from the (internal) context router
|
||||
// this way we keep the sessions and the values
|
||||
|
||||
@@ -165,12 +165,11 @@ func (w *GzipResponseWriter) WriteNow(contents []byte) (int, error) {
|
||||
// Or a better idea, acquire and adapt the gzip writer on-time when is not disabled.
|
||||
// So that is not needed any more:
|
||||
// w.gzipWriter.Reset(noop)
|
||||
|
||||
return w.ResponseWriter.Write(contents)
|
||||
}
|
||||
|
||||
w.ResponseWriter.Header().Add(varyHeaderKey, "Accept-Encoding")
|
||||
w.ResponseWriter.Header().Add(contentEncodingHeaderKey, "gzip")
|
||||
|
||||
AddGzipHeaders(w.ResponseWriter)
|
||||
// if not `WriteNow` but "Content-Length" header
|
||||
// is exists, then delete it before `.Write`
|
||||
// Content-Length should not be there.
|
||||
@@ -178,6 +177,13 @@ func (w *GzipResponseWriter) WriteNow(contents []byte) (int, error) {
|
||||
return writeGzip(w.ResponseWriter, contents)
|
||||
}
|
||||
|
||||
// AddGzipHeaders just adds the headers "Vary" to "Accept-Encoding"
|
||||
// and "Content-Encoding" to "gzip".
|
||||
func AddGzipHeaders(w ResponseWriter) {
|
||||
w.Header().Add(varyHeaderKey, acceptEncodingHeaderKey)
|
||||
w.Header().Add(contentEncodingHeaderKey, gzipHeaderValue)
|
||||
}
|
||||
|
||||
// FlushResponse validates the response headers in order to be compatible with the gzip written data
|
||||
// and writes the data to the underline ResponseWriter.
|
||||
func (w *GzipResponseWriter) FlushResponse() {
|
||||
|
||||
Reference in New Issue
Block a user