Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A fix to accept headers not being sent correctly in the Fetcher #437

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -829,10 +835,14 @@ 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
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
Expand Down Expand Up @@ -1091,8 +1101,9 @@ export default class Fetcher implements CallbackifyInterface {
}

let { actualProxyURI } = options

return this._fetch((actualProxyURI as string), 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
Expand Down Expand Up @@ -1529,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, 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)
Expand Down