src/Support/Web/WebRequest.php
/**
     * Returns a callback which parses response headers and populates them into the given `$headers` array.
     *
     * @param array $headers
     * @param string[] $httpVersion
     * @return callback
     */
Returns a callback which parses response headers and populates them into the given `$headers` array.
@param array $headers
@param string[] $httpVersion
@return callback
Returns a callback which parses response headers and populates them into the given ` $headers ` array . @param array $headers @param string [] $httpVersion @return callback
protected function createHeaderParser(&$headers, &$httpVersion, &$httpMessage) {
        return (function($handle, $header) use (&$headers, &$httpVersion, &$httpMessage) {
            $length = strlen($header);
            $header = explode(':', $header, 2);
            if (count($header) < 2) {
                if (preg_match('/^HTTP\/([\d\.]+)\s*(.*)$/i', $header[0], $matches)) {
                    $httpVersion = $matches[1];
                    $httpMessage = trim($matches[2]);
                    if ($this->customHeaderFunction) {
                        $callable = $this->customHeaderFunction;
                        $callable(self::HEADER_STATUS, (int) preg_replace('/[^0-9]/', '', $httpMessage), null);
                    }
                }
                return $length;
            }
            $headerName = strtolower(trim($header[0]));
            $headerValue = trim($header[1]);
            if (!isset($headers[$headerName])) {
                $headers[$headerName] = $headerValue;
            }
            else {
                if (!is_array($headers[$headerName])) {
                    $headers[$headerName] = [$headers[$headerName]];
                }
                $headers[$headerName][] = $headerValue;
            }
            if ($this->customHeaderFunction) {
                $callable = $this->customHeaderFunction;
                $callable(self::HEADER_LINE, $headerName, $headerValue);
            }
            return $length;
        });
    }
protected function createHeaderParser ( & $ headers , & $ httpVersion , & $ httpMessage ) { return ( function ( $ handle , $ header ) use ( & $ headers , & $ httpVersion , & $ httpMessage ) { $ length = strlen ( $ header ) ; $ header = explode ( ':' , $ header , 2 ) ; if ( count ( $ header ) < 2 ) { if ( preg_match ( '/^HTTP\/([\d\.]+)\s*(.*)$/i' , $ header [ 0 ] , $ matches ) ) { $ httpVersion = $ matches [ 1 ] ; $ httpMessage = trim ( $ matches [ 2 ] ) ; if ( $ this -> customHeaderFunction ) { $ callable = $ this -> customHeaderFunction ; $ callable ( self :: HEADER_STATUS , ( int ) preg_replace ( '/[^0-9]/' , '' , $ httpMessage ) , null ) ; } } return $ length ; } $ headerName = strtolower ( trim ( $ header [ 0 ] ) ) ; $ headerValue = trim ( $ header [ 1 ] ) ; if ( ! isset ( $ headers [ $ headerName ] ) ) { $ headers [ $ headerName ] = $ headerValue ; } else { if ( ! is_array ( $ headers [ $ headerName ] ) ) { $ headers [ $ headerName ] = [ $ headers [ $ headerName ] ] ; } $ headers [ $ headerName ] [ ] = $ headerValue ; } if ( $ this -> customHeaderFunction ) { $ callable = $ this -> customHeaderFunction ; $ callable ( self :: HEADER_LINE , $ headerName , $ headerValue ) ; } return $ length ; } ) ; }
Returns a callback which parses response headers and populates them into the given `$headers` array.
Returns a callback which parses response headers and populates them into the given ` $headers ` array .