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

chore: migrate to getSetCookie #586

Merged
merged 11 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
mark getAll as deprecated
  • Loading branch information
balazsorban44 committed Sep 7, 2023
commit 255a08dedee5129c76e8f30353b0f5f978ea1285
11 changes: 5 additions & 6 deletions packages/node-utils/src/edge-to-node/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ import { toToReadable } from './stream'

export function buildToNodeHandler(
dependencies: BuildDependencies,
options: RequestOptions
options: RequestOptions,
) {
const toRequest = buildToRequest(dependencies)
const toFetchEvent = buildToFetchEvent(dependencies)
return function toNodeHandler(webHandler: WebHandler): NodeHandler {
return (
incomingMessage: IncomingMessage,
serverResponse: ServerResponse
serverResponse: ServerResponse,
) => {
const request = toRequest(incomingMessage, options)
const maybePromise = webHandler(request, toFetchEvent(request))
if (maybePromise instanceof Promise) {
maybePromise.then((response) =>
toServerResponse(response, serverResponse)
toServerResponse(response, serverResponse),
)
} else {
toServerResponse(maybePromise, serverResponse)
Expand All @@ -36,16 +36,15 @@ export function buildToNodeHandler(

function toServerResponse(
webResponse: Response | null | undefined,
serverResponse: ServerResponse
serverResponse: ServerResponse,
) {
if (!webResponse) {
serverResponse.end()
return
}
mergeIntoServerResponse(
// @ts-ignore getAll() is not standard https://fetch.spec.whatwg.org/#headers-class
toOutgoingHeaders(webResponse.headers),
serverResponse
serverResponse,
)

serverResponse.statusCode = webResponse.status
Expand Down
1 change: 1 addition & 0 deletions packages/primitives/src/primitives/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ HeadersModule.Headers.prototype.values = function* () {
* Add a new method for retrieving all independent `set-cookie` headers that
* maybe have been appended. This will only work when getting `set-cookie`
* headers.
* @deprecated use [`Headers#getSetCookie()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/getSetCookie) instead
*/
HeadersModule.Headers.prototype.getAll = function (name) {
const _name = normalizeAndValidateHeaderName(name, 'Headers.getAll')
Expand Down
3 changes: 2 additions & 1 deletion packages/primitives/type-definitions/fetch.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export class Headers extends globalThis.Headers {
/** @deprecated use [`Headers#getSetCookie()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/getSetCookie) instead */
getAll?(key: 'set-cookie'): string[]
Copy link
Member Author

@balazsorban44 balazsorban44 Sep 7, 2023

Choose a reason for hiding this comment

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

Should we drop getAll altogether as part of a major bump?

}

Expand All @@ -16,7 +17,7 @@ export type RequestInfo = string | Request | globalThis.Request
export type RequestInit = globalThis.RequestInit
declare const fetchImplementation: (
info: RequestInfo,
init?: RequestInit
init?: RequestInit,
) => Promise<Response>

declare const FileConstructor: typeof File
Expand Down