Skip to content

Modern Docker Management, Designed for Everyone

fix: remove gzip middleware from agent endpoints (#2627)

Kyle Mendelle2b528fd8239
diff --git a/backend/internal/bootstrap/bootstrap_test.go b/backend/internal/bootstrap/bootstrap_test.go
index 58b1d5beb..1d883bf21 100644
--- a/backend/internal/bootstrap/bootstrap_test.go
+++ b/backend/internal/bootstrap/bootstrap_test.go
@@ -2,15 +2,21 @@ package bootstrap
import (
"context"
+ "crypto/tls"
+ "io"
+ "net"
"net/http"
"net/http/httptest"
+ "strconv"
"testing"
+ "time"
"github.com/getarcaneapp/arcane/backend/internal/config"
libcrypto "github.com/getarcaneapp/arcane/backend/pkg/libarcane/crypto"
tunnelpb "github.com/getarcaneapp/arcane/backend/pkg/libarcane/edge/proto/tunnel/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "golang.org/x/net/http2"
)
func TestNormalizeTunnelGRPCRequestPathInternal(t *testing.T) {
@@ -143,6 +149,65 @@ func TestConfigureHTTPProtocolsInternal(t *testing.T) {
})
}
+func TestHTTP2APIResponsesDoNotUseAPIGzipInternal(t *testing.T) {
+ router, _ := setupRouter(context.Background(), &config.Config{
+ AppUrl: "http://localhost:3552",
+ Environment: config.AppEnvironmentTest,
+ }, &Services{})
+ handler, protocols := configureHTTPProtocolsInternal(false, router)
+
+ listener, err := net.Listen("tcp", "127.0.0.1:0")
+ require.NoError(t, err)
+
+ server := &http.Server{
+ Handler: handler,
+ Protocols: protocols,
+ ReadHeaderTimeout: 5 * time.Second,
+ }
+ errCh := make(chan error, 1)
+ go func() {
+ errCh <- server.Serve(listener)
+ }()
+ t.Cleanup(func() {
+ require.NoError(t, server.Shutdown(context.Background()))
+ require.ErrorIs(t, <-errCh, http.ErrServerClosed)
+ })
+
+ transport := &http2.Transport{
+ AllowHTTP: true,
+ DisableCompression: true,
+ DialTLSContext: func(ctx context.Context, network, addr string, _ *tls.Config) (net.Conn, error) {
+ return (&net.Dialer{}).DialContext(ctx, network, addr)
+ },
+ }
+ client := &http.Client{Transport: transport}
+
+ for _, path := range []string{"/api/health", "/api/openapi.json"} {
+ t.Run(path, func(t *testing.T) {
+ req, err := http.NewRequest(http.MethodGet, "http://"+listener.Addr().String()+path, nil)
+ require.NoError(t, err)
+ req.Header.Set("Accept-Encoding", "gzip")
+
+ resp, err := client.Do(req)
+ require.NoError(t, err)
+ defer func() { _ = resp.Body.Close() }()
+
+ body, err := io.ReadAll(resp.Body)
+ require.NoError(t, err)
+
+ require.Equal(t, "HTTP/2.0", resp.Proto)
+ require.Equal(t, http.StatusOK, resp.StatusCode)
+ require.Empty(t, resp.Header.Get("Content-Encoding"))
+
+ if contentLength := resp.Header.Get("Content-Length"); contentLength != "" {
+ parsedLength, parseErr := strconv.Atoi(contentLength)
+ require.NoError(t, parseErr)
+ require.Equal(t, len(body), parsedLength)
+ }
+ })
+ }
+}
+
func TestPrepareServerTLSInternal_AgentModeSkipsManagerMTLSValidation(t *testing.T) {
cfg := &config.Config{
AgentMode: true,
diff --git a/backend/internal/bootstrap/router_bootstrap.go b/backend/internal/bootstrap/router_bootstrap.go
index 1a86f39f6..3f0c540e5 100644
--- a/backend/internal/bootstrap/router_bootstrap.go
+++ b/backend/internal/bootstrap/router_bootstrap.go
@@ -153,16 +153,6 @@ func setupRouter(ctx context.Context, cfg *config.Config, appServices *Services)
e.Use(middleware.NewCORSMiddleware(cfg).Add())
apiGroup := e.Group("/api")
- apiGroup.Use(echomiddleware.GzipWithConfig(echomiddleware.GzipConfig{
- Level: 5,
- Skipper: func(c echo.Context) bool {
- if strings.EqualFold(c.Request().Header.Get(echo.HeaderUpgrade), "websocket") {
- return true
- }
- path := c.Request().URL.Path
- return strings.Contains(path, "/ws/") || strings.Contains(path, "/logs") || strings.Contains(path, "/terminal")
- },
- }))
apiGroup.Use(middleware.PerIPRateLimitForPaths(
[]string{
diff --git a/backend/pkg/libarcane/edge/remenv.go b/backend/pkg/libarcane/edge/remenv.go
index 102f1c542..5ed8a8c25 100644
--- a/backend/pkg/libarcane/edge/remenv.go
+++ b/backend/pkg/libarcane/edge/remenv.go
@@ -164,7 +164,7 @@ func GetSkipHeaders() map[string]struct{} {
return map[string]struct{}{
"Host": {}, "Connection": {}, "Keep-Alive": {}, "Proxy-Authenticate": {},
"Proxy-Authorization": {}, "Te": {}, "Trailer": {}, "Transfer-Encoding": {},
- "Upgrade": {}, "Content-Length": {}, "Origin": {}, "Referer": {},
+ "Upgrade": {}, "Content-Length": {}, "Accept-Encoding": {}, "Origin": {}, "Referer": {},
"Access-Control-Request-Method": {}, "Access-Control-Request-Headers": {}, "Cookie": {},
}
}
diff --git a/backend/pkg/libarcane/edge/remenv_test.go b/backend/pkg/libarcane/edge/remenv_test.go
index da6235062..b3860b167 100644
--- a/backend/pkg/libarcane/edge/remenv_test.go
+++ b/backend/pkg/libarcane/edge/remenv_test.go
@@ -185,6 +185,7 @@ func TestGetSkipHeaders_ContainsExpectedEntries(t *testing.T) {
require.Contains(t, skip, "Transfer-Encoding")
require.Contains(t, skip, "Upgrade")
require.Contains(t, skip, "Content-Length")
+ require.Contains(t, skip, "Accept-Encoding")
require.Contains(t, skip, "Cookie")
require.Contains(t, skip, "Origin")
require.Contains(t, skip, "Referer")