Skip to content
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

[http-server-javascript] Support new-style multipart requests (and some other things) #5514

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

witemple-msft
Copy link
Member

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.

  • Add special handling for representation of well-known model TypeSpec.Http.HttpPart (link [core] Add signifier that designates a "must-understand" type. #5275).
  • Added encode/decode support for bytes through NodeJS.Buffer as Uint8Array.
  • Fixed an issue where serialization propagation did not flow through array types, leading to cases where models were being detected as not requiring serialization if they contained properties with array types, where the array value type did require serialization.
  • Implemented and pervasively used 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.
  • Implemented rfc5987 header parameter parsing as a shared helper module, used to extract boundary and other information while processing multipart requests.
  • Implemented streaming multipart chunking via web streams in a shared helper module. When a multipart/form-data content-type is detected, a parser is generated that first converts the 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."
  • Exposed error handlers (onInvalidRequest, onRequestNotFound, onInternalError) to application logic through 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.

@azure-sdk
Copy link
Collaborator

azure-sdk commented Jan 7, 2025

All changed packages have been documented.

  • @typespec/http-server-javascript
Show changes

@typespec/http-server-javascript - feature ✏️

  • Implemented new-style multipart request handling.,> - Fixed JSON serialization/deserialization in some cases where models that required serialization occurred within arrays.

@witemple-msft witemple-msft marked this pull request as ready for review January 7, 2025 17:03
@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 📚 Next docs 🛝 VSCode Extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants