From b77991f69b22f590518f41f5a0f44e80155ab0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 14 Apr 2017 16:00:52 +0200 Subject: [PATCH] refactoring: minor changes to #8122 --- public/app/core/services/backend_srv.ts | 43 ++++++++++++++----------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts index cc52de4147c..3159e87882b 100644 --- a/public/app/core/services/backend_srv.ts +++ b/public/app/core/services/backend_srv.ts @@ -63,17 +63,20 @@ export class BackendSrv { request(options) { options.retry = options.retry || 0; - var requestIsLocal = options.url.indexOf('/') === 0; + var requestIsLocal = !options.url.match(/^http/); var firstAttempt = options.retry === 0; - if (!options.url.match('https?://') && this.contextSrv && this.contextSrv.user && this.contextSrv.user.orgId) { - options.headers = options.headers || {}; - options.headers['X-Grafana-Org-Id'] = this.contextSrv.user.orgId; - } - if (requestIsLocal && !options.hasSubUrl) { - options.url = config.appSubUrl + options.url; - options.hasSubUrl = true; + if (requestIsLocal) { + if (this.contextSrv.user && this.contextSrv.user.orgId) { + options.headers = options.headers || {}; + options.headers['X-Grafana-Org-Id'] = this.contextSrv.user.orgId; + } + + if (!options.hasSubUrl) { + options.url = config.appSubUrl + options.url; + options.hasSubUrl = true; + } } return this.$http(options).then(results => { @@ -130,21 +133,23 @@ export class BackendSrv { this.addCanceler(requestId, canceler); } - var requestIsLocal = options.url.indexOf('/') === 0; + var requestIsLocal = !options.url.match(/^http/); var firstAttempt = options.retry === 0; - if (!options.url.match('https?://') && this.contextSrv && this.contextSrv.user && this.contextSrv.user.orgId) { - options.headers = options.headers || {}; - options.headers['X-Grafana-Org-Id'] = this.contextSrv.user.orgId; - } + if (requestIsLocal) { + if (this.contextSrv.user && this.contextSrv.user.orgId) { + options.headers = options.headers || {}; + options.headers['X-Grafana-Org-Id'] = this.contextSrv.user.orgId; + } - if (requestIsLocal && !options.hasSubUrl && options.retry === 0) { - options.url = config.appSubUrl + options.url; - } + if (!options.hasSubUrl && options.retry === 0) { + options.url = config.appSubUrl + options.url; + } - if (requestIsLocal && options.headers && options.headers.Authorization) { - options.headers['X-DS-Authorization'] = options.headers.Authorization; - delete options.headers.Authorization; + if (options.headers && options.headers.Authorization) { + options.headers['X-DS-Authorization'] = options.headers.Authorization; + delete options.headers.Authorization; + } } return this.$http(options).catch(err => {