Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

AbstractDate::fromString('Expires: 0') fails #103

Closed
bgaillard opened this issue Jan 10, 2017 · 2 comments · Fixed by #107
Closed

AbstractDate::fromString('Expires: 0') fails #103

bgaillard opened this issue Jan 10, 2017 · 2 comments · Fixed by #107
Assignees

Comments

@bgaillard
Copy link

Hi, we developed a custom Zend Event Listener for our Apigility application, this listener adds custom HTTP headers using the MvcEvent::EVENT_ROUTE Zend event.

In our response headers we send an Expires: 0 header, this is to prevent bugs with Internet Explorer which seems to cache our payloads if we do not explicitly provide HTTP headers to disable caching.

When we provided the Expires: 0 HTTP header Zend Http fails with the following exception.


Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (0) at position 0 (0): Unexpected character in D:\workspace\vgm-web-services\vendor\zendframework\zend-http\src\Header\AbstractDate.php:167 Stack trace: 
#0 D:\workspace\vgm-web-services\vendor\zendframework\zend-http\src\Header\AbstractDate.php(167): DateTime->__construct('0', Object(DateTimeZone)) 
#1 D:\workspace\vgm-web-services\vendor\zendframework\zend-http\src\Header\AbstractDate.php(86): Zend\Http\Header\AbstractDate->setDate('0') 
#2 D:\workspace\vgm-web-services\vendor\zendframework\zend-http\src\Headers.php(448): Zend\Http\Header\AbstractDate::fromString('Expires: 0') 
#3 D:\workspace\vgm-web-services\vendor\zendframework\zend-http\src\Headers.php(352): Zend\Http\Headers->lazyLoadHeader(8) 
#4 D:\workspace\vgm-web-services\vendor\zendframework\zend-mvc\src\ResponseSender\AbstractResponseSender.php(30): Zend\Http\Headers->current() 
#5 D:\workspace\vgm-web-services\vendor\zendframework\zend-mvc\src\ResponseSender\PhpEnvironmentRespon in D:\workspace\vgm-web-services\vendor\zendframework\zend-http\src\Header\AbstractDate.php on line 169

As you can see the problem comes from the following instruction.

Zend\Http\Header\AbstractDate::fromString('Expires: 0')

IMO this behavior is not normal because as explained in the RFC https://tools.ietf.org/html/rfc2616#section-14.21 values which are not compliant with the date format must be treated.

HTTP/1.1 clients and caches MUST treat other invalid date formats,
especially including the value "0", as in the past (i.e., "already
expired").

So I think Zend should consider that invalid dates are equivalent to Thu, 01 Jan 1970 00:00:00 GMT.

Do your agree with that ?

Perhaps this issue is also linked to #9.

Thanks

@ezimuel
Copy link
Contributor

ezimuel commented Jan 25, 2017

@bgaillard I just sent the PR #107 to allow Expires: 0.

@ezimuel ezimuel self-assigned this Jan 25, 2017
@bgaillard
Copy link
Author

Hi @ezimuel, ok great thanks for this fix 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants