In the following example, while the same headers setting is used for all four requests, the header is only sent in the first three requests, it is not sent in the fourth request:
const page =
`<html>
<head>
<script src='https://code.jquery.com/jquery-3.6.1.min.js'></script>
</head>
<body>
<script>
var headers = { 'X-Test-Header': 'Test-Header-Value' };
$.ajax('Request_1', { dataType: 'html', headers: headers });
$.ajax('Request_2', { dataType: 'html', crossDomain: true, headers: headers });
$.ajax('Request_3', { dataType: 'script', headers: headers });
$.ajax('Request_4', { dataType: 'script', crossDomain: true, headers: headers });
</script>
</body>
</html>`;
const express = require('express')();
express.get('/', (request, response) => { response.send(page); });
express.get(/^\/Request_[1-4]$/, (request, response) => {
console.log(`${request.path}: ${request.get('X-Test-Header')}`);
response.send(''); });
express.listen(9000);
The server logs:
/Request_1: Test-Header-Value
/Request_2: Test-Header-Value
/Request_3: Test-Header-Value
/Request_4: undefined
Shouldn’t the header also be sent in the fourth request?
In the following example, while the same
headerssetting is used for all four requests, the header is only sent in the first three requests, it is not sent in the fourth request:The server logs:
Shouldn’t the header also be sent in the fourth request?