Skip to content

Commit

Permalink
support *os.File in request param
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Sep 25, 2018
1 parent 293bdc8 commit bc0679a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions req.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,17 @@ func setContentType(req *http.Request, contentType string) {

func setBodyReader(req *http.Request, resp *Resp, rd io.Reader) func() {
var rc io.ReadCloser
if trc, ok := rd.(io.ReadCloser); ok {
rc = trc
} else {
switch r := rd.(type) {
case *os.File:
stat, err := r.Stat()
if err == nil {
req.ContentLength = stat.Size()
}
rc = r

case io.ReadCloser:
rc = r
default:
rc = ioutil.NopCloser(rd)
}
bw := &bodyWrapper{
Expand Down

0 comments on commit bc0679a

Please sign in to comment.