1window.sp = {}; 2 3const http = { 4 headers: { 5 csrfToken: 'X-CSRF-TOKEN', 6 }, 7 methods: { 8 GET: 'GET', 9 POST: 'POST', 10 }, 11 csrfToken: $('meta[name="csrf-token"]').attr('content') 12}; 13 14http.request = function(method, options) { 15 let xhrOptions = Object.assign({}, options, { 16 method, 17 }); 18 19 if (method === http.methods.POST) { 20 xhrOptions['headers'] = xhrOptions['headers'] ?? []; 21 xhrOptions.headers[http.headers.csrfToken] = http.csrfToken; 22 } 23 24 return $.ajax(xhrOptions); 25}; 26 27http.get = options => http.request(http.methods.GET, options); 28http.post = options => http.request(http.methods.POST, options); 29 30/** 31 * Summarises a failed request for the error logger. 32 * 33 * Never include the response body: when an intermediary (proxy, firewall, error page) 34 * answers instead of the application, that body is markup, and posting it back to the 35 * logger gets the report itself blocked - see APP-22751. 36 */ 37http.describeFailure = function(jqXHR, textStatus, errorThrown) { 38 jqXHR = jqXHR || {}; 39 40 return { 41 status: jqXHR.status, 42 statusText: jqXHR.statusText, 43 readyState: jqXHR.readyState, 44 contentType: 45 typeof jqXHR.getResponseHeader === 'function' 46 ? jqXHR.getResponseHeader('content-type') 47 : null, 48 responseLength: (jqXHR.responseText || '').length, 49 textStatus: textStatus, 50 // on a parse failure jQuery throws a SyntaxError whose message quotes the offending 51 // body, so this has to be bounded and stripped of markup like everything else here 52 errorThrown: String(errorThrown || '') 53 .replace(/[<>]/g, '') 54 .substring(0, 200) 55 }; 56}; 57 58window.sp.http = http; 59
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.