detached b485310

fix: increase read & write server timeouts

commit
b4853100dac6e9615904543f5ff5f6d30eab5d25
author
bnema · · 2024-04-21 01:50 UTC
parent
dac92ca
signature
unsigned
2 files · +19 -9
M internal/cli/handler/startserver.go +3 -0
@@ -6,6 +6,7 @@ import (
66 "os"
77 "os/signal"
88 "syscall"
9+ "time"
910
1011 "github.com/bnema/gordon/internal/httpserve"
1112 "github.com/bnema/gordon/internal/server"
@@ -39,6 +40,8 @@ func StartServer(a *server.App, port string) error {
3940 }()
4041
4142 e := echo.New()
43+ e.Server.ReadTimeout = 10 * time.Minute
44+ e.Server.WriteTimeout = 10 * time.Minute
4245 e.HideBanner = true
4346 e.HidePort = true
4447 e = httpserve.RegisterRoutes(e, a)
@@ -6,6 +6,7 @@ import (
6 "os"6 "os"
7 "os/signal"7 "os/signal"
8 "syscall"8 "syscall"
9+ "time"
9 10
10 "github.com/bnema/gordon/internal/httpserve"11 "github.com/bnema/gordon/internal/httpserve"
11 "github.com/bnema/gordon/internal/server"12 "github.com/bnema/gordon/internal/server"
@@ -39,6 +40,8 @@ func StartServer(a *server.App, port string) error {
39 }()40 }()
40 41
41 e := echo.New()42 e := echo.New()
43+ e.Server.ReadTimeout = 10 * time.Minute
44+ e.Server.WriteTimeout = 10 * time.Minute
42 e.HideBanner = true45 e.HideBanner = true
43 e.HidePort = true46 e.HidePort = true
44 e = httpserve.RegisterRoutes(e, a)47 e = httpserve.RegisterRoutes(e, a)
M internal/httpserve/handler/uploadcontainerimage.go +16 -9
@@ -38,19 +38,26 @@ func UploadImageGETHandler(c echo.Context, a *server.App) error {
3838 func UploadImagePOSTHandler(c echo.Context, a *server.App) error {
3939 // Set upload size limit
4040 c.Request().Body = http.MaxBytesReader(c.Response(), c.Request().Body, MaxUploadSize)
41- if err := c.Request().ParseMultipartForm(MaxUploadSize); err != nil {
42- return c.String(http.StatusRequestEntityTooLarge, "File size exceeded")
41+
42+ // Parse the multipart form
43+ form, err := c.MultipartForm()
44+ if err != nil {
45+ return sendError(c, err)
4346 }
4447
4548 // Get the file from the form
46- file, header, err := c.Request().FormFile("file")
49+ files := form.File["file"]
50+ if len(files) == 0 {
51+ return c.String(http.StatusBadRequest, "No file uploaded")
52+ }
53+ file := files[0]
54+
55+ // Open the file
56+ src, err := file.Open()
4757 if err != nil {
4858 return sendError(c, err)
4959 }
50- defer file.Close()
51-
52- // Get the filename
53- filename := header.Filename
60+ defer src.Close()
5461
5562 // Create a temporary file to store the uploaded chunks
5663 tempFile, err := os.CreateTemp("", "upload-*")
@@ -60,7 +67,7 @@ func UploadImagePOSTHandler(c echo.Context, a *server.App) error {
6067 defer tempFile.Close()
6168
6269 // Copy the file chunks to the temporary file
63- _, err = io.Copy(tempFile, file)
70+ _, err = io.Copy(tempFile, src)
6471 if err != nil {
6572 return sendError(c, err)
6673 }
@@ -72,7 +79,7 @@ func UploadImagePOSTHandler(c echo.Context, a *server.App) error {
7279 }
7380
7481 // Save the image to the storage directory
75- saveInPath, err := store.SaveImageToStorage(&a.Config, filename, tempFile)
82+ saveInPath, err := store.SaveImageToStorage(&a.Config, file.Filename, tempFile)
7683 if err != nil {
7784 return sendError(c, err)
7885 }
@@ -38,19 +38,26 @@ func UploadImageGETHandler(c echo.Context, a *server.App) error {
38 func UploadImagePOSTHandler(c echo.Context, a *server.App) error {38 func UploadImagePOSTHandler(c echo.Context, a *server.App) error {
39 // Set upload size limit39 // Set upload size limit
40 c.Request().Body = http.MaxBytesReader(c.Response(), c.Request().Body, MaxUploadSize)40 c.Request().Body = http.MaxBytesReader(c.Response(), c.Request().Body, MaxUploadSize)
41- if err := c.Request().ParseMultipartForm(MaxUploadSize); err != nil {41+
42- return c.String(http.StatusRequestEntityTooLarge, "File size exceeded")42+ // Parse the multipart form
43+ form, err := c.MultipartForm()
44+ if err != nil {
45+ return sendError(c, err)
43 }46 }
44 47
45 // Get the file from the form48 // Get the file from the form
46- file, header, err := c.Request().FormFile("file")49+ files := form.File["file"]
50+ if len(files) == 0 {
51+ return c.String(http.StatusBadRequest, "No file uploaded")
52+ }
53+ file := files[0]
54+
55+ // Open the file
56+ src, err := file.Open()
47 if err != nil {57 if err != nil {
48 return sendError(c, err)58 return sendError(c, err)
49 }59 }
50- defer file.Close()60+ defer src.Close()
51-
52- // Get the filename
53- filename := header.Filename
54 61
55 // Create a temporary file to store the uploaded chunks62 // Create a temporary file to store the uploaded chunks
56 tempFile, err := os.CreateTemp("", "upload-*")63 tempFile, err := os.CreateTemp("", "upload-*")
@@ -60,7 +67,7 @@ func UploadImagePOSTHandler(c echo.Context, a *server.App) error {
60 defer tempFile.Close()67 defer tempFile.Close()
61 68
62 // Copy the file chunks to the temporary file69 // Copy the file chunks to the temporary file
63- _, err = io.Copy(tempFile, file)70+ _, err = io.Copy(tempFile, src)
64 if err != nil {71 if err != nil {
65 return sendError(c, err)72 return sendError(c, err)
66 }73 }
@@ -72,7 +79,7 @@ func UploadImagePOSTHandler(c echo.Context, a *server.App) error {
72 }79 }
73 80
74 // Save the image to the storage directory81 // Save the image to the storage directory
75- saveInPath, err := store.SaveImageToStorage(&a.Config, filename, tempFile)82+ saveInPath, err := store.SaveImageToStorage(&a.Config, file.Filename, tempFile)
76 if err != nil {83 if err != nil {
77 return sendError(c, err)84 return sendError(c, err)
78 }85 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close