Skip to content

Commit

Permalink
revert possible breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Oct 11, 2024
1 parent 289a5aa commit b2e16a5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 32 deletions.
5 changes: 2 additions & 3 deletions packages/astro/src/core/render-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { callMiddleware } from './middleware/callMiddleware.js';
import { sequence } from './middleware/index.js';
import { renderRedirect } from './redirects/render.js';
import { type Pipeline, Slots, getParams, getProps } from './render/index.js';
import { copyRequest } from './routing/rewrite.js';

export const apiContextRoutesSymbol = Symbol.for('context.routes');

Expand Down Expand Up @@ -156,7 +155,7 @@ export class RenderContext {
if (payload instanceof Request) {
this.request = payload;
} else {
this.request = copyRequest(newUrl, this.request);
this.request = new Request(newUrl, this.request);
}
this.isRewriting = true;
this.url = new URL(this.request.url);
Expand Down Expand Up @@ -256,7 +255,7 @@ export class RenderContext {
if (reroutePayload instanceof Request) {
this.request = reroutePayload;
} else {
this.request = copyRequest(newUrl, this.request);
this.request = new Request(newUrl, this.request);
}
this.url = new URL(this.request.url);
this.cookies = new AstroCookies(this.request);
Expand Down
29 changes: 0 additions & 29 deletions packages/astro/src/core/routing/rewrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,3 @@ export function findRouteToRewrite({
}
}
}

/**
* Utility function that creates a new `Request` with a new URL from an old `Request`.
*
* @param newUrl The new `URL`
* @param oldRequest The old `Request`
*/
export function copyRequest(newUrl: URL, oldRequest: Request): Request {
if (oldRequest.bodyUsed) {
throw new AstroError(AstroErrorData.RewriteWithBodyUsed);
}
return new Request(newUrl, {
method: oldRequest.method,
headers: oldRequest.headers,
body: oldRequest.body,
referrer: oldRequest.referrer,
referrerPolicy: oldRequest.referrerPolicy,
mode: oldRequest.mode,
credentials: oldRequest.credentials,
cache: oldRequest.cache,
redirect: oldRequest.redirect,
integrity: oldRequest.integrity,
signal: oldRequest.signal,
keepalive: oldRequest.keepalive,
// https://fetch.spec.whatwg.org/#dom-request-duplex
// @ts-expect-error It isn't part of the types, but undici accepts it and it allows to carry over the body to a new request
duplex: 'half',
});
}

0 comments on commit b2e16a5

Please sign in to comment.