Skip to content

Commit 2c1d3d6

Browse files
committed
export HTTPFileMaxBytes, reference in cli test
1 parent 33860ae commit 2c1d3d6

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

cli/templatepull_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
"github.com/coder/coder/v2/archive"
1717
"github.com/coder/coder/v2/cli/clitest"
18+
"github.com/coder/coder/v2/coderd"
1819
"github.com/coder/coder/v2/coderd/coderdtest"
1920
"github.com/coder/coder/v2/coderd/rbac"
2021
"github.com/coder/coder/v2/provisioner/echo"
@@ -95,7 +96,7 @@ func TestTemplatePull_Stdout(t *testing.T) {
9596

9697
// Verify .zip format
9798
tarReader := tar.NewReader(bytes.NewReader(expected))
98-
expectedZip, err := archive.CreateZipFromTar(tarReader, int64(len(expected)))
99+
expectedZip, err := archive.CreateZipFromTar(tarReader, coderd.HTTPFileMaxBytes)
99100
require.NoError(t, err)
100101

101102
inv, root = clitest.New(t, "templates", "pull", "--zip", template.Name)

coderd/files.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const (
2828
tarMimeType = "application/x-tar"
2929
zipMimeType = "application/zip"
3030

31-
httpFileMaxBytes = 10 * (10 << 20)
31+
HTTPFileMaxBytes = 10 * (10 << 20)
3232
)
3333

3434
// @Summary Upload file
@@ -56,7 +56,7 @@ func (api *API) postFile(rw http.ResponseWriter, r *http.Request) {
5656
return
5757
}
5858

59-
r.Body = http.MaxBytesReader(rw, r.Body, httpFileMaxBytes)
59+
r.Body = http.MaxBytesReader(rw, r.Body, HTTPFileMaxBytes)
6060
data, err := io.ReadAll(r.Body)
6161
if err != nil {
6262
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
@@ -76,7 +76,7 @@ func (api *API) postFile(rw http.ResponseWriter, r *http.Request) {
7676
return
7777
}
7878

79-
data, err = archive.CreateTarFromZip(zipReader, httpFileMaxBytes)
79+
data, err = archive.CreateTarFromZip(zipReader, HTTPFileMaxBytes)
8080
if err != nil {
8181
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
8282
Message: "Internal error processing .zip archive.",
@@ -182,7 +182,7 @@ func (api *API) fileByID(rw http.ResponseWriter, r *http.Request) {
182182

183183
rw.Header().Set("Content-Type", codersdk.ContentTypeZip)
184184
rw.WriteHeader(http.StatusOK)
185-
err = archive.WriteZip(rw, tar.NewReader(bytes.NewReader(file.Data)), httpFileMaxBytes)
185+
err = archive.WriteZip(rw, tar.NewReader(bytes.NewReader(file.Data)), HTTPFileMaxBytes)
186186
if err != nil {
187187
api.Logger.Error(ctx, "invalid .zip archive", slog.F("file_id", fileID), slog.F("mimetype", file.Mimetype), slog.Error(err))
188188
}

0 commit comments

Comments
 (0)