Skip to content

chore(server): rewrite resolveHTTPResponse with Fetch - #5684

Merged
KATT merged 115 commits into
nextfrom
04-26-resolveResponse-and-multi
Apr 30, 2024
Merged

KATT merged 115 commits into
nextfrom
04-26-resolveResponse-and-multi

Conversation

@KATT

@KATT KATT commented Apr 28, 2024 •

Copy link
Copy Markdown
Member

Merges #5676 into #5665

Closes #5676
Closes #1853

🎯 Changes

Rewrites our resolve HTTP response function so it takes a Response and outputs a Request

Each adapter is responsible of converting their internal request-representation to a Response and handle a Response-response

βœ… Checklist

  • I have followed the steps listed in the Contributing guide.
  • If necessary, I have added documentation related to the changes made.
  • I have added or updated the tests related to the changes made.

);

const response = await resolveHTTPResponse({
const response = await resolveResponse({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we reject unsupported media types?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getContentTypeHandlerOrThrow()

const getInputForIndex = (() => {
const contentTypeHandler = getContentTypeHandlerOrThrow(req);

if (isBatchCall && !contentTypeHandler.batching) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool

// if `getRawInput` fails, we can't include the input in the error
input = undefined;
}
const input = inputGetter.getParsedInput();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's better

}

await controller.write(formatter.end());
await controller.close();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stuff is way tidier

Object {
"headers": Object {
"Content-Type": "application/json",
"content-type": "application/json",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lambda always reformats as 'Content-Type' in the wild, though not sure if that's a problem here?

return handler;
}

if (!handler && req.method === 'GET') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this behaviour originally because I don't believe it protects against the CSRF attack that we wanted to defend against? Best to throw 405 in any situation that we don't support it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand the mechanisms in play though, just read the original issue/PR and got the impression that form verb support is what matters, and forms do have a method="get" option

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to be able to open tRPC GET queries in my browser

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is where the juice is

KATT added 16 commits April 28, 2024 21:25
* rewrite lambda

* nuke

* tweaks

* tweak

* cool

* cool

* fix

* bump

* buump
This reverts commit c1585b6.
* shift complexity

* cool

* cool

* cool

* prob

* cool

* cool

* tweak

* mkay

* tweak

* tweak

* cool

* cool

* cool

* cool

* cool

* cool

* cool

* shift more

* cool

* cool

* cool

* cool

* request info

* wip

* cool

* cool

* Update packages/server/src/unstable-core-do-not-import/http/types.ts

* fix

* tweak
…-and-multi

# Conflicts:
#	.github/workflows/release-tmp.yml
#	examples/.experimental/next-formdata/src/server/routers/room.ts
#	examples/minimal-content-types/client/src/SendMultipartFormDataButton.tsx
#	examples/minimal-content-types/server/index.ts
#	examples/minimal-content-types/server/tsconfig.json
#	packages/server/src/@trpc/server/http.ts
#	packages/server/src/@trpc/server/index.ts
#	packages/server/src/adapters/aws-lambda/index.ts
#	packages/server/src/adapters/aws-lambda/utils.ts
#	packages/server/src/adapters/express.ts
#	packages/server/src/adapters/fastify/fastifyRequestHandler.ts
#	packages/server/src/adapters/fetch/fetchRequestHandler.ts
#	packages/server/src/adapters/fetch/types.ts
#	packages/server/src/adapters/next.ts
#	packages/server/src/adapters/node-http/content-type/form-data/index.ts
#	packages/server/src/adapters/node-http/content-type/json/getPostBody.ts
#	packages/server/src/adapters/node-http/content-type/json/index.ts
#	packages/server/src/adapters/node-http/content-type/types.ts
#	packages/server/src/adapters/node-http/nodeHTTPRequestHandler.ts
#	packages/server/src/adapters/node-http/types.ts
#	packages/server/src/adapters/standalone.ts
#	packages/server/src/unstable-core-do-not-import/http/contentType.ts
#	packages/server/src/unstable-core-do-not-import/http/index.ts
#	packages/server/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts
#	packages/server/src/unstable-core-do-not-import/http/types.ts
#	packages/server/src/unstable-core-do-not-import/rootConfig.ts
#	packages/tests/server/adapters/express.test.tsx
#	packages/tests/server/adapters/fastify.test.ts
#	packages/tests/server/adapters/next.test.ts
#	packages/tests/server/adapters/standalone.test.ts
#	packages/tests/server/react/octetStreams.test.tsx
#	www/docs/migration/migrate-from-v10-to-v11.mdx
…Response-and-multi"

This reverts commit 7edfea7, reversing
changes made to 3d33679.
trpc-bot
trpc-bot previously approved these changes Apr 30, 2024
@github-actions

github-actions Bot commented May 2, 2024

Copy link
Copy Markdown
Contributor

This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

This branch was successfully deployed

5 active deployments
Preview – www β€” 2c13b76e Deployed Apr 30, 2024 by vercel[bot]
Preview – next-prisma-starter β€” 2c13b76e Deployed Apr 30, 2024 by vercel[bot]
Preview – trpc-next-app-dir β€” 2c13b76e Deployed Apr 30, 2024 by vercel[bot]
Preview – todomvc β€” 2c13b76e Deployed Apr 30, 2024 by vercel[bot]
Preview – og-image β€” 2c13b76e Deployed Apr 30, 2024 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

update request handling in resolveHttpResponse to follow Fetch API

4 participants