-
-
Notifications
You must be signed in to change notification settings - Fork 494
🎉 feat: specialize response mapping via AOT for known schema types #1799
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,26 @@ export const WebStandardAdapter: ElysiaAdapter = { | |
| composeHandler: { | ||
| mapResponseContext: 'c.request', | ||
| preferWebstandardHeaders: true, | ||
| specializedResponse(kind, r, hasSet, saveResponse) { | ||
| switch (kind) { | ||
| case 'Object': | ||
| case 'Array': | ||
| return hasSet | ||
| ? `(c.set.headers['content-type']||(c.set.headers['content-type']='application/json'),new Response(JSON.stringify(${saveResponse}${r}),c.set))` | ||
| : `new Response(JSON.stringify(${saveResponse}${r}),{headers:{'content-type':'application/json'}})` | ||
| case 'String': | ||
| return hasSet | ||
| ? `(c.set.headers['content-type']||(c.set.headers['content-type']='text/plain'),new Response(${saveResponse}${r},c.set))` | ||
| : `new Response(${saveResponse}${r})` | ||
| case 'Number': | ||
| case 'Boolean': | ||
| return hasSet | ||
| ? `new Response(${saveResponse}''+${r},c.set)` | ||
| : `new Response(${saveResponse}''+${r})` | ||
|
Comment on lines
+33
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing The String case (lines 30-31) sets This inconsistency could cause clients to misinterpret numeric or boolean responses when headers/cookies/status are active. 🐛 Proposed fix to add content-type for Number/Boolean case 'Number':
case 'Boolean':
return hasSet
- ? `new Response(${saveResponse}''+${r},c.set)`
+ ? `(c.set.headers['content-type']||(c.set.headers['content-type']='text/plain'),new Response(${saveResponse}''+${r},c.set))`
: `new Response(${saveResponse}''+${r})`🤖 Prompt for AI Agents |
||
| default: | ||
| return undefined | ||
| } | ||
| }, | ||
| // @ts-ignore Bun specific | ||
| headers: | ||
| 'c.headers={}\n' + | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.