MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / redirect

Method redirect

lib.commonjs/utils/fetch.js:530–556  ·  view source on GitHub ↗

* Returns a new [[FetchRequest]] that represents the redirection * to %%location%%.

(location)

Source from the content-addressed store, hash-verified

528 * to %%location%%.
529 */
530 redirect(location) {
531 // Redirection; for now we only support absolute locations
532 const current = this.url.split(":")[0].toLowerCase();
533 const target = location.split(":")[0].toLowerCase();
534 // Don't allow redirecting:
535 // - non-GET requests
536 // - downgrading the security (e.g. https => http)
537 // - to non-HTTP (or non-HTTPS) protocols [this could be relaxed?]
538 (0, errors_js_1.assert)(this.method === "GET" && (current !== "https" || target !== "http") && location.match(/^https?:/), `unsupported redirect`, "UNSUPPORTED_OPERATION", {
539 operation: `redirect(${this.method} ${JSON.stringify(this.url)} => ${JSON.stringify(location)})`
540 });
541 // Create a copy of this request, with a new URL
542 const req = new FetchRequest(location);
543 req.method = "GET";
544 req.allowGzip = this.allowGzip;
545 req.timeout = this.timeout;
546 req.#headers = Object.assign({}, this.#headers);
547 if (this.#body) {
548 req.#body = new Uint8Array(this.#body);
549 }
550 req.#bodyType = this.#bodyType;
551 // Do not forward credentials unless on the same domain; only absolute
552 //req.allowInsecure = false;
553 // paths are currently supported; may want a way to specify to forward?
554 //setStore(req.#props, "creds", getStore(this.#pros, "creds"));
555 return req;
556 }
557 /**
558 * Create a new copy of this request.
559 */

Callers 1

#sendMethod · 0.45

Calls 1

splitMethod · 0.45

Tested by

no test coverage detected