Ejemplo n.º 1
0
 /**
  * The following headers are always modified:
  *
  * - `Cache-Control`: sets _cacheable_ to _public_.
  * - `Expires`: is set to "+1 month".
  *
  * If the status code is {@link Stauts::NOT_MODIFIED} the following headers are unset:
  *
  * - `Content-Type`
  * - `Content-Length`
  *
  * Otherwise, the following header is set:
  *
  * - `Content-Type`:
  *
  * @inheritdoc
  */
 protected function finalize(Headers &$headers, &$body)
 {
     parent::finalize($headers, $body);
     $status = $this->status->code;
     $expires = $this->expires;
     $headers['Expires'] = $expires;
     $headers['Cache-Control']->cacheable = 'public';
     $headers['Cache-Control']->max_age = $expires->timestamp - DateTime::now()->timestamp;
     $headers['Content-Type'] = $this->content_type;
     $headers['Etag'] = $this->etag;
     if ($status === Status::NOT_MODIFIED) {
         $this->finalize_for_not_modified($headers);
         return;
     }
     if ($status === Status::PARTIAL_CONTENT) {
         $this->finalize_for_partial_content($headers);
         return;
     }
     $this->finalize_for_other($headers);
 }
Ejemplo n.º 2
0
 /**
  * If `$body` is null the function does nothing.
  *
  * If {@link $rc} is a closure `$body` is set to {@link $rc}.
  *
  * Otherwise a JSON string is created with the message, errors and {@link $metas} of the
  * response. If the response is successful the {@link $rc} property is also present. This JSON
  * string is set in `$body`. The `Content-Type` header field is set to
  * "application/json" and the `Content-Length` header field is set to the length of the JSON
  * string.
  *
  * @inheritdoc
  */
 protected function finalize(Headers &$headers, &$body)
 {
     parent::finalize($headers, $body);
     if ($body !== null) {
         return;
     }
     $rc = $this->rc;
     # streaming
     if ($rc instanceof \Closure) {
         $body = $rc;
         return;
     }
     $this->finalize_as_json($this->finalize_as_array($rc), $headers, $body);
 }