-
Notifications
You must be signed in to change notification settings - Fork 117
Closed
Labels
Description
Environment
Node version: v12.14.1
Npm version: 6.13.4
OS and version: Ubuntu 18.04.1
typed-rest-client version: 1.7.2
Issue Description
Redirect URLs are being resolved incorrectly when the redirect location is a relative URL.
Expected behaviour
Redirect locations that are relative should be resolved using the URL of the current request as the base URL.
Actual behaviour
The URL is parsed as an absolute URL. This results in redirecting back to localhost.
Steps to reproduce
import * as httpm from "typed-rest-client/HttpClient";
import { IRequestOptions } from "typed-rest-client/Interfaces";
const userAgent = "";
const options: IRequestOptions = { allowRedirectDowngrade: true };
const client = new httpm.HttpClient(userAgent, [], options);
// This URL will result in a redirect to a relative URL.
const url = "https://postman-echo.com/cookies/set?foo1=bar1&foo2=bar2";
const headers = {};
// This fails with: `Error: connect ECONNREFUSED 127.0.0.1:80`
const result = client.request("GET", url, "", headers);
Logs
(node:9592) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:80
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1134:16)
Relevant curl output:
curl -v https://postman-echo.com/cookies/set\?foo1\=bar1\&foo2\=bar2
< HTTP/1.1 302 Found
< Content-Type: text/plain; charset=utf-8
< Date: Tue, 03 Mar 2020 23:19:51 GMT
< Location: /cookies