Ejemplo n.º 1
0
        public HttpResponse(IHttpRequest request, Socket socket)
        {
            Request = request;
            Socket = socket;

            StatusCode = 200;

            WriteHeaders = true;

            Stream = new HttpStream (this, socket.GetSocketStream ());
            Stream.Chunked = (request.MajorVersion > 0 && request.MinorVersion > 0);
        }
Ejemplo n.º 2
0
 public void Connect(Action connected)
 {
     this.sock = AppHost.Context.CreateSocket();
     sock.Connect(ConnectionPath.Host, (ConnectionPath.Port == -1) ? ConnectionPath.Scheme == "ws" ? 80 : 443 : ConnectionPath.Port, () => {
         var hand = ConnectionHandshake.Generate();
         this.WriteHeaders(hand);
         sock.GetSocketStream().Read((data) => {
             if (this.connected) {
                 if (data.Bytes[0] != 0x00 || data.Bytes[data.Length - 1] != 0xFF) return;
                 if (OnData != null)
                 {
                     OnData(new ByteBuffer(data.Bytes, data.Position + 1, data.Length - 2));
                 }
             } else {
                 if (this.EnsureResponse(data, hand))
                 {
                     this.connected = true;
                     connected();
                 }
                 else
                 {
                     this.sock.Close();
                 }
             }
         }, (e) => {}, () => {});
     });
 }