Multiple date response header using symfony 5

I’m developing with Symfony 5 and I’m receiving two times the response header ‘Date’ in my Homepage:

Cache-Control: no-cache, private
Connection: close
Content-Type: text/html; charset=UTF-8
Date: Wed, 02 Dec 2020 10:21:57 GMT
Date: Wed, 02 Dec 2020 10:21:57 GMT
Host: localhost:8000
X-Debug-Token: a91210
X-Debug-Token-Link: http://localhost:8000/_profiler/a91210
X-Powered-By: PHP/7.4.9
X-Robots-Tag: noindex

This makes my code not working and I can’t get why there is two times the ‘Date’, do you know where this could come from?

Here is a sample of my code:

Html:

...
<span id="server_date">  </span>
...

JavaScript:

$(function () {
  $.ajax({
    type: 'GET',
    cache: false,
    url: location.href,
    complete: function (req, textStatus) {
      var dateString = req.getResponseHeader('Date');
      if (dateString.indexOf('GMT') === -1) {
        dateString += ' GMT';
      }
      var date = new Date(dateString);
      $('#server_date').text(date);
    }
  });
});

As there is two date response header, "dateString" is equal to "Wed, 02 Dec 2020 10:21:57 GMT, Wed, 02 Dec 2020 10:21:57 GMT" and thus "var date = new Date(dateString);" returns invalid date.

Thanks for help!

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *