-
-
Notifications
You must be signed in to change notification settings - Fork 733
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
How can I manually configure *resty.Request.RawRequest.ContentLength? #971
Comments
Typically, net/http will also automatically set req.ContentLength, but this is limited to when the body type is *bytes.Buffer, *bytes.Reader, or *strings.Reader.
|
@BoneAsh Thanks for trying out v3 and sharing your feedback.
This is true for Resty v3 Regarding the Content-Length value, I will validate the resty v3 and get back to you. |
@BoneAsh, I’ve identified the root cause. It’s a side effect of removing the v2 flow. I’ll add the new content-length flow for explicit setting of a value. Once ready, you could try the branch before I create a PR. |
@BoneAsh The implementation is available in this branch |
ok, I will try it out. |
This issue has been fixed. I used the Resty library to call the PUT method to upload file slices to MinIO, and the body uses my own implementation of *io.Reader. The Content-Length value is already set in the headers. Thank you very much! You can merge this modification into the main branch of version 3. @jeevatkm |
@BoneAsh Thanks for the feedback. I need to do some final touches before the PR creation. |
@jeevatkm I found that when the body is multipart/form-data, the Content-Length is still problematic. I pinpointed the code at line 219 in middleware.go, where r.Body is nil, so the Content-Length is set directly to 0. However, at this point, the data is in r.bodyBuf, and this code is not executed. Moreover, the length of the body cannot be calculated from the outside because the boundary is generated by the Resty package itself. So please check if there is a logical issue here.
|
I am not sure if there are cases where both r.Body and r.bodyBuf have values, so please conduct compatibility tests for all body types and combinations, such as |
I just realized that when the body is multipart/form-data, it is not possible to set the Content-Length using the SetContentLength method. However, this is indeed correct; the length should be calculated by Resty. |
@BoneAsh I'm in the process of further testing since your last feedback. FYI, Resty v3 by default does streaming for multipart upload cases, so when streaming happens Resty cannot figure out the content length, so it is |
go 1.23.6
resty v3
I tested it using the net/http package, and when I send an HTTP request with the body as an io.Reader type, setting the Content-Length in the header does not work. I need to set req.ContentLength directly.
util.MyReader is a custom struct that implements the io.Reader interface, specifically the Read(p []byte) (n int, err error) method.
The text was updated successfully, but these errors were encountered: