Error with 400 Bad Request when both 'file' and 'shorten' set #65

Merged
electricdusk merged 2 commits from issue-56 into master 2020-07-06 17:14:40 +02:00
Showing only changes of commit 70538f170f - Show all commits

View File

@ -159,3 +159,26 @@ func TestIssue60(t *testing.T) {
srv.ServeHTTP(rr, req) srv.ServeHTTP(rr, req)
checkStatusCode(t, rr, http.StatusNotFound) checkStatusCode(t, rr, http.StatusNotFound)
} }
func TestIssue56(t *testing.T) {
srv, _ := createTemporaryRouter(t)
// Make a POST request with both a 'file' *and* a 'shorten' part.
var body bytes.Buffer
form := multipart.NewWriter(&body)
if _, err := form.CreateFormFile("file", "empty.txt"); err != nil {
t.Fatal(err)
}
if _, err := form.CreateFormField("shorten"); err != nil {
t.Fatal(err)
}
form.Close()
req, err := http.NewRequest("POST", "/", bytes.NewReader(body.Bytes()))
if err != nil {
t.Fatal(err)
}
req.Header.Add("Content-Type", form.FormDataContentType())
rr := httptest.NewRecorder()
srv.ServeHTTP(rr, req)
checkStatusCode(t, rr, http.StatusBadRequest)
}