@@ -82,10 +82,13 @@ class Response
82
82
*/
83
83
public function __construct ($ content = '' , $ status = 200 , $ headers = array ())
84
84
{
85
+ $ this ->headers = new ResponseHeaderBag ($ headers );
85
86
$ this ->setContent ($ content );
86
87
$ this ->setStatusCode ($ status );
87
88
$ this ->setProtocolVersion ('1.0 ' );
88
- $ this ->headers = new ResponseHeaderBag ($ headers );
89
+ if (!$ this ->headers ->has ('Date ' )) {
90
+ $ this ->setDate (new \DateTime (null , new \DateTimeZone ('UTC ' )));
91
+ }
89
92
$ this ->charset = 'UTF-8 ' ;
90
93
}
91
94
@@ -329,20 +332,24 @@ public function mustRevalidate()
329
332
/**
330
333
* Returns the Date header as a DateTime instance.
331
334
*
332
- * When no Date header is present, the current time is returned.
333
- *
334
335
* @return \DateTime A \DateTime instance
335
336
*
336
337
* @throws \RuntimeException when the header is not parseable
337
338
*/
338
339
public function getDate ()
339
340
{
340
- if (null === $ date = $ this ->headers ->getDate ('Date ' )) {
341
- $ date = new \DateTime (null , new \DateTimeZone ('UTC ' ));
342
- $ this ->headers ->set ('Date ' , $ date ->format ('D, d M Y H:i:s ' ).' GMT ' );
343
- }
341
+ return $ this ->headers ->getDate ('Date ' );
342
+ }
344
343
345
- return $ date ;
344
+ /**
345
+ * Sets the Date header.
346
+ *
347
+ * @param \DateTime $date A \DateTime instance
348
+ */
349
+ public function setDate (\DateTime $ date )
350
+ {
351
+ $ date ->setTimezone (new \DateTimeZone ('UTC ' ));
352
+ $ this ->headers ->set ('Date ' , $ date ->format ('D, d M Y H:i:s ' ).' GMT ' );
346
353
}
347
354
348
355
/**
0 commit comments