This commit is contained in:
Rikki Gibson 2018-04-05 09:24:31 -07:00
Родитель 96471b17df
Коммит 4289979528
2 изменённых файлов: 5 добавлений и 9 удалений

Просмотреть файл

@ -3,8 +3,7 @@
import { BaseFilter } from "./baseFilter";
import { HttpOperationResponse } from "../httpOperationResponse";
import * as utils from "../util/utils";
const parse = require("url-parse");
import * as parse from "url-parse";
export class RedirectFilter extends BaseFilter {
@ -21,13 +20,9 @@ export class RedirectFilter extends BaseFilter {
if (response && response.headers && response.headers.get("location") &&
(response.status === 300 || response.status === 307 || (response.status === 303 && request.method === "POST")) &&
(!this.maximumRetries || currentRetries < this.maximumRetries)) {
if (parse(response.headers.get("location")).hostname) {
request.url = response.headers.get("location") as string;
} else {
const urlObject = parse(request.url);
urlObject.set("pathname", response.headers.get("location") as string);
request.url = urlObject.href;
}
request.url = parse(response.headers.get("location")!, parse(request.url)).href;
// POST request with Status code 303 should be converted into a
// redirected GET request if the redirect url is present in the location header
if (response.status === 303) {

Просмотреть файл

@ -47,6 +47,7 @@
"devDependencies": {
"@types/mocha": "^2.2.40",
"@types/should": "^8.1.30",
"@types/url-parse": "^1.1.0",
"@types/xml2js": "^0.4.2",
"mocha": "^3.5.3",
"should": "5.2.0",