Skip to content

Commit

Permalink
handle EOF when detect content type
Browse files Browse the repository at this point in the history
  • Loading branch information
stingshen authored and casualjim committed Dec 9, 2023
1 parent 7c81d43 commit 5adaa35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (r *request) buildHTTP(mediaType, basePath string, producers map[string]run
// Need to read the data so that we can detect the content type
buf := make([]byte, 512)
size, err := fi.Read(buf)
if err != nil {
if err != nil && err != io.EOF {
logClose(err, pw)
return
}
Expand Down
6 changes: 5 additions & 1 deletion client/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,14 @@ func TestBuildRequest_BuildHTTP_Files(t *testing.T) {
require.NoError(t, err)
cont2, err := os.ReadFile("./request.go")
require.NoError(t, err)
emptyFile, err := os.CreateTemp("", "empty")
require.NoError(t, err)

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

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

//nolint:dupl
Expand Down

0 comments on commit 5adaa35

Please sign in to comment.