|
77 | 77 | });
|
78 | 78 | }
|
79 | 79 |
|
| 80 | + const setCookie = function (name, value, days) { |
| 81 | + var exp = new Date(); |
| 82 | + exp.setTime(exp.getTime() + (days * 24 * 60 * 60 * 1000)); |
| 83 | + document.cookie = name + '=' + value + '; expires=' + exp.toGMTString() + '; path=/; SameSite=Lax'; |
| 84 | + }; |
| 85 | +
|
| 86 | + const getCookie = function (name) { |
| 87 | + var prefix = name + '='; |
| 88 | + var cookieStartIndex = document.cookie.indexOf(prefix); |
| 89 | + var cookieEndIndex; |
| 90 | +
|
| 91 | + if (cookieStartIndex == -1) { |
| 92 | + return null; |
| 93 | + } |
| 94 | +
|
| 95 | + cookieEndIndex = document.cookie.indexOf(';', cookieStartIndex + prefix.length); |
| 96 | + if (cookieEndIndex == -1) { |
| 97 | + cookieEndIndex = document.cookie.length; |
| 98 | + } |
| 99 | +
|
| 100 | + return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex)); |
| 101 | + }; |
| 102 | +
|
80 | 103 | var request = function(url, onSuccess, onError, payload, options, tries) {
|
81 | 104 | var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
|
82 | 105 | options = options || {};
|
|
88 | 111 | xhr.open(options.method || 'GET', url, true);
|
89 | 112 | xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
90 | 113 | xhr.onreadystatechange = function(state) {
|
| 114 | + if (xdebugCookieValue !== null) { |
| 115 | + setCookie('XDEBUG_SESSION', xdebugCookieValue, 365); |
| 116 | + } |
| 117 | +
|
91 | 118 | if (4 !== xhr.readyState) {
|
92 | 119 | return null;
|
93 | 120 | }
|
|
114 | 141 | options.onSend(tries);
|
115 | 142 | }
|
116 | 143 |
|
| 144 | + var xdebugCookieValue = getCookie('XDEBUG_SESSION'); |
| 145 | + if (xdebugCookieValue !== null) { |
| 146 | + setCookie('XDEBUG_SESSION', null, -1); |
| 147 | + } |
| 148 | +
|
117 | 149 | xhr.send(payload || '');
|
118 | 150 | };
|
119 | 151 |
|
|
0 commit comments