Browse Source

Add the `X-Requested-With` header to Swagger requests.

pull/13156/head
maliming 4 years ago
parent
commit
fa23fd0147
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 23
      framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js

23
framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js

@ -1,24 +1,23 @@
var abp = abp || {}; var abp = abp || {};
(function () { (function() {
abp.SwaggerUIBundle = function (configObject) { abp.SwaggerUIBundle = function(configObject) {
var excludeUrl = ["swagger.json", "connect/token"] var excludeUrl = ["swagger.json", "connect/token"]
var firstRequest = true; var firstRequest = true;
abp.appPath = configObject.baseUrl || abp.appPath; abp.appPath = configObject.baseUrl || abp.appPath;
var requestInterceptor = configObject.requestInterceptor; 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; firstRequest = true;
} }
if(firstRequest && !excludeUrl.some(url => request.url.includes(url))) if (firstRequest && !excludeUrl.some(url => request.url.includes(url))) {
{ await fetch(`${abp.appPath}abp/Swashbuckle/SetCsrfCookie`, {
await fetch(`${abp.appPath}abp/Swashbuckle/SetCsrfCookie`,{
headers: request.headers headers: request.headers
}); });
firstRequest = false; firstRequest = false;
@ -28,8 +27,12 @@ var abp = abp || {};
if (antiForgeryToken) { if (antiForgeryToken) {
request.headers[abp.security.antiForgery.tokenHeaderName] = 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); requestInterceptor(request);
} }
return request; return request;

Loading…
Cancel
Save