[http-server-javascript] Support new-style multipart requests (and some other things) #5514
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements handling for new-style multipart requests and heavily refactors the multipart core to use web streams. While this doesn't enable streaming multipart yet (i.e. the implementation layer still buffers the parts before providing them to the business logic), it's a step towards streaming multipart.
TypeSpec.Http.HttpPart
(link [core] Add signifier that designates a "must-understand" type. #5275).bytes
throughNodeJS.Buffer
asUint8Array
.gensym
, which generates unique symbols containing a monotonically incrementing counter. This helps me prevent collisions between names of variables I generate and names of variables generated from user typespec code without requiring a full-blown scope solution. It costs readability of the generated code, but isn't so bad.http.IncomingMessage
into a ReadableStream, then the bytes read from the multipart body are split into parts and streamed individually. Finally, each individual part stream is consumed by a transform that reads enough of the stream to parse the headers and then passes the rest of the body through to a final "body stream."HttpContext
. The application logic can use these handlers to manually respond with validation/internal errors in whichever way the router would ordinarily respond to them.