Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for compression in http api #3752

Merged
merged 1 commit into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions agent/agent_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,10 @@ func (s *HTTPServer) AgentMonitor(resp http.ResponseWriter, req *http.Request) (

// Send header so client can start streaming body
resp.WriteHeader(http.StatusOK)

// 0 byte write is needed before the Flush call so that if we are using
// a gzip stream it will go ahead and write out the HTTP response header
resp.Write([]byte(""))
flusher.Flush()

// Stream logs until the connection is closed.
Expand Down
7 changes: 6 additions & 1 deletion agent/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/go-cleanhttp"
"github.com/mitchellh/mapstructure"
"github.com/NYTimes/gziphandler"
)

// MethodNotAllowedError should be returned by a handler when the HTTP method is not allowed.
Expand Down Expand Up @@ -64,6 +65,7 @@ func registerEndpoint(pattern string, methods []string, fn unboundEndpoint) {
if endpoints[pattern] != nil || allowedMethods[pattern] != nil {
panic(fmt.Errorf("Pattern %q is already registered", pattern))
}

endpoints[pattern] = fn
allowedMethods[pattern] = methods
}
Expand Down Expand Up @@ -111,7 +113,10 @@ func (s *HTTPServer) handler(enableDebug bool) http.Handler {
metrics.MeasureSince(append([]string{"consul"}, key...), start)
metrics.MeasureSince(key, start)
}
mux.HandleFunc(pattern, wrapper)

gzipWrapper, _ := gziphandler.GzipHandlerWithOpts(gziphandler.MinSize(0))
gzipHandler := gzipWrapper(http.HandlerFunc(wrapper))
mux.Handle(pattern, gzipHandler)
}

mux.HandleFunc("/", s.Index)
Expand Down
201 changes: 201 additions & 0 deletions vendor/github.com/NYTimes/gziphandler/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions vendor/github.com/NYTimes/gziphandler/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading