-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
To wrap the closer as a nop for request body #7
To wrap the closer as a nop for request body #7
Conversation
Signed-off-by: jojohappy <[email protected]>
3 similar comments
@jojohappy Thanks for your PR! 听起来似乎是可以在传入参数前用 |
@mozillazg 好的,谢谢。不过这样做的初衷是希望对用户透明,让用户不用去关心接口以外的内容。 |
@jojohappy req.body 自动 close 是为了防止出现资源泄露,如果直接用 |
@mozillazg 谢谢你的回复,我同意你的说法。这个 PR 的目的是针对类似 |
@jojohappy 后来又想了一下,修改位置的 body 主要是用于上传文件的场景下,你的修改确实是比较合理的考虑。 |
@mozillazg 非常感谢~ 如果后续需要做改进,可以再联系我~ |
Signed-off-by: jojohappy [email protected]
变更:
由于 Golang 的
net/http
包在做client.Do(req)
时默认会调用req.Body.Close()
, 如果我们上传的Object
是文件时,文件句柄将会被关闭,这样就没有办法在外部程序复用这个文件句柄,同时会有file already closed
的错误发生。这里的修改尝试在
io.Reader
外面再封装一个NopCloser
,默认Close()
返回nil
。对于文件句柄的关闭操作应当由调用方来处理。