aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/gitea.com/macaron/gzip
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-01-26 23:36:53 +0800
committerGitHub <noreply@github.com>2021-01-26 16:36:53 +0100
commit6433ba0ec3dfde67f45267aa12bd713c4a44c740 (patch)
tree8813388f7e58ff23ad24af9ccbdb5f0350cb3a09 /vendor/gitea.com/macaron/gzip
parent3adbbb4255c42cde04d59b6ebf5ead7e3edda3e7 (diff)
downloadgitea-6433ba0ec3dfde67f45267aa12bd713c4a44c740.tar.gz
gitea-6433ba0ec3dfde67f45267aa12bd713c4a44c740.zip
Move macaron to chi (#14293)
Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR. - [x] Define `context.ResponseWriter` interface with an implementation `context.Response`. - [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before. - [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic . - [x] Use https://github.com/unrolled/render instead of macaron's internal render - [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip - [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK** - [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha - [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache - [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding - [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors - [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation` - [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle. - [x] Removed macaron log service because it's not need any more. **BREAK** - [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition. - [x] Move Git HTTP protocol implementation to use routers directly. - [x] Fix the problem that chi routes don't support trailing slash but macaron did. - [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. Notices: - Chi router don't support request with trailing slash - Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI. Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'vendor/gitea.com/macaron/gzip')
-rw-r--r--vendor/gitea.com/macaron/gzip/.drone.yml24
-rw-r--r--vendor/gitea.com/macaron/gzip/README.md19
-rw-r--r--vendor/gitea.com/macaron/gzip/go.mod11
-rw-r--r--vendor/gitea.com/macaron/gzip/go.sum48
-rw-r--r--vendor/gitea.com/macaron/gzip/gzip.go368
5 files changed, 0 insertions, 470 deletions
diff --git a/vendor/gitea.com/macaron/gzip/.drone.yml b/vendor/gitea.com/macaron/gzip/.drone.yml
deleted file mode 100644
index 087a19664c..0000000000
--- a/vendor/gitea.com/macaron/gzip/.drone.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-kind: pipeline
-name: go1-14
-
-steps:
-- name: test
- image: golang:1.14
- environment:
- GOPROXY: https://goproxy.cn
- commands:
- - go build -v
- - go test -v -race -coverprofile=coverage.txt -covermode=atomic
-
----
-kind: pipeline
-name: go1-15
-
-steps:
-- name: test
- image: golang:1.15
- environment:
- GOPROXY: https://goproxy.cn
- commands:
- - go build -v
- - go test -v -race -coverprofile=coverage.txt -covermode=atomic \ No newline at end of file
diff --git a/vendor/gitea.com/macaron/gzip/README.md b/vendor/gitea.com/macaron/gzip/README.md
deleted file mode 100644
index e09c4a9d8c..0000000000
--- a/vendor/gitea.com/macaron/gzip/README.md
+++ /dev/null
@@ -1,19 +0,0 @@
-# gzip
-
-Middleware gzip provides gzip comparess middleware for [Macaron](https://gitea.com/macaron/macaron).
-
-### Installation
-
- go get gitea.com/macaron/gzip
-
-## Getting Help
-
-- [API Reference](https://godoc.org/gitea.com/macaron/gzip)
-
-## Credits
-
-This package is a modified version of [go-macaron gzip](github.com/go-macaron/gzip).
-
-## License
-
-This project is under the Apache License, Version 2.0. See the [LICENSE](LICENSE) file for the full license text. \ No newline at end of file
diff --git a/vendor/gitea.com/macaron/gzip/go.mod b/vendor/gitea.com/macaron/gzip/go.mod
deleted file mode 100644
index 877ee7e37a..0000000000
--- a/vendor/gitea.com/macaron/gzip/go.mod
+++ /dev/null
@@ -1,11 +0,0 @@
-module gitea.com/macaron/gzip
-
-go 1.12
-
-require (
- gitea.com/macaron/macaron v1.5.0
- github.com/klauspost/compress v1.9.2
- github.com/stretchr/testify v1.4.0
- golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
- gopkg.in/ini.v1 v1.60.1 // indirect
-)
diff --git a/vendor/gitea.com/macaron/gzip/go.sum b/vendor/gitea.com/macaron/gzip/go.sum
deleted file mode 100644
index b34055da3e..0000000000
--- a/vendor/gitea.com/macaron/gzip/go.sum
+++ /dev/null
@@ -1,48 +0,0 @@
-gitea.com/macaron/inject v0.0.0-20190805023432-d4c86e31027a h1:aOKEXkDTnh4euoH0so/THLXeHtQuqHmDPb1xEk6Ehok=
-gitea.com/macaron/inject v0.0.0-20190805023432-d4c86e31027a/go.mod h1:h6E4kLao1Yko6DOU6QDnQPcuoNzvbZqzj2mtPcEn1aM=
-gitea.com/macaron/macaron v1.5.0 h1:TvWEcHw1/zaHlo0GTuKEukLh3A99+QsU2mjBrXLXjVQ=
-gitea.com/macaron/macaron v1.5.0/go.mod h1:P7hfDbQjcW22lkYkXlxdRIfWOXxH2+K4EogN4Q0UlLY=
-github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
-github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
-github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1ks85zJ1lfDGgIiMDuIptTOhJq+zKyg=
-github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
-github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
-github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
-github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
-github.com/klauspost/compress v1.9.2 h1:LfVyl+ZlLlLDeQ/d2AqfGIIH4qEDu0Ed2S5GyhCWIWY=
-github.com/klauspost/compress v1.9.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
-github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 h1:Jpy1PXuP99tXNrhbq2BaPz9B+jNAvH1JPQQpG/9GCXY=
-github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
-github.com/smartystreets/assertions v1.0.1 h1:voD4ITNjPL5jjBfgR/r8fPIIBrliWrWHeiJApdr3r4w=
-github.com/smartystreets/assertions v1.0.1/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM=
-github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
-github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 h1:WN9BUFbdyOsSH/XohnWpXOlq9NBD5sGAB2FciQMUEe8=
-github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
-github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
-github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
-github.com/unknwon/com v1.0.1 h1:3d1LTxD+Lnf3soQiD4Cp/0BRB+Rsa/+RTvz8GMMzIXs=
-github.com/unknwon/com v1.0.1/go.mod h1:tOOxU81rwgoCLoOVVPHb6T/wt8HZygqH5id+GNnlCXM=
-golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
-golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
-golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
-golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM=
-golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
-golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
-golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
-golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
-golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/ini.v1 v1.44.0 h1:YRJzTUp0kSYWUVFF5XAbDFfyiqwsl0Vb9R8TVP5eRi0=
-gopkg.in/ini.v1 v1.44.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
-gopkg.in/ini.v1 v1.60.1 h1:P5y5shSkb0CFe44qEeMBgn8JLow09MP17jlJHanke5g=
-gopkg.in/ini.v1 v1.60.1/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
-gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
-gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/vendor/gitea.com/macaron/gzip/gzip.go b/vendor/gitea.com/macaron/gzip/gzip.go
deleted file mode 100644
index cd93e03f68..0000000000
--- a/vendor/gitea.com/macaron/gzip/gzip.go
+++ /dev/null
@@ -1,368 +0,0 @@
-// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package gzip
-
-import (
- "bufio"
- "errors"
- "fmt"
- "io"
- "net"
- "net/http"
- "regexp"
- "strconv"
- "strings"
- "sync"
-
- "gitea.com/macaron/macaron"
- "github.com/klauspost/compress/gzip"
-)
-
-const (
- acceptEncodingHeader = "Accept-Encoding"
- contentEncodingHeader = "Content-Encoding"
- contentLengthHeader = "Content-Length"
- contentTypeHeader = "Content-Type"
- rangeHeader = "Range"
- varyHeader = "Vary"
-)
-
-const (
- // MinSize is the minimum size of content we will compress
- MinSize = 1400
-)
-
-// noopClosers are io.Writers with a shim to prevent early closure
-type noopCloser struct {
- io.Writer
-}
-
-func (noopCloser) Close() error { return nil }
-
-// WriterPool is a gzip writer pool to reduce workload on creation of
-// gzip writers
-type WriterPool struct {
- pool sync.Pool
- compressionLevel int
-}
-
-// NewWriterPool creates a new pool
-func NewWriterPool(compressionLevel int) *WriterPool {
- return &WriterPool{pool: sync.Pool{
- // New will return nil, we'll manage the creation of new
- // writers in the middleware
- New: func() interface{} { return nil },
- },
- compressionLevel: compressionLevel}
-}
-
-// Get a writer from the pool - or create one if not available
-func (wp *WriterPool) Get(rw macaron.ResponseWriter) *gzip.Writer {
- ret := wp.pool.Get()
- if ret == nil {
- ret, _ = gzip.NewWriterLevel(rw, wp.compressionLevel)
- } else {
- ret.(*gzip.Writer).Reset(rw)
- }
- return ret.(*gzip.Writer)
-}
-
-// Put returns a writer to the pool
-func (wp *WriterPool) Put(w *gzip.Writer) {
- wp.pool.Put(w)
-}
-
-var writerPool WriterPool
-
-// Options represents the configuration for the gzip middleware
-type Options struct {
- CompressionLevel int
-}
-
-func validateCompressionLevel(level int) bool {
- return level == gzip.DefaultCompression ||
- level == gzip.ConstantCompression ||
- (level >= gzip.BestSpeed && level <= gzip.BestCompression)
-}
-
-func validate(options []Options) Options {
- // Default to level 4 compression (Best results seem to be between 4 and 6)
- opt := Options{CompressionLevel: 4}
- if len(options) > 0 {
- opt = options[0]
- }
- if !validateCompressionLevel(opt.CompressionLevel) {
- opt.CompressionLevel = 4
- }
- return opt
-}
-
-// Middleware creates a macaron.Handler to proxy the response
-func Middleware(options ...Options) macaron.Handler {
- opt := validate(options)
- writerPool = *NewWriterPool(opt.CompressionLevel)
- regex := regexp.MustCompile(`bytes=(\d+)\-.*`)
-
- return func(ctx *macaron.Context) {
- // If the client won't accept gzip or x-gzip don't compress
- if !strings.Contains(ctx.Req.Header.Get(acceptEncodingHeader), "gzip") &&
- !strings.Contains(ctx.Req.Header.Get(acceptEncodingHeader), "x-gzip") {
- return
- }
-
- // If the client is asking for a specific range of bytes - don't compress
- if rangeHdr := ctx.Req.Header.Get(rangeHeader); rangeHdr != "" {
-
- match := regex.FindStringSubmatch(rangeHdr)
- if len(match) > 1 {
- return
- }
- }
-
- // OK we should proxy the response writer
- // We are still not necessarily going to compress...
- proxyWriter := &ProxyResponseWriter{
- internal: ctx.Resp,
- }
- defer proxyWriter.Close()
-
- ctx.Resp = proxyWriter
- ctx.MapTo(proxyWriter, (*http.ResponseWriter)(nil))
-
- // Check if render middleware has been registered,
- // if yes, we need to modify ResponseWriter for it as well.
- if _, ok := ctx.Render.(*macaron.DummyRender); !ok {
- ctx.Render.SetResponseWriter(proxyWriter)
- }
-
- ctx.Next()
- ctx.Resp = proxyWriter.internal
- }
-}
-
-// ProxyResponseWriter is a wrapped macaron ResponseWriter that may compress its contents
-type ProxyResponseWriter struct {
- writer io.WriteCloser
- internal macaron.ResponseWriter
- stopped bool
-
- code int
- buf []byte
-}
-
-// Header returns the header map
-func (proxy *ProxyResponseWriter) Header() http.Header {
- return proxy.internal.Header()
-}
-
-// Status returns the status code of the response or 0 if the response has not been written.
-func (proxy *ProxyResponseWriter) Status() int {
- if proxy.code != 0 {
- return proxy.code
- }
- return proxy.internal.Status()
-}
-
-// Written returns whether or not the ResponseWriter has been written.
-func (proxy *ProxyResponseWriter) Written() bool {
- if proxy.code != 0 {
- return true
- }
- return proxy.internal.Written()
-}
-
-// Size returns the size of the response body.
-func (proxy *ProxyResponseWriter) Size() int {
- return proxy.internal.Size()
-}
-
-// Before allows for a function to be called before the ResponseWriter has been written to. This is
-// useful for setting headers or any other operations that must happen before a response has been written.
-func (proxy *ProxyResponseWriter) Before(before macaron.BeforeFunc) {
- proxy.internal.Before(before)
-}
-
-// Write appends data to the proxied gzip writer.
-func (proxy *ProxyResponseWriter) Write(b []byte) (int, error) {
- // if writer is initialized, use the writer
- if proxy.writer != nil {
- return proxy.writer.Write(b)
- }
-
- proxy.buf = append(proxy.buf, b...)
-
- var (
- contentLength, _ = strconv.Atoi(proxy.Header().Get(contentLengthHeader))
- contentType = proxy.Header().Get(contentTypeHeader)
- contentEncoding = proxy.Header().Get(contentEncodingHeader)
- )
-
- // OK if an encoding hasn't been chosen, and content length > 1400
- // and content type isn't a compressed type
- if contentEncoding == "" &&
- (contentLength == 0 || contentLength >= MinSize) &&
- (contentType == "" || !compressedContentType(contentType)) {
- // If current buffer is less than the min size and a Content-Length isn't set, then wait
- if len(proxy.buf) < MinSize && contentLength == 0 {
- return len(b), nil
- }
-
- // If the Content-Length is larger than minSize or the current buffer is larger than minSize, then continue.
- if contentLength >= MinSize || len(proxy.buf) >= MinSize {
- // if we don't know the content type, infer it
- if contentType == "" {
- contentType = http.DetectContentType(proxy.buf)
- proxy.Header().Set(contentTypeHeader, contentType)
- }
- // If the Content-Type is not compressed - Compress!
- if !compressedContentType(contentType) {
- if err := proxy.startGzip(); err != nil {
- return 0, err
- }
- return len(b), nil
- }
- }
- }
- // If we got here, we should not GZIP this response.
- if err := proxy.startPlain(); err != nil {
- return 0, err
- }
- return len(b), nil
-}
-
-func (proxy *ProxyResponseWriter) startGzip() error {
- // Set the content-encoding and vary headers.
- proxy.Header().Set(contentEncodingHeader, "gzip")
- proxy.Header().Set(varyHeader, acceptEncodingHeader)
-
- // if the Content-Length is already set, then calls to Write on gzip
- // will fail to set the Content-Length header since its already set
- // See: https://github.com/golang/go/issues/14975.
- proxy.Header().Del(contentLengthHeader)
-
- // Write the header to gzip response.
- if proxy.code != 0 {
- proxy.internal.WriteHeader(proxy.code)
- // Ensure that no other WriteHeader's happen
- proxy.code = 0
- }
-
- // Initialize and flush the buffer into the gzip response if there are any bytes.
- // If there aren't any, we shouldn't initialize it yet because on Close it will
- // write the gzip header even if nothing was ever written.
- if len(proxy.buf) > 0 {
- // Initialize the GZIP response.
- proxy.writer = writerPool.Get(proxy.internal)
-
- return proxy.writeBuf()
- }
- return nil
-}
-
-func (proxy *ProxyResponseWriter) startPlain() error {
- if proxy.code != 0 {
- proxy.internal.WriteHeader(proxy.code)
- proxy.code = 0
- }
- proxy.stopped = true
- proxy.writer = noopCloser{proxy.internal}
- return proxy.writeBuf()
-}
-
-func (proxy *ProxyResponseWriter) writeBuf() error {
- if proxy.buf == nil {
- return nil
- }
-
- n, err := proxy.writer.Write(proxy.buf)
-
- // This should never happen (per io.Writer docs), but if the write didn't
- // accept the entire buffer but returned no specific error, we have no clue
- // what's going on, so abort just to be safe.
- if err == nil && n < len(proxy.buf) {
- err = io.ErrShortWrite
- }
- proxy.buf = nil
- return err
-}
-
-// WriteHeader will ensure that we have setup the writer before we write the header
-func (proxy *ProxyResponseWriter) WriteHeader(code int) {
- if proxy.code == 0 {
- proxy.code = code
- }
-}
-
-// Close the writer
-func (proxy *ProxyResponseWriter) Close() error {
- if proxy.stopped {
- return nil
- }
-
- if proxy.writer == nil {
- err := proxy.startPlain()
- if err != nil {
- return fmt.Errorf("GzipMiddleware: write to regular responseWriter at close gets error: %q", err.Error())
- }
- }
-
- err := proxy.writer.Close()
-
- if poolWriter, ok := proxy.writer.(*gzip.Writer); ok {
- writerPool.Put(poolWriter)
- }
-
- proxy.writer = nil
- proxy.stopped = true
- return err
-}
-
-// Flush the writer
-func (proxy *ProxyResponseWriter) Flush() {
- if proxy.writer == nil {
- return
- }
-
- if gw, ok := proxy.writer.(*gzip.Writer); ok {
- gw.Flush()
- }
-
- proxy.internal.Flush()
-}
-
-// Push implements http.Pusher for HTTP/2 Push purposes
-func (proxy *ProxyResponseWriter) Push(target string, opts *http.PushOptions) error {
- pusher, ok := proxy.internal.(http.Pusher)
- if !ok {
- return errors.New("the ResponseWriter doesn't support the Pusher interface")
- }
- return pusher.Push(target, opts)
-}
-
-// Hijack implements http.Hijacker. If the underlying ResponseWriter is a
-// Hijacker, its Hijack method is returned. Otherwise an error is returned.
-func (proxy *ProxyResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
- hijacker, ok := proxy.internal.(http.Hijacker)
- if !ok {
- return nil, nil, fmt.Errorf("the ResponseWriter doesn't support the Hijacker interface")
- }
- return hijacker.Hijack()
-}
-
-// verify Hijacker interface implementation
-var _ http.Hijacker = &ProxyResponseWriter{}
-
-func compressedContentType(contentType string) bool {
- switch contentType {
- case "application/zip":
- return true
- case "application/x-gzip":
- return true
- case "application/gzip":
- return true
- default:
- return false
- }
-}