From 8131f222d411e2e97c87398c4dd36ee68196672c Mon Sep 17 00:00:00 2001 From: Steve Purdy Date: Wed, 6 Mar 2019 11:32:12 -0500 Subject: [PATCH 1/3] Prevent mangled URL when redirected to https When starting with an 'http' URL for a Gitlab instance that redirects to 'https', the URL is getting mangled as the 'replace' call is looking for 'https://gitlab.example/api/v4/projects' when the service.url is 'http://gitlab.example/api/v4/projects'. You end up with something like "http://gitlab.example/api/v4/projects/https://gitlab.example/api/v4/projects/" in subsequent steps. --- src/infrastructure/RequestHelper.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/infrastructure/RequestHelper.ts b/src/infrastructure/RequestHelper.ts index 222fc583..53a9882f 100644 --- a/src/infrastructure/RequestHelper.ts +++ b/src/infrastructure/RequestHelper.ts @@ -103,6 +103,9 @@ async function getPaginated( // If not looking for a singular page and still under the max pages limit // AND their is a next page, paginate if (!queryOptions.page && underMaxPageLimit && links.next) { + // If redirected from http:// to https://, need to update service.url to avoid url inception + if (service.url.slice(0,5) === 'http:' && links.next.url.slice(0,5) === 'https') + service.url = service.url.replace('http:', 'https:'); more = await getPaginated(service, links.next.url.replace(service.url, ''), options); data = [...response.body, ...more]; } else { From 837f4ab1c65c01c563ff1e66ad4ff9dac4a3e78b Mon Sep 17 00:00:00 2001 From: Steve Purdy Date: Wed, 6 Mar 2019 11:39:42 -0500 Subject: [PATCH 2/3] Add whitespace and braces to If statement --- src/infrastructure/RequestHelper.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/infrastructure/RequestHelper.ts b/src/infrastructure/RequestHelper.ts index 53a9882f..d6e1585c 100644 --- a/src/infrastructure/RequestHelper.ts +++ b/src/infrastructure/RequestHelper.ts @@ -104,8 +104,10 @@ async function getPaginated( // AND their is a next page, paginate if (!queryOptions.page && underMaxPageLimit && links.next) { // If redirected from http:// to https://, need to update service.url to avoid url inception - if (service.url.slice(0,5) === 'http:' && links.next.url.slice(0,5) === 'https') + if (service.url.slice(0,5) === 'http:' && links.next.url.slice(0,5) === 'https') { service.url = service.url.replace('http:', 'https:'); + } + more = await getPaginated(service, links.next.url.replace(service.url, ''), options); data = [...response.body, ...more]; } else { From 2f11c603d666f3c47238ae02c64a1f56a17dc179 Mon Sep 17 00:00:00 2001 From: Steve Purdy Date: Wed, 6 Mar 2019 14:11:26 -0500 Subject: [PATCH 3/3] Whitespace changes to make lint happy --- src/infrastructure/RequestHelper.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/infrastructure/RequestHelper.ts b/src/infrastructure/RequestHelper.ts index d6e1585c..d3ebad95 100644 --- a/src/infrastructure/RequestHelper.ts +++ b/src/infrastructure/RequestHelper.ts @@ -104,10 +104,9 @@ async function getPaginated( // AND their is a next page, paginate if (!queryOptions.page && underMaxPageLimit && links.next) { // If redirected from http:// to https://, need to update service.url to avoid url inception - if (service.url.slice(0,5) === 'http:' && links.next.url.slice(0,5) === 'https') { + if (service.url.slice(0, 5) === 'http:' && links.next.url.slice(0, 5) === 'https') { service.url = service.url.replace('http:', 'https:'); } - more = await getPaginated(service, links.next.url.replace(service.url, ''), options); data = [...response.body, ...more]; } else {