Rewrote Caddy from the ground up; initial commit of 0.9 branch
These changes span work from the last ~4 months in an effort to make
Caddy more extensible, reduce the coupling between its components, and
lay a more robust foundation of code going forward into 1.0. A bunch of
new features have been added, too, with even higher future potential.
The most significant design change is an overall inversion of
dependencies. Instead of the caddy package knowing about the server
and the notion of middleware and config, the caddy package exposes an
interface that other components plug into. This does introduce more
indirection when reading the code, but every piece is very modular and
pluggable. Even the HTTP server is pluggable.
The caddy package has been moved to the top level, and main has been
pushed into a subfolder called caddy. The actual logic of the main
file has been pushed even further into caddy/caddymain/run.go so that
custom builds of Caddy can be 'go get'able.
The HTTPS logic was surgically separated into two parts to divide the
TLS-specific code and the HTTPS-specific code. The caddytls package can
now be used by any type of server that needs TLS, not just HTTP. I also
added the ability to customize nearly every aspect of TLS at the site
level rather than all sites sharing the same TLS configuration. Not all
of this flexibility is exposed in the Caddyfile yet, but it may be in
the future. Caddy can also generate self-signed certificates in memory
for the convenience of a developer working on localhost who wants HTTPS.
And Caddy now supports the DNS challenge, assuming at least one DNS
provider is plugged in.
Dozens, if not hundreds, of other minor changes swept through the code
base as I literally started from an empty main function, copying over
functions or files as needed, then adjusting them to fit in the new
design. Most tests have been restored and adapted to the new API,
but more work is needed there.
A lot of what was "impossible" before is now possible, or can be made
possible with minimal disruption of the code. For example, it's fairly
easy to make plugins hook into another part of the code via callbacks.
Plugins can do more than just be directives; we now have plugins that
customize how the Caddyfile is loaded (useful when you need to get your
configuration from a remote store).
Site addresses no longer need be just a host and port. They can have a
path, allowing you to scope a configuration to a specific path. There is
no inheretance, however; each site configuration is distinct.
Thanks to amazing work by Lucas Clemente, this commit adds experimental
QUIC support. Turn it on using the -quic flag; your browser may have
to be configured to enable it.
Almost everything is here, but you will notice that most of the middle-
ware are missing. After those are transferred over, we'll be ready for
beta tests.
I'm very excited to get this out. Thanks for everyone's help and
patience these last few months. I hope you like it!!
2016-06-04 18:00:29 -05:00
|
|
|
// Package gzip provides a middleware layer that performs
|
2015-01-30 01:52:18 -05:00
|
|
|
// gzip compression on the response.
|
2015-01-30 00:04:18 -05:00
|
|
|
package gzip
|
|
|
|
|
|
|
|
import (
|
2016-02-24 14:23:15 -05:00
|
|
|
"bufio"
|
2015-01-30 00:04:18 -05:00
|
|
|
"compress/gzip"
|
|
|
|
"io"
|
2015-12-09 12:44:25 -05:00
|
|
|
"io/ioutil"
|
2016-02-24 14:23:15 -05:00
|
|
|
"net"
|
2015-01-30 00:04:18 -05:00
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
2017-02-17 11:25:22 -05:00
|
|
|
"errors"
|
2017-03-12 17:41:49 -05:00
|
|
|
|
Rewrote Caddy from the ground up; initial commit of 0.9 branch
These changes span work from the last ~4 months in an effort to make
Caddy more extensible, reduce the coupling between its components, and
lay a more robust foundation of code going forward into 1.0. A bunch of
new features have been added, too, with even higher future potential.
The most significant design change is an overall inversion of
dependencies. Instead of the caddy package knowing about the server
and the notion of middleware and config, the caddy package exposes an
interface that other components plug into. This does introduce more
indirection when reading the code, but every piece is very modular and
pluggable. Even the HTTP server is pluggable.
The caddy package has been moved to the top level, and main has been
pushed into a subfolder called caddy. The actual logic of the main
file has been pushed even further into caddy/caddymain/run.go so that
custom builds of Caddy can be 'go get'able.
The HTTPS logic was surgically separated into two parts to divide the
TLS-specific code and the HTTPS-specific code. The caddytls package can
now be used by any type of server that needs TLS, not just HTTP. I also
added the ability to customize nearly every aspect of TLS at the site
level rather than all sites sharing the same TLS configuration. Not all
of this flexibility is exposed in the Caddyfile yet, but it may be in
the future. Caddy can also generate self-signed certificates in memory
for the convenience of a developer working on localhost who wants HTTPS.
And Caddy now supports the DNS challenge, assuming at least one DNS
provider is plugged in.
Dozens, if not hundreds, of other minor changes swept through the code
base as I literally started from an empty main function, copying over
functions or files as needed, then adjusting them to fit in the new
design. Most tests have been restored and adapted to the new API,
but more work is needed there.
A lot of what was "impossible" before is now possible, or can be made
possible with minimal disruption of the code. For example, it's fairly
easy to make plugins hook into another part of the code via callbacks.
Plugins can do more than just be directives; we now have plugins that
customize how the Caddyfile is loaded (useful when you need to get your
configuration from a remote store).
Site addresses no longer need be just a host and port. They can have a
path, allowing you to scope a configuration to a specific path. There is
no inheretance, however; each site configuration is distinct.
Thanks to amazing work by Lucas Clemente, this commit adds experimental
QUIC support. Turn it on using the -quic flag; your browser may have
to be configured to enable it.
Almost everything is here, but you will notice that most of the middle-
ware are missing. After those are transferred over, we'll be ready for
beta tests.
I'm very excited to get this out. Thanks for everyone's help and
patience these last few months. I hope you like it!!
2016-06-04 18:00:29 -05:00
|
|
|
"github.com/mholt/caddy"
|
|
|
|
"github.com/mholt/caddy/caddyhttp/httpserver"
|
2015-01-30 00:04:18 -05:00
|
|
|
)
|
|
|
|
|
Rewrote Caddy from the ground up; initial commit of 0.9 branch
These changes span work from the last ~4 months in an effort to make
Caddy more extensible, reduce the coupling between its components, and
lay a more robust foundation of code going forward into 1.0. A bunch of
new features have been added, too, with even higher future potential.
The most significant design change is an overall inversion of
dependencies. Instead of the caddy package knowing about the server
and the notion of middleware and config, the caddy package exposes an
interface that other components plug into. This does introduce more
indirection when reading the code, but every piece is very modular and
pluggable. Even the HTTP server is pluggable.
The caddy package has been moved to the top level, and main has been
pushed into a subfolder called caddy. The actual logic of the main
file has been pushed even further into caddy/caddymain/run.go so that
custom builds of Caddy can be 'go get'able.
The HTTPS logic was surgically separated into two parts to divide the
TLS-specific code and the HTTPS-specific code. The caddytls package can
now be used by any type of server that needs TLS, not just HTTP. I also
added the ability to customize nearly every aspect of TLS at the site
level rather than all sites sharing the same TLS configuration. Not all
of this flexibility is exposed in the Caddyfile yet, but it may be in
the future. Caddy can also generate self-signed certificates in memory
for the convenience of a developer working on localhost who wants HTTPS.
And Caddy now supports the DNS challenge, assuming at least one DNS
provider is plugged in.
Dozens, if not hundreds, of other minor changes swept through the code
base as I literally started from an empty main function, copying over
functions or files as needed, then adjusting them to fit in the new
design. Most tests have been restored and adapted to the new API,
but more work is needed there.
A lot of what was "impossible" before is now possible, or can be made
possible with minimal disruption of the code. For example, it's fairly
easy to make plugins hook into another part of the code via callbacks.
Plugins can do more than just be directives; we now have plugins that
customize how the Caddyfile is loaded (useful when you need to get your
configuration from a remote store).
Site addresses no longer need be just a host and port. They can have a
path, allowing you to scope a configuration to a specific path. There is
no inheretance, however; each site configuration is distinct.
Thanks to amazing work by Lucas Clemente, this commit adds experimental
QUIC support. Turn it on using the -quic flag; your browser may have
to be configured to enable it.
Almost everything is here, but you will notice that most of the middle-
ware are missing. After those are transferred over, we'll be ready for
beta tests.
I'm very excited to get this out. Thanks for everyone's help and
patience these last few months. I hope you like it!!
2016-06-04 18:00:29 -05:00
|
|
|
func init() {
|
2016-06-06 16:31:03 -05:00
|
|
|
caddy.RegisterPlugin("gzip", caddy.Plugin{
|
Rewrote Caddy from the ground up; initial commit of 0.9 branch
These changes span work from the last ~4 months in an effort to make
Caddy more extensible, reduce the coupling between its components, and
lay a more robust foundation of code going forward into 1.0. A bunch of
new features have been added, too, with even higher future potential.
The most significant design change is an overall inversion of
dependencies. Instead of the caddy package knowing about the server
and the notion of middleware and config, the caddy package exposes an
interface that other components plug into. This does introduce more
indirection when reading the code, but every piece is very modular and
pluggable. Even the HTTP server is pluggable.
The caddy package has been moved to the top level, and main has been
pushed into a subfolder called caddy. The actual logic of the main
file has been pushed even further into caddy/caddymain/run.go so that
custom builds of Caddy can be 'go get'able.
The HTTPS logic was surgically separated into two parts to divide the
TLS-specific code and the HTTPS-specific code. The caddytls package can
now be used by any type of server that needs TLS, not just HTTP. I also
added the ability to customize nearly every aspect of TLS at the site
level rather than all sites sharing the same TLS configuration. Not all
of this flexibility is exposed in the Caddyfile yet, but it may be in
the future. Caddy can also generate self-signed certificates in memory
for the convenience of a developer working on localhost who wants HTTPS.
And Caddy now supports the DNS challenge, assuming at least one DNS
provider is plugged in.
Dozens, if not hundreds, of other minor changes swept through the code
base as I literally started from an empty main function, copying over
functions or files as needed, then adjusting them to fit in the new
design. Most tests have been restored and adapted to the new API,
but more work is needed there.
A lot of what was "impossible" before is now possible, or can be made
possible with minimal disruption of the code. For example, it's fairly
easy to make plugins hook into another part of the code via callbacks.
Plugins can do more than just be directives; we now have plugins that
customize how the Caddyfile is loaded (useful when you need to get your
configuration from a remote store).
Site addresses no longer need be just a host and port. They can have a
path, allowing you to scope a configuration to a specific path. There is
no inheretance, however; each site configuration is distinct.
Thanks to amazing work by Lucas Clemente, this commit adds experimental
QUIC support. Turn it on using the -quic flag; your browser may have
to be configured to enable it.
Almost everything is here, but you will notice that most of the middle-
ware are missing. After those are transferred over, we'll be ready for
beta tests.
I'm very excited to get this out. Thanks for everyone's help and
patience these last few months. I hope you like it!!
2016-06-04 18:00:29 -05:00
|
|
|
ServerType: "http",
|
|
|
|
Action: setup,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-04-09 00:24:59 -05:00
|
|
|
// Gzip is a middleware type which gzips HTTP responses. It is
|
|
|
|
// imperative that any handler which writes to a gzipped response
|
|
|
|
// specifies the Content-Type, otherwise some clients will assume
|
|
|
|
// application/x-gzip and try to download a file.
|
2015-03-20 19:11:54 -05:00
|
|
|
type Gzip struct {
|
Rewrote Caddy from the ground up; initial commit of 0.9 branch
These changes span work from the last ~4 months in an effort to make
Caddy more extensible, reduce the coupling between its components, and
lay a more robust foundation of code going forward into 1.0. A bunch of
new features have been added, too, with even higher future potential.
The most significant design change is an overall inversion of
dependencies. Instead of the caddy package knowing about the server
and the notion of middleware and config, the caddy package exposes an
interface that other components plug into. This does introduce more
indirection when reading the code, but every piece is very modular and
pluggable. Even the HTTP server is pluggable.
The caddy package has been moved to the top level, and main has been
pushed into a subfolder called caddy. The actual logic of the main
file has been pushed even further into caddy/caddymain/run.go so that
custom builds of Caddy can be 'go get'able.
The HTTPS logic was surgically separated into two parts to divide the
TLS-specific code and the HTTPS-specific code. The caddytls package can
now be used by any type of server that needs TLS, not just HTTP. I also
added the ability to customize nearly every aspect of TLS at the site
level rather than all sites sharing the same TLS configuration. Not all
of this flexibility is exposed in the Caddyfile yet, but it may be in
the future. Caddy can also generate self-signed certificates in memory
for the convenience of a developer working on localhost who wants HTTPS.
And Caddy now supports the DNS challenge, assuming at least one DNS
provider is plugged in.
Dozens, if not hundreds, of other minor changes swept through the code
base as I literally started from an empty main function, copying over
functions or files as needed, then adjusting them to fit in the new
design. Most tests have been restored and adapted to the new API,
but more work is needed there.
A lot of what was "impossible" before is now possible, or can be made
possible with minimal disruption of the code. For example, it's fairly
easy to make plugins hook into another part of the code via callbacks.
Plugins can do more than just be directives; we now have plugins that
customize how the Caddyfile is loaded (useful when you need to get your
configuration from a remote store).
Site addresses no longer need be just a host and port. They can have a
path, allowing you to scope a configuration to a specific path. There is
no inheretance, however; each site configuration is distinct.
Thanks to amazing work by Lucas Clemente, this commit adds experimental
QUIC support. Turn it on using the -quic flag; your browser may have
to be configured to enable it.
Almost everything is here, but you will notice that most of the middle-
ware are missing. After those are transferred over, we'll be ready for
beta tests.
I'm very excited to get this out. Thanks for everyone's help and
patience these last few months. I hope you like it!!
2016-06-04 18:00:29 -05:00
|
|
|
Next httpserver.Handler
|
2015-06-06 18:58:37 -05:00
|
|
|
Configs []Config
|
|
|
|
}
|
|
|
|
|
|
|
|
// Config holds the configuration for Gzip middleware
|
|
|
|
type Config struct {
|
2015-12-07 17:17:05 -05:00
|
|
|
RequestFilters []RequestFilter
|
|
|
|
ResponseFilters []ResponseFilter
|
|
|
|
Level int // Compression level
|
2015-03-20 19:11:54 -05:00
|
|
|
}
|
|
|
|
|
2015-01-30 00:04:18 -05:00
|
|
|
// ServeHTTP serves a gzipped response if the client supports it.
|
2015-03-28 17:47:41 -05:00
|
|
|
func (g Gzip) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
|
2015-01-30 00:04:18 -05:00
|
|
|
if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
|
2015-04-03 00:30:54 -05:00
|
|
|
return g.Next.ServeHTTP(w, r)
|
2015-01-30 00:04:18 -05:00
|
|
|
}
|
2015-06-06 18:58:37 -05:00
|
|
|
outer:
|
|
|
|
for _, c := range g.Configs {
|
|
|
|
|
2015-12-07 17:17:05 -05:00
|
|
|
// Check request filters to determine if gzipping is permitted for this request
|
|
|
|
for _, filter := range c.RequestFilters {
|
2015-06-06 18:58:37 -05:00
|
|
|
if !filter.ShouldCompress(r) {
|
|
|
|
continue outer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-08 06:01:24 -05:00
|
|
|
// gzipWriter modifies underlying writer at init,
|
2015-12-09 12:44:25 -05:00
|
|
|
// use a discard writer instead to leave ResponseWriter in
|
2015-12-08 06:01:24 -05:00
|
|
|
// original form.
|
2015-12-09 12:44:25 -05:00
|
|
|
gzipWriter, err := newWriter(c, ioutil.Discard)
|
2015-06-06 18:58:37 -05:00
|
|
|
if err != nil {
|
|
|
|
// should not happen
|
|
|
|
return http.StatusInternalServerError, err
|
|
|
|
}
|
|
|
|
defer gzipWriter.Close()
|
2015-12-18 14:58:23 -05:00
|
|
|
gz := &gzipResponseWriter{Writer: gzipWriter, ResponseWriter: w}
|
2015-06-06 18:58:37 -05:00
|
|
|
|
2015-12-07 17:17:05 -05:00
|
|
|
var rw http.ResponseWriter
|
|
|
|
// if no response filter is used
|
|
|
|
if len(c.ResponseFilters) == 0 {
|
2015-12-09 12:44:25 -05:00
|
|
|
// replace discard writer with ResponseWriter
|
2015-12-08 06:01:24 -05:00
|
|
|
gzipWriter.Reset(w)
|
2015-12-07 17:17:05 -05:00
|
|
|
rw = gz
|
|
|
|
} else {
|
|
|
|
// wrap gzip writer with ResponseFilterWriter
|
|
|
|
rw = NewResponseFilterWriter(c.ResponseFilters, gz)
|
|
|
|
}
|
|
|
|
|
2015-06-06 18:58:37 -05:00
|
|
|
// Any response in forward middleware will now be compressed
|
2015-12-07 17:17:05 -05:00
|
|
|
status, err := g.Next.ServeHTTP(rw, r)
|
2015-06-06 18:58:37 -05:00
|
|
|
|
|
|
|
// If there was an error that remained unhandled, we need
|
|
|
|
// to send something back before gzipWriter gets closed at
|
|
|
|
// the return of this method!
|
|
|
|
if status >= 400 {
|
Rewrote Caddy from the ground up; initial commit of 0.9 branch
These changes span work from the last ~4 months in an effort to make
Caddy more extensible, reduce the coupling between its components, and
lay a more robust foundation of code going forward into 1.0. A bunch of
new features have been added, too, with even higher future potential.
The most significant design change is an overall inversion of
dependencies. Instead of the caddy package knowing about the server
and the notion of middleware and config, the caddy package exposes an
interface that other components plug into. This does introduce more
indirection when reading the code, but every piece is very modular and
pluggable. Even the HTTP server is pluggable.
The caddy package has been moved to the top level, and main has been
pushed into a subfolder called caddy. The actual logic of the main
file has been pushed even further into caddy/caddymain/run.go so that
custom builds of Caddy can be 'go get'able.
The HTTPS logic was surgically separated into two parts to divide the
TLS-specific code and the HTTPS-specific code. The caddytls package can
now be used by any type of server that needs TLS, not just HTTP. I also
added the ability to customize nearly every aspect of TLS at the site
level rather than all sites sharing the same TLS configuration. Not all
of this flexibility is exposed in the Caddyfile yet, but it may be in
the future. Caddy can also generate self-signed certificates in memory
for the convenience of a developer working on localhost who wants HTTPS.
And Caddy now supports the DNS challenge, assuming at least one DNS
provider is plugged in.
Dozens, if not hundreds, of other minor changes swept through the code
base as I literally started from an empty main function, copying over
functions or files as needed, then adjusting them to fit in the new
design. Most tests have been restored and adapted to the new API,
but more work is needed there.
A lot of what was "impossible" before is now possible, or can be made
possible with minimal disruption of the code. For example, it's fairly
easy to make plugins hook into another part of the code via callbacks.
Plugins can do more than just be directives; we now have plugins that
customize how the Caddyfile is loaded (useful when you need to get your
configuration from a remote store).
Site addresses no longer need be just a host and port. They can have a
path, allowing you to scope a configuration to a specific path. There is
no inheretance, however; each site configuration is distinct.
Thanks to amazing work by Lucas Clemente, this commit adds experimental
QUIC support. Turn it on using the -quic flag; your browser may have
to be configured to enable it.
Almost everything is here, but you will notice that most of the middle-
ware are missing. After those are transferred over, we'll be ready for
beta tests.
I'm very excited to get this out. Thanks for everyone's help and
patience these last few months. I hope you like it!!
2016-06-04 18:00:29 -05:00
|
|
|
httpserver.DefaultErrorFunc(w, r, status)
|
2015-06-06 18:58:37 -05:00
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// no matching filter
|
|
|
|
return g.Next.ServeHTTP(w, r)
|
|
|
|
}
|
|
|
|
|
|
|
|
// newWriter create a new Gzip Writer based on the compression level.
|
|
|
|
// If the level is valid (i.e. between 1 and 9), it uses the level.
|
|
|
|
// Otherwise, it uses default compression level.
|
2015-12-08 06:01:24 -05:00
|
|
|
func newWriter(c Config, w io.Writer) (*gzip.Writer, error) {
|
2015-06-06 18:58:37 -05:00
|
|
|
if c.Level >= gzip.BestSpeed && c.Level <= gzip.BestCompression {
|
|
|
|
return gzip.NewWriterLevel(w, c.Level)
|
2015-04-09 00:24:59 -05:00
|
|
|
}
|
2015-06-06 18:58:37 -05:00
|
|
|
return gzip.NewWriter(w), nil
|
2015-01-30 00:04:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// gzipResponeWriter wraps the underlying Write method
|
|
|
|
// with a gzip.Writer to compress the output.
|
|
|
|
type gzipResponseWriter struct {
|
|
|
|
io.Writer
|
|
|
|
http.ResponseWriter
|
2015-12-18 14:58:23 -05:00
|
|
|
statusCodeWritten bool
|
2015-01-30 00:04:18 -05:00
|
|
|
}
|
|
|
|
|
2015-05-02 10:20:39 -05:00
|
|
|
// WriteHeader wraps the underlying WriteHeader method to prevent
|
|
|
|
// problems with conflicting headers from proxied backends. For
|
|
|
|
// example, a backend system that calculates Content-Length would
|
|
|
|
// be wrong because it doesn't know it's being gzipped.
|
2015-12-18 14:58:23 -05:00
|
|
|
func (w *gzipResponseWriter) WriteHeader(code int) {
|
2015-05-02 10:20:39 -05:00
|
|
|
w.Header().Del("Content-Length")
|
2015-12-08 06:01:24 -05:00
|
|
|
w.Header().Set("Content-Encoding", "gzip")
|
2015-12-15 10:56:44 -05:00
|
|
|
w.Header().Add("Vary", "Accept-Encoding")
|
2015-05-02 10:20:39 -05:00
|
|
|
w.ResponseWriter.WriteHeader(code)
|
2015-12-18 14:58:23 -05:00
|
|
|
w.statusCodeWritten = true
|
2015-05-02 10:20:39 -05:00
|
|
|
}
|
|
|
|
|
2015-01-30 00:04:18 -05:00
|
|
|
// Write wraps the underlying Write method to do compression.
|
2015-12-18 14:58:23 -05:00
|
|
|
func (w *gzipResponseWriter) Write(b []byte) (int, error) {
|
2015-01-30 00:04:18 -05:00
|
|
|
if w.Header().Get("Content-Type") == "" {
|
|
|
|
w.Header().Set("Content-Type", http.DetectContentType(b))
|
|
|
|
}
|
2016-01-12 06:26:37 -05:00
|
|
|
if !w.statusCodeWritten {
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
}
|
2015-01-30 00:04:18 -05:00
|
|
|
n, err := w.Writer.Write(b)
|
|
|
|
return n, err
|
|
|
|
}
|
2016-02-24 14:23:15 -05:00
|
|
|
|
|
|
|
// Hijack implements http.Hijacker. It simply wraps the underlying
|
|
|
|
// ResponseWriter's Hijack method if there is one, or returns an error.
|
|
|
|
func (w *gzipResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
|
|
|
if hj, ok := w.ResponseWriter.(http.Hijacker); ok {
|
|
|
|
return hj.Hijack()
|
|
|
|
}
|
2016-10-10 21:15:33 -05:00
|
|
|
return nil, nil, httpserver.NonHijackerError{Underlying: w.ResponseWriter}
|
2016-02-24 14:23:15 -05:00
|
|
|
}
|
2016-04-10 23:16:41 -05:00
|
|
|
|
2016-04-11 01:24:26 -05:00
|
|
|
// Flush implements http.Flusher. It simply wraps the underlying
|
|
|
|
// ResponseWriter's Flush method if there is one, or panics.
|
|
|
|
func (w *gzipResponseWriter) Flush() {
|
|
|
|
if f, ok := w.ResponseWriter.(http.Flusher); ok {
|
|
|
|
f.Flush()
|
|
|
|
} else {
|
2016-10-10 21:15:33 -05:00
|
|
|
panic(httpserver.NonFlusherError{Underlying: w.ResponseWriter}) // should be recovered at the beginning of middleware stack
|
2016-04-11 01:24:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-10 23:16:41 -05:00
|
|
|
// CloseNotify implements http.CloseNotifier.
|
|
|
|
// It just inherits the underlying ResponseWriter's CloseNotify method.
|
|
|
|
func (w *gzipResponseWriter) CloseNotify() <-chan bool {
|
|
|
|
if cn, ok := w.ResponseWriter.(http.CloseNotifier); ok {
|
|
|
|
return cn.CloseNotify()
|
|
|
|
}
|
2016-10-10 21:15:33 -05:00
|
|
|
panic(httpserver.NonCloseNotifierError{Underlying: w.ResponseWriter})
|
2016-04-10 23:16:41 -05:00
|
|
|
}
|
2017-02-17 11:25:22 -05:00
|
|
|
|
|
|
|
func (w *gzipResponseWriter) Push(target string, opts *http.PushOptions) error {
|
|
|
|
if pusher, hasPusher := w.ResponseWriter.(http.Pusher); hasPusher {
|
|
|
|
return pusher.Push(target, opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors.New("push is unavailable (probably chained http.ResponseWriter does not implement http.Pusher)")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Interface guards
|
|
|
|
var _ http.Pusher = (*gzipResponseWriter)(nil)
|
|
|
|
var _ http.Flusher = (*gzipResponseWriter)(nil)
|
|
|
|
var _ http.CloseNotifier = (*gzipResponseWriter)(nil)
|
|
|
|
var _ http.Hijacker = (*gzipResponseWriter)(nil)
|