Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Bug Fixes

* Apply the configured ACME issuer settings and use the same configuration for certificate renewal.
* Remove multipart temp files when the request fails to parse.

## [6.1.0](https://github.com/roadrunner-server/http/compare/v6.0.0...v6.1.0) (2026-10-16)

Expand Down
48 changes: 48 additions & 0 deletions handler/handler_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package handler

import (
"bytes"
"context"
"crypto/tls"
"fmt"
"mime/multipart"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -104,6 +106,52 @@ func TestServeHTTP_TruncatedMultipart_Returns400(t *testing.T) {
}
}

func TestServeHTTP_MultipartTreeConflict_RemovesTempFiles(t *testing.T) {
tmp := t.TempDir()
// multipart.Reader writes file parts past defaultMaxMemory to os.TempDir().
t.Setenv("TMPDIR", tmp)

// "a" and "a[b]" conflict in the upload tree, so parseUploads fails after the spill.
var body bytes.Buffer
mw := multipart.NewWriter(&body)
for _, part := range []struct {
name string
size int
}{
{name: "a", size: 1},
{name: "a[b]", size: defaultMaxMemory + 1},
} {
fw, err := mw.CreateFormFile(part.name, "f.bin")
if err != nil {
t.Fatal(err)
}
if _, err = fw.Write(bytes.Repeat([]byte("x"), part.size)); err != nil {
t.Fatal(err)
}
}
if err := mw.Close(); err != nil {
t.Fatal(err)
}

h := newTestHandler(t, defaultCfg(), nil)
req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/", &body)
req.Header.Set("Content-Type", mw.FormDataContentType())

rr := httptest.NewRecorder()
h.ServeHTTP(rr, req)

if rr.Code != http.StatusBadRequest {
t.Fatalf("expected 400, got %d", rr.Code)
}
left, err := os.ReadDir(tmp)
if err != nil {
t.Fatal(err)
}
if len(left) != 0 {
t.Errorf("expected no temp files, got %d", len(left))
}
}

// ── Group B: Direct calls to handleError, URI, FetchIP ───────────────────────

func TestHandleError_NoFreeWorkers_SetsNoWorkersHeader(t *testing.T) {
Expand Down
8 changes: 5 additions & 3 deletions handler/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,16 @@ func (r *Request) Open(log *slog.Logger, dir string, forbid, allow map[string]st

// Close clears all temp file uploads
func (r *Request) Close(log *slog.Logger, hr *http.Request) {
// The HTTP/3 and FastCGI servers do not remove multipart temp files after the handler returns.
if hr.MultipartForm != nil {
_ = hr.MultipartForm.RemoveAll()
}

if r.Uploads == nil {
return
}

r.Uploads.Clear(log)
if hr.MultipartForm != nil {
_ = hr.MultipartForm.RemoveAll()
}
}

// Payload request marshaled RoadRunner payload based on PSR7 data. values encode method is JSON. Make sure to open
Expand Down
Loading