forked from nytimes/gziphandler
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gzip_compat.go
92 lines (80 loc) · 3.17 KB
/
gzip_compat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// +build go1.9
// +build ignore
package gziphandler
import "net/http"
const (
// DefaultQValue is the default qvalue to assign to an encoding if no explicit qvalue is set.
// This is actually kind of ambiguous in RFC 2616, so hopefully it's correct.
// The examples seem to indicate that it is.
//
// Deprecated: maintained for compatibility, no longer used.
DefaultQValue = 1.0
// DefaultMinSize defines the minimum size to reach to enable compression.
//
// Deprecated: maintained for compatibility.
DefaultMinSize = defaultMinSize
)
// DeprecatedHandler is a type alias to to group deprecated
// functions together for godoc.
//
// This will be removed once godoc automatically groups
// deprecated symbols, see golang/go#17056.
type DeprecatedHandler = http.Handler
// DeprecatedMiddleware is a type alias to to group
// deprecated functions together for godoc.
//
// This will be removed once godoc automatically groups
// deprecated symbols, see golang/go#17056.
type DeprecatedMiddleware = func(http.Handler) http.Handler
// 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
// default compression level.
//
// Deprecated: maintained for compatibility, use Gzip.
func GzipHandler(h http.Handler) DeprecatedHandler {
return Gzip(h)
}
// GzipHandlerWithOpts ...
//
// Deprecated: maintained for compatibility, use Wrapper.
func GzipHandlerWithOpts(opts ...option) (DeprecatedMiddleware, error) {
return Wrapper(opts), nil
}
// MustNewGzipLevelHandler behaves just like
// NewGzipLevelHandler except that in an error case it
// panics rather than returning an error.
//
// Deprecated: maintained for compatibility, use Wrapper.
func MustNewGzipLevelHandler(level int) DeprecatedMiddleware {
return Wrapper(CompressionLevel(level))
}
// NewGzipLevelAndMinSize behave as NewGzipLevelHandler
// except it let the caller specify the minimum size before
// compression.
//
// Deprecated: maintained for compatibility, use Wrapper.
func NewGzipLevelAndMinSize(level, minSize int) (DeprecatedMiddleware, error) {
return Wrapper(CompressionLevel(level), MinSize(minSize)), nil
}
// NewGzipLevelHandler returns a wrapper function (often
// known as middleware) which can be used to wrap an HTTP
// handler to transparently gzip the response body if the
// client supports it (via the Accept-Encoding header).
// Responses will be encoded at the given gzip compression
// level. An error will be returned only if an invalid gzip
// compression level is given, so if one can ensure the
// level is valid, the returned error can be safely ignored.
//
// Deprecated: maintained for compatibility, use Wrapper.
func NewGzipLevelHandler(level int) (DeprecatedMiddleware, error) {
return Wrapper(CompressionLevel(level)), nil
}
/*type GzipResponseWriter
func (w *GzipResponseWriter) Close() error
func (w *GzipResponseWriter) Flush()
func (w *GzipResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
func (w *GzipResponseWriter) Push(target string, opts *http.PushOptions) error
func (w *GzipResponseWriter) Write(b []byte) (int, error)
func (w *GzipResponseWriter) WriteHeader(code int)
*/