From 78c05928a620dd462f4e4de0e5631e5e84edf844 Mon Sep 17 00:00:00 2001 From: Jonathan Poelman Date: Wed, 29 Jul 2020 14:43:14 +0200 Subject: [PATCH 1/5] when uri in proxy URL is not a param use encodeURI --- src/fetcher.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/fetcher.ts b/src/fetcher.ts index 2b94b25f4..9d6c4073d 100644 --- a/src/fetcher.ts +++ b/src/fetcher.ts @@ -754,8 +754,14 @@ export default class Fetcher implements CallbackifyInterface { static crossSiteProxy (uri: string): undefined | any { if (Fetcher.crossSiteProxyTemplate) { - return Fetcher.crossSiteProxyTemplate + if (Fetcher.crossSiteProxyTemplate.indexOf('={uri}') !== -1){ + return Fetcher.crossSiteProxyTemplate .replace('{uri}', encodeURIComponent(uri)) + } else { + return Fetcher.crossSiteProxyTemplate + .replace('{uri}', encodeURI(uri)) + } + } else { return undefined } @@ -831,8 +837,13 @@ export default class Fetcher implements CallbackifyInterface { typeof document !== 'undefined' && document.location && ('' + document.location).slice(0, 6) === 'https:' && // origin is secure uri.slice(0, 5) === 'http:') { // requested data is not - return Fetcher.crossSiteProxyTemplate - .replace('{uri}', encodeURIComponent(uri)) + if (Fetcher.crossSiteProxyTemplate.indexOf('={uri}') !== -1){ + return Fetcher.crossSiteProxyTemplate + .replace('{uri}', encodeURIComponent(uri)) + } else { + return Fetcher.crossSiteProxyTemplate + .replace('{uri}', encodeURI(uri)) + } } return uri From dfc80ff2970f5e6d0609d0aac7165b877ba52b82 Mon Sep 17 00:00:00 2001 From: Jonathan Poelman Date: Mon, 3 Aug 2020 09:50:47 +0200 Subject: [PATCH 2/5] removed https condition when fetching proxy --- src/fetcher.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/fetcher.ts b/src/fetcher.ts index 9d6c4073d..24c9c7c3a 100644 --- a/src/fetcher.ts +++ b/src/fetcher.ts @@ -835,7 +835,6 @@ export default class Fetcher implements CallbackifyInterface { // prevent it loading insecure http: stuff so we need proxy. if (Fetcher.crossSiteProxyTemplate && typeof document !== 'undefined' && document.location && - ('' + document.location).slice(0, 6) === 'https:' && // origin is secure uri.slice(0, 5) === 'http:') { // requested data is not if (Fetcher.crossSiteProxyTemplate.indexOf('={uri}') !== -1){ return Fetcher.crossSiteProxyTemplate From 0cf0b9c327f729387c0ca0ac2239aa3c94b61612 Mon Sep 17 00:00:00 2001 From: Jonathan Poelman Date: Mon, 10 Aug 2020 15:22:59 +0200 Subject: [PATCH 3/5] fix request headers --- src/fetcher.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fetcher.ts b/src/fetcher.ts index 24c9c7c3a..44e970aad 100644 --- a/src/fetcher.ts +++ b/src/fetcher.ts @@ -1102,7 +1102,7 @@ export default class Fetcher implements CallbackifyInterface { let { actualProxyURI } = options - return this._fetch((actualProxyURI as string), options) + return this._fetch((actualProxyURI as string), options as any) .then(response => this.handleResponse(response, docuri, options), error => { // @@ handleError? // @ts-ignore Invalid response object @@ -1541,7 +1541,7 @@ export default class Fetcher implements CallbackifyInterface { Fetcher.setCredentials(uri, options) return new Promise(function (resolve, reject) { - fetcher._fetch(uri, options).then(response => { + fetcher._fetch(uri, options as any).then(response => { if (response.ok) { if (method === 'PUT' || method === 'PATCH' || method === 'POST' || method === 'DELETE') { fetcher.invalidateCache (uri) From b50576b30de4815c93555fc8535cd3987fa44295 Mon Sep 17 00:00:00 2001 From: Jonathan Poelman Date: Mon, 10 Aug 2020 15:41:07 +0200 Subject: [PATCH 4/5] try fix with assign --- src/fetcher.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fetcher.ts b/src/fetcher.ts index 44e970aad..fcc8fe894 100644 --- a/src/fetcher.ts +++ b/src/fetcher.ts @@ -1102,7 +1102,7 @@ export default class Fetcher implements CallbackifyInterface { let { actualProxyURI } = options - return this._fetch((actualProxyURI as string), options as any) + return this._fetch((actualProxyURI as string), Object.assign({},options)) .then(response => this.handleResponse(response, docuri, options), error => { // @@ handleError? // @ts-ignore Invalid response object @@ -1541,7 +1541,7 @@ export default class Fetcher implements CallbackifyInterface { Fetcher.setCredentials(uri, options) return new Promise(function (resolve, reject) { - fetcher._fetch(uri, options as any).then(response => { + fetcher._fetch(uri, Object.assign({}, options)).then(response => { if (response.ok) { if (method === 'PUT' || method === 'PATCH' || method === 'POST' || method === 'DELETE') { fetcher.invalidateCache (uri) From f9a8bacdafdcd8a818101970878f40549c01cbe0 Mon Sep 17 00:00:00 2001 From: Jonathan Poelman Date: Mon, 10 Aug 2020 16:05:19 +0200 Subject: [PATCH 5/5] tried something else with object assign --- src/fetcher.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/fetcher.ts b/src/fetcher.ts index fcc8fe894..a3c326e07 100644 --- a/src/fetcher.ts +++ b/src/fetcher.ts @@ -1101,8 +1101,9 @@ export default class Fetcher implements CallbackifyInterface { } let { actualProxyURI } = options - - return this._fetch((actualProxyURI as string), Object.assign({},options)) + let requestOptions = Object.assign({}, options); + requestOptions.headers = Object.assign({}, options.headers); + return this._fetch((actualProxyURI as string), requestOptions) .then(response => this.handleResponse(response, docuri, options), error => { // @@ handleError? // @ts-ignore Invalid response object @@ -1539,9 +1540,10 @@ export default class Fetcher implements CallbackifyInterface { (options as any).headers['content-type'] = options.contentType } Fetcher.setCredentials(uri, options) - + let requestOptions = Object.assign({}, options); + requestOptions.headers = Object.assign({}, options.headers); return new Promise(function (resolve, reject) { - fetcher._fetch(uri, Object.assign({}, options)).then(response => { + fetcher._fetch(uri, Object.assign({}, requestOptions)).then(response => { if (response.ok) { if (method === 'PUT' || method === 'PATCH' || method === 'POST' || method === 'DELETE') { fetcher.invalidateCache (uri)