コード例 #1
0
ファイル: MPNSResponse.php プロジェクト: rubendgr/lunr
 /**
  * Parse response header information.
  *
  * @param \http\Header $header      Instance of a Header class.
  * @param String       $result      Response result
  * @param Integer      $header_size Size of the header
  *
  * @return void
  */
 private function parse_headers($header, $result, $header_size)
 {
     $this->headers = $header->parse(substr($result, 0, $header_size));
     if (in_array($this->http_code, [400, 401, 405, 503])) {
         $this->headers['X-Notificationstatus'] = 'N/A';
         $this->headers['X-Deviceconnectionstatus'] = 'N/A';
         $this->headers['X-Subscriptionstatus'] = 'N/A';
     } elseif ($this->http_code === 412) {
         $this->headers['X-Subscriptionstatus'] = 'N/A';
     }
 }
コード例 #2
0
 /**
  * Parses a HTTP header string into an associative array
  *
  * @param   string   $header_string  Header string to parse
  * @return  HTTP_Header
  */
 public static function parse_header_string($header_string)
 {
     // If the PECL HTTP extension is loaded
     if (extension_loaded('http')) {
         // Use the fast method to parse header string
         $headers = version_compare(phpversion('http'), '2.0.0', '>=') ? \http\Header::parse($header_string) : http_parse_headers($header_string);
         return new HTTP_Header($headers);
     }
     // Otherwise we use the slower PHP parsing
     $headers = array();
     // Match all HTTP headers
     if (preg_match_all('/(\\w[^\\s:]*):[ ]*([^\\r\\n]*(?:\\r\\n[ \\t][^\\r\\n]*)*)/', $header_string, $matches)) {
         // Parse each matched header
         foreach ($matches[0] as $key => $value) {
             // If the header has not already been set
             if (!isset($headers[$matches[1][$key]])) {
                 // Apply the header directly
                 $headers[$matches[1][$key]] = $matches[2][$key];
             } else {
                 // If the entry is an array
                 if (is_array($headers[$matches[1][$key]])) {
                     // Apply the new entry to the array
                     $headers[$matches[1][$key]][] = $matches[2][$key];
                 } else {
                     $headers[$matches[1][$key]] = array($headers[$matches[1][$key]], $matches[2][$key]);
                 }
             }
         }
     }
     // Return the headers
     return new HTTP_Header($headers);
 }
コード例 #3
0
ファイル: WebRequestParser.php プロジェクト: rubendgr/lunr
 /**
  * Negotiate & retrieve the clients prefered charset.
  *
  * @param Array $supported Array containing the supported charsets
  *
  * @return Mixed $return The best match of the prefered charsets or NULL if
  *                       there are no supported charsets or the header is not set
  */
 public function parse_accept_charset($supported = [])
 {
     if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
         $this->header->name = 'Accept-Charset';
         $this->header->value = $_SERVER['HTTP_ACCEPT_CHARSET'];
         return $this->header->negotiate($supported);
     }
     return NULL;
 }
コード例 #4
0
ファイル: Header.php プロジェクト: skeetr/skeetr
 /**
  * Send a raw HTTP header.
  *
  * @link http://www.php.net/manual/en/function.header.php
  *
  * @param  string  $string             The header string.
  * @param  boolean $replace            (optional) The optional replace parameter indicates whether the header should replace a previous similar header, or add a second header of the same type.
  * @param  boolean $http_response_code (optional) Forces the HTTP response code to the specified value.
  * @return boolean
  */
 public static final function header($string, $replace = true, $http_response_code = null)
 {
     if (!($headers = http\Header::parse($string))) {
         Returns;
     }
     $header = key($headers);
     if ($replace || !isset(self::$list[$header])) {
         self::$list[$header] = array();
     }
     self::$list[$header][] = $string;
     if (strtolower($header) == 'location') {
         $http_response_code = 302;
     }
     if ($http_response_code) {
         self::$code = $http_response_code;
     }
 }
コード例 #5
0
 public static function parse_header_string($header_string)
 {
     if (extension_loaded("http")) {
         $headers = version_compare(phpversion("http"), "2.0.0", ">=") ? \http\Header::parse($header_string) : http_parse_headers($header_string);
         return new HTTP_Header($headers);
     }
     $headers = array();
     if (preg_match_all('/(\\w[^\\s:]*):[ ]*([^\\r\\n]*(?:\\r\\n[ \\t][^\\r\\n]*)*)/', $header_string, $matches)) {
         foreach ($matches[0] as $key => $value) {
             if (!isset($headers[$matches[1][$key]])) {
                 $headers[$matches[1][$key]] = $matches[2][$key];
             } else {
                 if (is_array($headers[$matches[1][$key]])) {
                     $headers[$matches[1][$key]][] = $matches[2][$key];
                 } else {
                     $headers[$matches[1][$key]] = array($headers[$matches[1][$key]], $matches[2][$key]);
                 }
             }
         }
     }
     return new HTTP_Header($headers);
 }
コード例 #6
0
ファイル: CliRequestParser.php プロジェクト: rubendgr/lunr
 /**
  * Negotiate & retrieve the clients prefered charset.
  *
  * @param Array $supported Array containing the supported charsets
  *
  * @return Mixed $return The best match of the prefered charsets or NULL if
  *                       there are no supported charsets or the header is not set
  */
 public function parse_accept_charset($supported = [])
 {
     $this->header->name = 'Accept-Charset';
     $this->header->value = $this->ast['accept-charset'][0];
     return $this->header->negotiate($supported);
 }
コード例 #7
0
ファイル: SoapClientResponse.php プロジェクト: mheydt/scalr
 /**
  * Constructor
  *
  * @param   string $response
  */
 public function __construct($response, $responseHeaders, $request)
 {
     $this->response = $response;
     $this->responseHeaders = Header::parse($responseHeaders);
     $this->request = $request;
 }
コード例 #8
0
ファイル: Response.php プロジェクト: skeetr/skeetr
 /**
  * Add headers. If append is true, headers with the same name will be separated,
  * else overwritten.
  *
  * @param string $header just a string with the header
  * @param array  $append if true, and a header of the same type allready exists will
  *                      append, if false will be replaced.
  * @return boolean Returns TRUE on success or FALSE on failure.
  */
 public function addHeader($header, $append = false)
 {
     if (!($headers = Header::parse($header))) {
         return false;
     }
     return $this->addHeaders($headers, $append);
 }
コード例 #9
0
ファイル: ZombieJS.php プロジェクト: pfz/codeception
    /**
     * @param string $url The URL to make HEAD request to
     * @return array Header-Name => Value array
     */
    public function headRequest($url)
    {
        $headers = $this->server->evalJS(sprintf(<<<JS
        var http = new browser.window.XMLHttpRequest();
        http.open('HEAD', '%s');
        http.onreadystatechange = function(){
            stream.end(http.getAllResponseHeaders());
        };
        http.send(null);
JS
, addslashes($url)));
        if (method_exists('\\http\\Header', 'parse')) {
            return \http\Header::parse(str_replace("\n", "\r\n", $headers));
        } else {
            return http_parse_headers(str_replace("\n", "\r\n", $headers));
        }
    }