Skip to content

Commit 5adaa35

Browse files
stingshencasualjim
authored andcommitted
handle EOF when detect content type
1 parent 7c81d43 commit 5adaa35

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

client/request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (r *request) buildHTTP(mediaType, basePath string, producers map[string]run
171171
// Need to read the data so that we can detect the content type
172172
buf := make([]byte, 512)
173173
size, err := fi.Read(buf)
174-
if err != nil {
174+
if err != nil && err != io.EOF {
175175
logClose(err, pw)
176176
return
177177
}

client/request_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,14 @@ func TestBuildRequest_BuildHTTP_Files(t *testing.T) {
426426
require.NoError(t, err)
427427
cont2, err := os.ReadFile("./request.go")
428428
require.NoError(t, err)
429+
emptyFile, err := os.CreateTemp("", "empty")
430+
require.NoError(t, err)
429431

430-
reqWrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, _ strfmt.Registry) error {
432+
reqWrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, reg strfmt.Registry) error {
431433
_ = req.SetFormParam("something", "some value")
432434
_ = req.SetFileParam("file", mustGetFile("./runtime.go"))
433435
_ = req.SetFileParam("otherfiles", mustGetFile("./runtime.go"), mustGetFile("./request.go"))
436+
_ = req.SetFileParam("empty", emptyFile)
434437
_ = req.SetQueryParam("hello", "world")
435438
_ = req.SetPathParam("id", "1234")
436439
_ = req.SetHeaderParam("X-Rate-Limit", "200")
@@ -472,6 +475,7 @@ func TestBuildRequest_BuildHTTP_Files(t *testing.T) {
472475

473476
fileverifier("otherfiles", 0, "runtime.go", cont)
474477
fileverifier("otherfiles", 1, "request.go", cont2)
478+
fileverifier("empty", 0, filepath.Base(emptyFile.Name()), []byte{})
475479
}
476480

477481
//nolint:dupl

0 commit comments

Comments
 (0)