src/Dispatcher.php
public function terminate(HttpRequest $request, HttpResponse $response)
	{
		$this->dispatcher->notify(new SendResponseEvent($request, self::MASTER_REQUEST, $response, $this));
		
		while(ob_get_level() > 1)
		{
			ob_end_flush();
		}
		
		$buffer = ob_get_level() ? ob_get_clean() : '';
		
		ini_set('default_mimetype', NULL);
		ini_set('default_charset', NULL);
		
		if($response->hasEntity() && !$request->isHead())
		{
			if('gzip' == strtolower($response->getHeader('Content-Encoding', '')))
			{
				ini_set('zlib.output_compression_level', 1);
				ini_set('zlib.output_compression', 4096);
			}
			else
			{
				ob_start(NULL, 4096);
			}
		}
		
		foreach($response->getHeaders() as $n => $headers)
		{
			switch($n)
			{
				case 'server':
				case 'connection':
				case 'content-length':
				case 'content-encoding':
				case 'transfer-encoding':
					continue 2;
			}
			
			foreach($headers as $index => $header)
			{
				header(sprintf('%s: %s', $header[0], $header[1]), $index == 0);
			}
		}
		
		$statusLine = sprintf('%s %u %s', $response->getProtocol(), $response->getStatus(), $response->getReason());
		
		header($statusLine, true, $response->getStatus());
		
		if($response->hasEntity() && !$request->isHead())
		{
			$stream = new UrlStream('php://output', 'wb');
			
			try
			{
				$response->getEntity()->send($stream);
			}
			finally
			{
				$stream->close();
			}
		}
		
		if(function_exists('fastcgi_finish_request'))
		{
			@fastcgi_finish_request();
		}
		
		$event = new TerminateEvent($request, self::MASTER_REQUEST, $response, $this);
		$event->bufferedContent = $buffer;
		
		$this->dispatcher->notify($event);
	}
public function terminate(HttpRequest $request, HttpResponse $response)
	{
		$this->dispatcher->notify(new SendResponseEvent($request, self::MASTER_REQUEST, $response, $this));
		
		while(ob_get_level() > 1)
		{
			ob_end_flush();
		}
		
		$buffer = ob_get_level() ? ob_get_clean() : '';
		
		ini_set('default_mimetype', NULL);
		ini_set('default_charset', NULL);
		
		if($response->hasEntity() && !$request->isHead())
		{
			if('gzip' == strtolower($response->getHeader('Content-Encoding', '')))
			{
				ini_set('zlib.output_compression_level', 1);
				ini_set('zlib.output_compression', 4096);
			}
			else
			{
				ob_start(NULL, 4096);
			}
		}
		
		foreach($response->getHeaders() as $n => $headers)
		{
			switch($n)
			{
				case 'server':
				case 'connection':
				case 'content-length':
				case 'content-encoding':
				case 'transfer-encoding':
					continue 2;
			}
			
			foreach($headers as $index => $header)
			{
				header(sprintf('%s: %s', $header[0], $header[1]), $index == 0);
			}
		}
		
		$statusLine = sprintf('%s %u %s', $response->getProtocol(), $response->getStatus(), $response->getReason());
		
		header($statusLine, true, $response->getStatus());
		
		if($response->hasEntity() && !$request->isHead())
		{
			$stream = new UrlStream('php://output', 'wb');
			
			try
			{
				$response->getEntity()->send($stream);
			}
			finally
			{
				$stream->close();
			}
		}
		
		if(function_exists('fastcgi_finish_request'))
		{
			@fastcgi_finish_request();
		}
		
		$event = new TerminateEvent($request, self::MASTER_REQUEST, $response, $this);
		$event->bufferedContent = $buffer;
		
		$this->dispatcher->notify($event);
	}
{@inheritDoc}