-
Notifications
You must be signed in to change notification settings - Fork 284
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
Added basic support for multi-part form uploads in HTTPClient #1178
base: master
Are you sure you want to change the base?
Conversation
Any comments on the interface for this in general? Should I make the headers editable after the object is created? |
fix add sibling fix add sibling
@@ -599,6 +599,18 @@ final class HTTPClientRequest : HTTPRequest { | |||
finalize(); | |||
} | |||
|
|||
/// Writes a multipart upload as a body to the request. This must be written in its entirety because the Content-Length | |||
/// must be known beforehand. | |||
/// Usage: req.writeBody(new FileMultiPart(req.headers, "Photo", "images/picture.jpg")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be reformatted to be rendered properly in the documentation:
/** Writes a multipart form as a body to the request.
This must be written in its entirety because the Content-Length
must be known beforehand.
Usage: `req.writeBody(new FileMultiPart(req.headers, "Photo", "images/picture.jpg"));`
*/
Ideal would be to put the example into a documented unit test to verify that it doesn't get out of date.
Instead of putting the headers (and string data) into |
I think the headers need to be kept aside until being written because the multipart forms were designed like linked lists and can be nested, and the content-length needs to be known beforehand in many browsers/parsers. |
What about my suggestion to use a counting range to determine the length? I guess that should be pretty fast and should be an overall win over using dynamic memory allocations. |
I have a hard time visualizing it, but as long as you have the length before you start writing the body it should be fine. After all, |
Any update in regards to adding multipart for HTTPClient? Other than the conflicts github is reporting, is there anything else that would be required for this to get pulled into vibe-d or is there already a multipart implementation in works that isnt pushed into the master branch? |
This still needs a test, but the logic should be right. These two objects (file, memory) will cover 99% of what's usually needed in multi-part form uploads. The alternative to using these is a lot of boilerplate and some specialized low-level protocol knowledge.
I'll write the test to complete the pull request if the structure is satisfying.