From 89741ad99bd38dca833cb876ab0e0d51fa0b05d0 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Sat, 30 Jan 2021 11:41:25 +0100
Subject: [PATCH] refactor: HttpResponse.authorization (#8470)

---
 lib/util/http/__snapshots__/index.spec.ts.snap | 8 ++++++++
 lib/util/http/index.ts                         | 3 +++
 2 files changed, 11 insertions(+)

diff --git a/lib/util/http/__snapshots__/index.spec.ts.snap b/lib/util/http/__snapshots__/index.spec.ts.snap
index 2d399e98b9..13e7e4858f 100644
--- a/lib/util/http/__snapshots__/index.spec.ts.snap
+++ b/lib/util/http/__snapshots__/index.spec.ts.snap
@@ -2,6 +2,7 @@
 
 exports[`util/http/index deleteJson 1`] = `
 Object {
+  "authorization": false,
   "body": Object {},
   "headers": Object {
     "content-type": "application/json",
@@ -12,6 +13,7 @@ Object {
 
 exports[`util/http/index get 1`] = `
 Object {
+  "authorization": false,
   "body": "",
   "headers": Object {},
   "statusCode": 200,
@@ -20,6 +22,7 @@ Object {
 
 exports[`util/http/index getJson 1`] = `
 Object {
+  "authorization": false,
   "body": Object {
     "test": true,
   },
@@ -30,6 +33,7 @@ Object {
 
 exports[`util/http/index headJson 1`] = `
 Object {
+  "authorization": false,
   "body": Object {},
   "headers": Object {
     "content-type": "application/json",
@@ -40,6 +44,7 @@ Object {
 
 exports[`util/http/index patchJson 1`] = `
 Object {
+  "authorization": false,
   "body": Object {},
   "headers": Object {
     "content-type": "application/json",
@@ -50,6 +55,7 @@ Object {
 
 exports[`util/http/index postJson 1`] = `
 Object {
+  "authorization": false,
   "body": Object {},
   "headers": Object {
     "content-type": "application/json",
@@ -60,6 +66,7 @@ Object {
 
 exports[`util/http/index putJson 1`] = `
 Object {
+  "authorization": false,
   "body": Object {},
   "headers": Object {
     "content-type": "application/json",
@@ -70,6 +77,7 @@ Object {
 
 exports[`util/http/index retries 1`] = `
 Object {
+  "authorization": false,
   "body": "",
   "headers": Object {
     "x-some-header": "abc",
diff --git a/lib/util/http/index.ts b/lib/util/http/index.ts
index d735e5a620..45b886d8b7 100644
--- a/lib/util/http/index.ts
+++ b/lib/util/http/index.ts
@@ -44,6 +44,7 @@ export interface HttpResponse<T = string> {
   statusCode: number;
   body: T;
   headers: any;
+  authorization?: boolean;
 }
 
 function cloneResponse<T>(response: any): HttpResponse<T> {
@@ -52,6 +53,7 @@ function cloneResponse<T>(response: any): HttpResponse<T> {
     statusCode: response.statusCode,
     body: clone<T>(response.body),
     headers: clone(response.headers),
+    authorization: !!response.authorization,
   };
 }
 
@@ -148,6 +150,7 @@ export class Http<GetOptions = HttpOptions, PostOptions = HttpPostOptions> {
 
     try {
       const res = await resPromise;
+      res.authorization = !!options?.headers?.authorization;
       return cloneResponse(res);
     } catch (err) {
       const { abortOnError, abortIgnoreStatusCodes } = options;
-- 
GitLab