From fa23fd0147147677ec3c8a5a192321f75e55885f Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 29 Jun 2022 09:57:54 +0800 Subject: [PATCH] Add the `X-Requested-With` header to Swagger requests. --- .../wwwroot/swagger/ui/abp.swagger.js | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js b/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js index 249f75ebb0..c143b7e75e 100644 --- a/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js +++ b/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js @@ -1,24 +1,23 @@ var abp = abp || {}; -(function () { +(function() { - abp.SwaggerUIBundle = function (configObject) { + abp.SwaggerUIBundle = function(configObject) { var excludeUrl = ["swagger.json", "connect/token"] var firstRequest = true; abp.appPath = configObject.baseUrl || abp.appPath; var requestInterceptor = configObject.requestInterceptor; - - configObject.requestInterceptor = async function (request) { - if(request.url.includes(excludeUrl[1])){ + configObject.requestInterceptor = async function(request) { + + if (request.url.includes(excludeUrl[1])) { firstRequest = true; } - if(firstRequest && !excludeUrl.some(url => request.url.includes(url))) - { - await fetch(`${abp.appPath}abp/Swashbuckle/SetCsrfCookie`,{ + if (firstRequest && !excludeUrl.some(url => request.url.includes(url))) { + await fetch(`${abp.appPath}abp/Swashbuckle/SetCsrfCookie`, { headers: request.headers }); firstRequest = false; @@ -28,8 +27,12 @@ var abp = abp || {}; if (antiForgeryToken) { request.headers[abp.security.antiForgery.tokenHeaderName] = antiForgeryToken; } - - if(requestInterceptor){ + + if (!request.headers["X-Requested-With"]) { + request.headers["X-Requested-With"] = "XMLHttpRequest"; + } + + if (requestInterceptor) { requestInterceptor(request); } return request;