Skip to content

feat: gzip static http server assets #2272

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

Merged
merged 4 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 3 additions & 1 deletion coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync"
"time"

"github.com/NYTimes/gziphandler"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/pion/webrtc/v3"
Expand Down Expand Up @@ -350,7 +351,8 @@ func New(options *Options) *API {
r.Get("/state", api.workspaceBuildState)
})
})
r.NotFound(api.siteHandler.ServeHTTP)

r.NotFound(gziphandler.GzipHandler(http.HandlerFunc(api.siteHandler.ServeHTTP)).ServeHTTP)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to prefer gziphandler vs chi/middleware.Compress here? The Chi one also supports deflate. (I think it would be nice to support all of: deflate, gzip and br (brotli), but chi does not handle br.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that one looks better!

return api
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ require (
cdr.dev/slog v1.4.2-0.20220525200111-18dce5c2cd5f
cloud.google.com/go/compute v1.6.1
github.com/AlecAivazis/survey/v2 v2.3.4
github.com/NYTimes/gziphandler v1.1.1
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2
github.com/awalterschulze/gographviz v2.0.3+incompatible
github.com/bgentry/speakeasy v0.1.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ github.com/Microsoft/hcsshim v0.9.2/go.mod h1:7pLA8lDk46WKDWlVsENo92gC0XFa8rbKfy
github.com/Microsoft/hcsshim/test v0.0.0-20201218223536-d3e5debf77da/go.mod h1:5hlzMzRKMLyo42nCZ9oml8AdTlq/0cvIaBv6tK1RehU=
github.com/Microsoft/hcsshim/test v0.0.0-20210227013316-43a75bb4edd3/go.mod h1:mw7qgWloBUl75W/gVH3cQszUg1+gUITj7D6NY7ywVnY=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
Expand Down
4 changes: 2 additions & 2 deletions provisionersdk/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set -eux pipefail
BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXXX)/coder
BINARY_URL=${ACCESS_URL}bin/coder-linux-${ARCH}
if which curl >/dev/null 2>&1; then
curl -fsSL "${BINARY_URL}" -o "${BINARY_LOCATION}"
curl -fsSL --compressed "${BINARY_URL}" -o "${BINARY_LOCATION}"
elif which wget >/dev/null 2>&1; then
wget -q "${BINARY_URL}" -O "${BINARY_LOCATION}"
elif which busybox >/dev/null 2>&1; then
Expand All @@ -38,7 +38,7 @@ exec $BINARY_LOCATION agent`
darwinScript = `#!/usr/bin/env sh
set -eux pipefail
BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXXX)/coder
curl -fsSL "${ACCESS_URL}bin/coder-darwin-${ARCH}" -o "${BINARY_LOCATION}"
curl -fsSL --compressed "${ACCESS_URL}bin/coder-darwin-${ARCH}" -o "${BINARY_LOCATION}"
chmod +x $BINARY_LOCATION
export CODER_AGENT_AUTH="${AUTH_TYPE}"
export CODER_AGENT_URL="${ACCESS_URL}"
Expand Down