public static function encode($content, TcpConnection $connection)
    {
        // Default http-code.
        if (!isset(HttpCache::$header['Http-Code'])) {
            $header = "HTTP/1.1 200 OK\r\n";
        } else {
            $header = HttpCache::$header['Http-Code'] . "\r\n";
            unset(HttpCache::$header['Http-Code']);
        }

        // Content-Type
        if (!isset(HttpCache::$header['Content-Type'])) {
            $header .= "Content-Type: text/html;charset=utf-8\r\n";
        }

        // other headers
        foreach (HttpCache::$header as $key => $item) {
            if ('Set-Cookie' === $key && is_array($item)) {
                foreach ($item as $it) {
                    $header .= $it . "\r\n";
                }
            } else {
                $header .= $item . "\r\n";
            }
        }
		if(HttpCache::$gzip && isset($connection->gzip) && $connection->gzip){
			$header .= "Content-Encoding: gzip\r\n";
			$content = gzencode($content,$connection->gzip);
		}
        // header
        $header .= "Server: workerman/" . Worker::VERSION . "\r\nContent-Length: " . strlen($content) . "\r\n\r\n";

        // save session
        self::sessionWriteClose();

        // the whole http package
        return $header . $content;
    }
public static function encode($content, TcpConnection $connection)
    {
        // Default http-code.
        if (!isset(HttpCache::$header['Http-Code'])) {
            $header = "HTTP/1.1 200 OK\r\n";
        } else {
            $header = HttpCache::$header['Http-Code'] . "\r\n";
            unset(HttpCache::$header['Http-Code']);
        }

        // Content-Type
        if (!isset(HttpCache::$header['Content-Type'])) {
            $header .= "Content-Type: text/html;charset=utf-8\r\n";
        }

        // other headers
        foreach (HttpCache::$header as $key => $item) {
            if ('Set-Cookie' === $key && is_array($item)) {
                foreach ($item as $it) {
                    $header .= $it . "\r\n";
                }
            } else {
                $header .= $item . "\r\n";
            }
        }
		if(HttpCache::$gzip && isset($connection->gzip) && $connection->gzip){
			$header .= "Content-Encoding: gzip\r\n";
			$content = gzencode($content,$connection->gzip);
		}
        // header
        $header .= "Server: workerman/" . Worker::VERSION . "\r\nContent-Length: " . strlen($content) . "\r\n\r\n";

        // save session
        self::sessionWriteClose();

        // the whole http package
        return $header . $content;
    }
public static function encode ( $ content , TcpConnection $ connection ) { // Default http-code. if ( ! isset ( HttpCache :: $ header [ 'Http-Code' ] ) ) { $ header = "HTTP/1.1 200 OK\r\n" ; } else { $ header = HttpCache :: $ header [ 'Http-Code' ] . "\r\n" ; unset ( HttpCache :: $ header [ 'Http-Code' ] ) ; } // Content-Type if ( ! isset ( HttpCache :: $ header [ 'Content-Type' ] ) ) { $ header .= "Content-Type: text/html;charset=utf-8\r\n" ; } // other headers foreach ( HttpCache :: $ header as $ key => $ item ) { if ( 'Set-Cookie' === $ key && is_array ( $ item ) ) { foreach ( $ item as $ it ) { $ header .= $ it . "\r\n" ; } } else { $ header .= $ item . "\r\n" ; } } if ( HttpCache :: $ gzip && isset ( $ connection -> gzip ) && $ connection -> gzip ) { $ header .= "Content-Encoding: gzip\r\n" ; $ content = gzencode ( $ content , $ connection -> gzip ) ; } // header $ header .= "Server: workerman/" . Worker :: VERSION . "\r\nContent-Length: " . strlen ( $ content ) . "\r\n\r\n" ; // save session self :: sessionWriteClose ( ) ; // the whole http package return $ header . $ content ; }
Http encode.

@param string        $content
@param TcpConnection $connection
@return string
Http encode .