summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorFelipe Baltor <fbaltor@gmail.com>2023-07-30 10:13:28 -0300
committerGitHub <noreply@github.com>2023-07-30 09:13:28 -0400
commit3cb260ed15a26785272bb09427504a565010963d (patch)
treecc29322017d235d3d56c75240eab1ce9f1f8be76 /ext
parentcfdef0c38038e42a4ac40f6e962c5e40a0c5cbe6 (diff)
fix(Deno.serve): accessing .url on cloned request throws (#19869)
This PR fixes #19818. The problem was that the new InnerRequest class does not initialize the fields urlList and urlListProcessed that are used during a request clone. The solution aims to be straightforward by simply initializing the missing properties during the clone process. I also implemented a "cache" to the url getter of the new InnerRequest, avoiding the cost of calling op_http_get_request_method_and_url.
Diffstat (limited to 'ext')
-rw-r--r--ext/fetch/23_request.js4
-rw-r--r--ext/http/00_serve.js16
2 files changed, 13 insertions, 7 deletions
diff --git a/ext/fetch/23_request.js b/ext/fetch/23_request.js
index daf77a834..afd3c1c50 100644
--- a/ext/fetch/23_request.js
+++ b/ext/fetch/23_request.js
@@ -174,8 +174,8 @@ function cloneInnerRequest(request, skipBody = false) {
body,
redirectMode: request.redirectMode,
redirectCount: request.redirectCount,
- urlList: request.urlList,
- urlListProcessed: request.urlListProcessed,
+ urlList: [() => request.url()],
+ urlListProcessed: [request.url()],
clientRid: request.clientRid,
blobUrlEntry: request.blobUrlEntry,
url() {
diff --git a/ext/http/00_serve.js b/ext/http/00_serve.js
index e881cca2a..b51dfee07 100644
--- a/ext/http/00_serve.js
+++ b/ext/http/00_serve.js
@@ -129,6 +129,7 @@ class InnerRequest {
#streamRid;
#body;
#upgraded;
+ #urlValue;
constructor(slabId, context) {
this.#slabId = slabId;
@@ -236,6 +237,10 @@ class InnerRequest {
}
url() {
+ if (this.#urlValue !== undefined) {
+ return this.#urlValue;
+ }
+
if (this.#methodAndUri === undefined) {
if (this.#slabId === undefined) {
throw new TypeError("request closed");
@@ -249,27 +254,28 @@ class InnerRequest {
// * is valid for OPTIONS
if (path === "*") {
- return "*";
+ return this.#urlValue = "*";
}
// If the path is empty, return the authority (valid for CONNECT)
if (path == "") {
- return this.#methodAndUri[1];
+ return this.#urlValue = this.#methodAndUri[1];
}
// CONNECT requires an authority
if (this.#methodAndUri[0] == "CONNECT") {
- return this.#methodAndUri[1];
+ return this.#urlValue = this.#methodAndUri[1];
}
const hostname = this.#methodAndUri[1];
if (hostname) {
// Construct a URL from the scheme, the hostname, and the path
- return this.#context.scheme + hostname + path;
+ return this.#urlValue = this.#context.scheme + hostname + path;
}
// Construct a URL from the scheme, the fallback hostname, and the path
- return this.#context.scheme + this.#context.fallbackHost + path;
+ return this.#urlValue = this.#context.scheme + this.#context.fallbackHost +
+ path;
}
get remoteAddr() {