예제 #1
0
        public void Write(IContext context, object msg)
        {
            HttpResponse response = msg as HttpResponse;

            if (response != null)
            {
                bool isContinue = true;
                if (_config.StatusListener != null && response.Status != 200)
                {
                    isContinue = _config.StatusListener(response);
                }
                if (isContinue)
                {
                    response.KeepAlive = _keepalive;
                    if (_config.DisableGzip)
                    {
                        response.Gzip = false;
                    }
                    HttpResponseEncoder.WriteResponse(response);
                    context.FirePreWrite(msg);
                }
            }
            else
            {
                HandshakeResponse websockethandshake = msg as HandshakeResponse;
                if (websockethandshake != null)
                {
                    HttpResponseEncoder.WriteWebSocketHandshakeResponse(websockethandshake);
                    //升级协议为websocket
                    _source.SetState(new WebSocketState(context, _source, _config));
                }
                context.FirePreWrite(msg);
            }
        }
예제 #2
0
        public void Write(IContext context, object msg)
        {
            FrameResponse response = msg as FrameResponse;

            if (response != null)
            {
                HttpResponseEncoder.WriteWebSocketFrameResponse(response, false);
            }
            context.FirePreWrite(msg);
        }