Multipart requests #4

Open
opened 2024-02-02 15:52:16 +01:00 by Jef Roosens · 1 comment

HTTP multipart allows sending multiple bodies in a single request, each with its own content type and thus formatting. This is for example useful for uploading a file and its metadata at once, with the metadata being sent first as a JSON-encoded body and the file as the second part. This would require only one request, while still allowing for the same level of complexity and flexibility.

LNM should provide some level of abstraction to handle these requests, parsing the data as needed and exposing an API to the user to interact with the various payloads.

To do

  • Be able to retrieve key-value pairs from headers (to read the boundary directive in the content-type header)

  • Be able to read only the value part from a header

From Content-Type: multipart/form-data; boundary=2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f, we should have a function to retrieve multipart/form-data, and another to retrieve the boundary.

  • Add API functions to abstract reading of HTTP body

Response code should probably signal whether the entire body has been read, or if an error occured.

  • Detect if request is multipart and transparently allow reading bodies one by one (providing some way to detect what part of the body is being read and retrieve filename, name etc.)
HTTP multipart allows sending multiple bodies in a single request, each with its own content type and thus formatting. This is for example useful for uploading a file and its metadata at once, with the metadata being sent first as a JSON-encoded body and the file as the second part. This would require only one request, while still allowing for the same level of complexity and flexibility. LNM should provide some level of abstraction to handle these requests, parsing the data as needed and exposing an API to the user to interact with the various payloads. ## To do - [ ] Be able to retrieve key-value pairs from headers (to read the `boundary` directive in the content-type header) - [ ] Be able to read only the value part from a header From `Content-Type: multipart/form-data; boundary=2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f`, we should have a function to retrieve `multipart/form-data`, and another to retrieve the boundary. - [ ] Add API functions to abstract reading of HTTP body Response code should probably signal whether the entire body has been read, or if an error occured. - [ ] Detect if request is multipart and transparently allow reading bodies one by one (providing some way to detect what part of the body is being read and retrieve filename, name etc.)
Jef Roosens added the
enhancement
label 2024-02-02 15:52:16 +01:00

My current idea is to add a layer of abstraction to the reading of HTTP body data from the request. Instead of accessing the read buffer directly, LNM would instead expose a "read body" function which reads data from the current body, be it a regular body or part of a multipart request. This function would currently delimit reads between bodies, allowing the framework to transparently split the bodies as needed. Some string variable would also be present which describes what the current part is the user is reading from.

To process parts, the user would define multiple steps, with each step processing a specific part of the multipart request. This would allow for easy integration into the current design of steps, with the body read functions emitting lnm step errors, allowing easy composition into a step.

My current idea is to add a layer of abstraction to the reading of HTTP body data from the request. Instead of accessing the read buffer directly, LNM would instead expose a "read body" function which reads data from the current body, be it a regular body or part of a multipart request. This function would currently delimit reads between bodies, allowing the framework to transparently split the bodies as needed. Some string variable would also be present which describes what the current part is the user is reading from. To process parts, the user would define multiple steps, with each step processing a specific part of the multipart request. This would allow for easy integration into the current design of steps, with the body read functions emitting lnm step errors, allowing easy composition into a step.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Chewing_Bever/lnm#4
There is no content yet.