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

"Content-Length" header set to "0" returns header line without value #26

Closed
curzio-della-santa opened this issue Oct 12, 2015 · 1 comment · Fixed by #87
Closed

"Content-Length" header set to "0" returns header line without value #26

curzio-della-santa opened this issue Oct 12, 2015 · 1 comment · Fixed by #87

Comments

@curzio-della-santa
Copy link

Hi

Setting the "Content-Length" header to 0, will return an empty header line Content-Length: in the response.
This might break CORS preflight requests processed by load-balancers (e.g. on fortrabbit).

Problem is located in the \Zend\Http\Header\ContentLength constructor, that does not sets the $value property if 0 is passed.

Issue can be fixed in \Zend\Http\Header\ContentLength either:

  • changing the constructor behavior (accepting 0 or '0' as value):
    from if ($value) { to if ($value !== null) {
    Note: all other classes in the Zend\Http\Header namespace have the same similar (buggy?) constructor (except GenericHeader).

  • changing the getFieldValue method to:

      public function getFieldValue()
      {
          return $this->value ?: 0;
      }

As soon as fixed I recommend to change the requirement of "zfr/zfr-cors" to the newest version of "zendframework/zend-http"

Kind regards,
Curzio

@curzio-della-santa
Copy link
Author

Until a fix will be provided for this issue, we have created a dedicated Zf2 module as temporary fix.

This registers a new listener in the MvcEvent::EVENT_FINISH event, to fix (substitute) the incorrect header just before response is returned.

Kind regards,
Curzio

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.

1 participant