Allows for the mini profiler in the back office (again)

This commit is contained in:
Shannon
2017-06-29 01:04:20 +10:00
parent 923ceadd02
commit 7ca7b6f922
6 changed files with 85 additions and 13 deletions

View File

@@ -96,7 +96,18 @@ angular.module('umbraco.security.interceptor')
});
};
}])
//used to set headers on all requests where necessary
.factory('umbracoRequestInterceptor', function ($q, queryStrings) {
return {
//dealing with requests:
'request': function(config) {
if (queryStrings.getParams().umbDebug === "true" || queryStrings.getParams().umbdebug === "true") {
config.headers["X-UMB-DEBUG"] = "true";
}
return config;
}
};
})
.value('requestInterceptorFilter', function() {
return ["www.gravatar.com"];
})
@@ -104,4 +115,5 @@ angular.module('umbraco.security.interceptor')
// We have to add the interceptor to the queue as a string because the interceptor depends upon service instances that are not available in the config block.
.config(['$httpProvider', function ($httpProvider) {
$httpProvider.responseInterceptors.push('securityInterceptor');
$httpProvider.interceptors.push('umbracoRequestInterceptor');
}]);

View File

@@ -574,7 +574,32 @@ function umbPropEditorHelper() {
}
angular.module('umbraco.services').factory('umbPropEditorHelper', umbPropEditorHelper);
/**
* @ngdoc service
* @name umbraco.services.queryStrings
* @description A helper used to get query strings in the real URL (not the hash URL)
**/
function queryStrings($window) {
var pl = /\+/g; // Regex for replacing addition symbol with a space
var search = /([^&=]+)=?([^&]*)/g;
var decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); };
return {
getParams: function () {
var match;
var query = $window.location.search.substring(1);
var urlParams = {};
while (match = search.exec(query)) {
urlParams[decode(match[1])] = decode(match[2]);
}
return urlParams;
}
};
}
angular.module('umbraco.services').factory('queryStrings', queryStrings);

View File

@@ -1,13 +1,16 @@
/** Executed when the application starts, binds to events and set global state */
app.run(['userService', '$log', '$rootScope', '$location', 'navigationService', 'appState', 'editorState', 'fileManager', 'assetsService', 'eventsService', '$cookies', '$templateCache', 'localStorageService',
function (userService, $log, $rootScope, $location, navigationService, appState, editorState, fileManager, assetsService, eventsService, $cookies, $templateCache, localStorageService) {
app.run(['userService', '$log', '$rootScope', '$location', 'queryStrings', 'navigationService', 'appState', 'editorState', 'fileManager', 'assetsService', 'eventsService', '$cookies', '$templateCache', 'localStorageService',
function (userService, $log, $rootScope, $location, queryStrings, navigationService, appState, editorState, fileManager, assetsService, eventsService, $cookies, $templateCache, localStorageService) {
//This sets the default jquery ajax headers to include our csrf token, we
// need to user the beforeSend method because our token changes per user/login so
// it cannot be static
$.ajaxSetup({
beforeSend: function (xhr) {
xhr.setRequestHeader("X-XSRF-TOKEN", $cookies["XSRF-TOKEN"]);
xhr.setRequestHeader("X-XSRF-TOKEN", $cookies["XSRF-TOKEN"]);
if (queryStrings.getParams().umbDebug === "true" || queryStrings.getParams().umbdebug === "true") {
xhr.setRequestHeader("X-UMB-DEBUG", "true");
}
}
});

View File

@@ -84,6 +84,7 @@
@if (isDebug)
{
<script type="text/javascript" src="lib/jquery/jquery.min.js"></script>
@Html.RenderProfiler()
}

View File

@@ -26,7 +26,24 @@
}
};
}
if (!window.location.search.getParams) {
var pl = /\+/g; // Regex for replacing addition symbol with a space
var search = /([^&=]+)=?([^&]*)/g;
var decode = function(s) { return decodeURIComponent(s.replace(pl, " ")); };
window.location.search.getParams = function() {
var match;
var query = window.location.search.substring(1);
var urlParams = {};
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
return urlParams;
}
}
if (!String.prototype.startsWith) {
String.prototype.startsWith = function (str) {
///<summary>startsWith extension method for string</summary>
@@ -366,10 +383,20 @@
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length === 2) return parts.pop().split(";").shift();
if (parts.length === 2)
return parts.pop().split(";").shift();
return null;
}
xhr.setRequestHeader("X-XSRF-TOKEN", getCookie("XSRF-TOKEN"));
var cookieVal = getCookie("XSRF-TOKEN");
if (cookieVal) {
xhr.setRequestHeader("X-XSRF-TOKEN", cookieVal);
}
var queryString = window.location.search.getParams();
if (queryString.umbDebug === "true") {
xhr.setRequestHeader("X-UMB-DEBUG", cookieVal);
}
}
});

View File

@@ -99,13 +99,17 @@ namespace Umbraco.Web.Profiling
if (request.Success == false || request.Result.Url.IsClientSideRequest())
return false;
if (string.IsNullOrEmpty(request.Result.QueryString["umbDebug"]))
return false;
//if there is an umbDebug query string than profile it
bool umbDebug;
if (string.IsNullOrEmpty(request.Result.QueryString["umbDebug"]) == false && bool.TryParse(request.Result.QueryString["umbDebug"], out umbDebug))
return true;
if (request.Result.Url.IsBackOfficeRequest(HttpRuntime.AppDomainAppVirtualPath))
return false;
//if there is an umbDebug header than profile it
if (string.IsNullOrEmpty(request.Result.Headers["X-UMB-DEBUG"]) == false && bool.TryParse(request.Result.Headers["X-UMB-DEBUG"], out umbDebug))
return true;
return true;
//everything else is ok to profile
return false;
}
/// <summary>