public function header($s, $replace = true, $code = false)
    {
        if ($code) {
            $this->status($code);
        }

        if ($this->headers_sent) {
            throw new RequestHeadersAlreadySent;
        }
        $s = strtr($s, "\r\n", '  ');

        $e = explode(':', $s, 2);

        if (!isset($e[1])) {
            $e[0] = 'STATUS';

            if (strncmp($s, 'HTTP/', 5) === 0) {
                $s = substr($s, 9);
            }
        }

        $k = strtr(strtoupper($e[0]), Generic::$htr);

        if ($k === 'CONTENT_TYPE') {
            Generic::parseStr(strtolower($e[1]), $ctype, true);
            if (!isset($ctype['charset'])) {
                $ctype['charset'] = $this->upstream->pool->config->defaultcharset->value;

                $s = $e[0] . ': ';
                $i = 0;
                foreach ($ctype as $k => $v) {
                    $s .= ($i > 0 ? '; ' : '') . $k . ($v !== '' ? '=' . $v : '');
                    ++$i;
                }
            }
        }
        if ($k === 'SET_COOKIE') {
            $k .= '_' . ++$this->cookieNum;
        } elseif (!$replace && isset($this->headers[$k])) {
            return false;
        }

        $this->headers[$k] = $s;

        if ($k === 'CONTENT_LENGTH') {
            $this->contentLength = (int)$e[1];
        } elseif ($k === 'LOCATION') {
            $this->status(301);
        }

        if (Daemon::$compatMode) {
            is_callable('header_native') ? header_native($s) : header($s);
        }

        return true;
    }
public function header($s, $replace = true, $code = false)
    {
        if ($code) {
            $this->status($code);
        }

        if ($this->headers_sent) {
            throw new RequestHeadersAlreadySent;
        }
        $s = strtr($s, "\r\n", '  ');

        $e = explode(':', $s, 2);

        if (!isset($e[1])) {
            $e[0] = 'STATUS';

            if (strncmp($s, 'HTTP/', 5) === 0) {
                $s = substr($s, 9);
            }
        }

        $k = strtr(strtoupper($e[0]), Generic::$htr);

        if ($k === 'CONTENT_TYPE') {
            Generic::parseStr(strtolower($e[1]), $ctype, true);
            if (!isset($ctype['charset'])) {
                $ctype['charset'] = $this->upstream->pool->config->defaultcharset->value;

                $s = $e[0] . ': ';
                $i = 0;
                foreach ($ctype as $k => $v) {
                    $s .= ($i > 0 ? '; ' : '') . $k . ($v !== '' ? '=' . $v : '');
                    ++$i;
                }
            }
        }
        if ($k === 'SET_COOKIE') {
            $k .= '_' . ++$this->cookieNum;
        } elseif (!$replace && isset($this->headers[$k])) {
            return false;
        }

        $this->headers[$k] = $s;

        if ($k === 'CONTENT_LENGTH') {
            $this->contentLength = (int)$e[1];
        } elseif ($k === 'LOCATION') {
            $this->status(301);
        }

        if (Daemon::$compatMode) {
            is_callable('header_native') ? header_native($s) : header($s);
        }

        return true;
    }
public function header ( $ s , $ replace = true , $ code = false ) { if ( $ code ) { $ this -> status ( $ code ) ; } if ( $ this -> headers_sent ) { throw new RequestHeadersAlreadySent ; } $ s = strtr ( $ s , "\r\n" , '  ' ) ; $ e = explode ( ':' , $ s , 2 ) ; if ( ! isset ( $ e [ 1 ] ) ) { $ e [ 0 ] = 'STATUS' ; if ( strncmp ( $ s , 'HTTP/' , 5 ) === 0 ) { $ s = substr ( $ s , 9 ) ; } } $ k = strtr ( strtoupper ( $ e [ 0 ] ) , Generic :: $ htr ) ; if ( $ k === 'CONTENT_TYPE' ) { Generic :: parseStr ( strtolower ( $ e [ 1 ] ) , $ ctype , true ) ; if ( ! isset ( $ ctype [ 'charset' ] ) ) { $ ctype [ 'charset' ] = $ this -> upstream -> pool -> config -> defaultcharset -> value ; $ s = $ e [ 0 ] . ': ' ; $ i = 0 ; foreach ( $ ctype as $ k => $ v ) { $ s .= ( $ i > 0 ? '; ' : '' ) . $ k . ( $ v !== '' ? '=' . $ v : '' ) ; ++ $ i ; } } } if ( $ k === 'SET_COOKIE' ) { $ k .= '_' . ++ $ this -> cookieNum ; } elseif ( ! $ replace && isset ( $ this -> headers [ $ k ] ) ) { return false ; } $ this -> headers [ $ k ] = $ s ; if ( $ k === 'CONTENT_LENGTH' ) { $ this -> contentLength = ( int ) $ e [ 1 ] ; } elseif ( $ k === 'LOCATION' ) { $ this -> status ( 301 ) ; } if ( Daemon :: $ compatMode ) { is_callable ( 'header_native' ) ? header_native ( $ s ) : header ( $ s ) ; } return true ; }
Send the header
@param  string $s Header. Example: 'Location: http://php.net/'
@param  boolean $replace Optional. Replace?
@param  boolean $code Optional. HTTP response code
@throws \PHPDaemon\Request\RequestHeadersAlreadySent
@return boolean          Success
Send the header