/**
  * 发送响应
  * @param $client_id
  * @param $response
  * @return unknown_type
  */
 function response($client_id, Swoole\Request $request, Swoole\Response $response)
 {
     if (!isset($response->head['Date'])) {
         $response->head['Date'] = gmdate("D, d M Y H:i:s T");
     }
     if (!isset($response->head['Server'])) {
         $response->head['Server'] = self::SOFTWARE;
     }
     if (!isset($response->head['Connection'])) {
         //keepalive
         if ($this->keepalive and (isset($request->head['Connection']) and $request->head['Connection'] == 'keep-alive')) {
             $response->head['KeepAlive'] = 'on';
             $response->head['Connection'] = 'keep-alive';
         } else {
             $response->head['KeepAlive'] = 'off';
             $response->head['Connection'] = 'close';
         }
     }
     //过期命中
     if ($this->expire and $response->http_status == 304) {
         $out = $response->head();
         $this->server->send($client_id, $out);
         return;
     }
     //压缩
     if ($this->gzip) {
         $response->head['Content-Encoding'] = 'deflate';
         $response->body = gzdeflate($response->body, $this->config['server']['gzip_level']);
     }
     $response->head['Content-Length'] = strlen($response->body);
     $out = $response->head();
     $out .= $response->body;
     $this->server->send($client_id, $out);
 }
Example #2
0
 /**
 * 发送响应
 * @param $client_id
 * @param \Swoole\Response $response
 * @return unknown_type
 */
 function response($client_id, $response)
 {
     if (!isset($response->head['Date'])) {
         $response->head['Date'] = gmdate("D, d M Y H:i:s T");
     }
     if (!isset($response->head['Server'])) {
         $response->head['Server'] = self::SOFTWARE;
     }
     if (!isset($response->head['KeepAlive'])) {
         $response->head['KeepAlive'] = 'off';
     }
     if (!isset($response->head['Connection'])) {
         $response->head['Connection'] = 'close';
     }
     if (!isset($response->head['Content-Length'])) {
         $response->head['Content-Length'] = strlen($response->body);
     }
     $out = $response->head();
     $out .= $response->body;
     $this->server->send($client_id, $out);
 }