示例#1
0
文件: Request.php 项目: fobiaweb/slim
 /**
  * Get Scheme (https or http)
  *
  * @return string
  * @api
  */
 public function getScheme()
 {
     $isHttps = false;
     if ($this->headers->has('X_FORWARDED_PROTO') === true) {
         $headerValue = $this->headers->get('X_FORWARDED_PROTO');
         $isHttps = strtolower($headerValue) === 'https';
     } else {
         $headerValue = $this->env->get('HTTPS');
         $isHttps = empty($headerValue) === false && $headerValue !== 'off';
     }
     return $isHttps ? 'https' : 'http';
 }
示例#2
0
 /**
  * Does this request have a given header?
  *
  * @param  string $name
  * @return bool
  * @api
  */
 public function hasHeader($name)
 {
     return $this->headers->has($name);
 }
示例#3
0
文件: Cookies.php 项目: fobiaweb/slim
 /**
  * Delete HTTP cookie header
  *
  * This method will construct and set the HTTP `Set-Cookie` header to invalidate
  * a client-side HTTP cookie. If a cookie with the same name (and, optionally, domain)
  * is already set in the HTTP response, it will also be removed. Slim uses this method
  * instead of PHP's native `setcookie` method. This allows more control of the HTTP header
  * irrespective of PHP's native implementation's dependency on PHP versions.
  *
  * This method accepts the \Slim\Http\Headers object by reference as its
  * first argument; this method directly modifies this object instead of
  * returning a value.
  *
  * @param \Slim\Interfaces\Http\HeadersInterface $headers
  * @param string                                 $name
  * @param array                                  $value
  * @api
  */
 public function deleteHeader(HeadersInterface &$headers, $name, $value = array())
 {
     $crumbs = $headers->has('Set-Cookie') ? explode("\n", $headers->get('Set-Cookie')) : array();
     $cookies = array();
     foreach ($crumbs as $crumb) {
         if (isset($value['domain']) && $value['domain']) {
             $regex = sprintf('@%s=.*domain=%s@', urlencode($name), preg_quote($value['domain']));
         } else {
             $regex = sprintf('@%s=@', urlencode($name));
         }
         if (preg_match($regex, $crumb) === 0) {
             $cookies[] = $crumb;
         }
     }
     if (!empty($cookies)) {
         $headers->set('Set-Cookie', implode("\n", $cookies));
     } else {
         $headers->remove('Set-Cookie');
     }
     $this->setHeader($headers, $name, array_merge(array('value' => '', 'path' => null, 'domain' => null, 'expires' => time() - 100), $value));
 }