-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[fix] set rawBody to null when body is nullish in simulated load fetch #2295
Conversation
🦋 Changeset detectedLatest commit: a140832 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
lgtm.
i'm not sure the best place to test this if you want to do an integration test. but a unit test might run faster and be less flaky
the smallest unit test would be to make an encode_body
function. that's a pretty small function and barely worth having though. an alternative might be to refactor out a function to make the IncomingRequest
:
/**
* @param {string} url
* @param {RequestInit} opts
* @param {import('types/hooks').ServerRequest} request
* @param {string} relative
* @returns {import('types/app').IncomingRequest}
*/
export function incoming_request(url, opts, request, relative) {
const headers = /** @type {import('types/helper').RequestHeaders} */ ({
...opts.headers
});
if (opts.credentials !== 'omit') {
headers.cookie = request.headers.cookie;
if (!headers.authorization) {
headers.authorization = request.headers.authorization;
}
}
const search = url.includes('?') ? url.slice(url.indexOf('?') + 1) : '';
return {
host: request.host,
method: opts.method || 'GET',
headers,
path: relative,
rawBody: opts.body === null ? null : new TextEncoder().encode(/** @type {string} */ (opts.body)),
query: new URLSearchParams(search)
};
}
Will this have an affect on Adapters? Currently |
I don't think this is the root cause |
If |
I forgot about |
Also, the type cast ( |
rawBody: | ||
opts.body == null | ||
? null | ||
: new TextEncoder().encode(/** @type {string} */ (opts.body)), |
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.
rawBody: | |
opts.body == null | |
? null | |
: new TextEncoder().encode(/** @type {string} */ (opts.body)), | |
rawBody: opts.body == null ? null : new TextEncoder().encode(opts.body), |
@JeanJPNM Yup, the cast to string is unnecessary now, good catch. I'm confused about what you're saying about I'm also confused about why you're saying this isn't the root cause. At
parse_body we're parsing that rawBody of null as a body of null , which node-fetch then doesn't complain about. Is there a different route you think we should be taking to that?
@jthegedus In the discussions on #2215, it was decided that |
About the root cause: I thought that the problem wasn't on that line of code because the typecast was there as a "promise" that the body would be a string, but because the body was |
Great, thanks for the clarification. I didn't read that whole discussion, so when I updated the
Thanks, I will await the type fix and update on my end accordingly. |
Fixes #2294. No tests yet. I'd appreciate suggestions for where/how those should be added, as I haven't spent a ton of time in this codebase.
Before submitting the PR, please make sure you do the following
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0