Exemplo n.º 1
0
        public HttpTransaction(HttpServer server, IOStream stream, Socket socket, HttpConnectionCallback callback)
        {
            Server = server;
            IOStream = stream;
            Socket = socket;
            ConnectionCallback = callback;

            write_ops = new Queue<IWriteOperation> ();

            stream.ReadUntil ("\r\n\r\n", OnHeaders);
        }
Exemplo n.º 2
0
        private void HandleEvents(IntPtr fd, EpollEvents events)
        {
            while (true) {
                Socket s = null;
                try {
                    s = Socket.Accept ();
                } catch (SocketException se) {
                    if (se.SocketErrorCode == SocketError.WouldBlock || se.SocketErrorCode == SocketError.TryAgain)
                        return;
                    throw se;
                } catch {
                    throw;
                }

                IOStream iostream = new IOStream (s, IOLoop);
                HttpTransaction.BeginTransaction (this, iostream, s, callback);
            }
        }
Exemplo n.º 3
0
        private void OnHeaders(IOStream stream, byte [] data)
        {
            string h = Encoding.ASCII.GetString (data);
            StringReader reader = new StringReader (h);

            string verb;
            string path;
            string version;

            string line = reader.ReadLine ();
            ParseStartLine (line, out verb, out path, out version);

            HttpHeaders headers = new HttpHeaders ();
            headers.Parse (reader);

            Request = new HttpRequest (this, headers, verb, path, Version_1_1_Supported (version));
            Response = new HttpResponse (this, Encoding.ASCII);

            if (headers.ContentLength != null && headers.ContentLength > 0) {
                stream.ReadBytes ((int) headers.ContentLength, OnBody);
                return;
            }

            Server.IOLoop.QueueTransaction (this);
        }
Exemplo n.º 4
0
        private void OnBody(IOStream stream, byte [] data)
        {
            if (Request.Method == "POST") {
                string ct = Request.Headers ["Content-Type"];
                if (ct == "application/x-www-form-urlencoded")
                    OnWwwFormData (data);
                else if (ct == "multipart/form-data")
                    OnMultiPartFormData (data);
            }

            Server.IOLoop.QueueTransaction (this);
        }
Exemplo n.º 5
0
 public static void BeginTransaction(HttpServer server, IOStream stream, Socket socket, HttpConnectionCallback cb)
 {
     HttpTransaction transaction = new HttpTransaction (server, stream, socket, cb);
 }
Exemplo n.º 6
0
        private void HandleIOEvents(Loop loop, IOWatcher watcher, int revents)
        {
            while (true) {
                  	Socket s = null;
                try {
                    s = Socket.Accept ();
                } catch (SocketException se) {
                    if (se.SocketErrorCode == SocketError.WouldBlock || se.SocketErrorCode == SocketError.TryAgain)
                        return;
                    throw se;
                } catch {
                    throw;
                }

                IOStream iostream = new IOStream (s, IOLoop);
                transactions.Add (HttpTransaction.BeginTransaction (this, iostream, s, callback));
            }
        }
Exemplo n.º 7
0
 public void Write(IOStream stream)
 {
     stream.SendFile (file, callback);
 }
Exemplo n.º 8
0
        private void OnWwwFormData(IOStream stream, byte [] data)
        {
            //
            // The best I can tell, you can't actually set the content-type of
            // the url-encoded form data.  Looking at the source of apache
            // seems to confirm this.  So for now I wont worry about the
            // encoding type and I'll just use ASCII.
            //

            string post = Encoding.ASCII.GetString (data);

            if (!String.IsNullOrEmpty (post)) {
                // TODO: pass this to the encoder to populate
                DataDictionary post_data = HttpUtility.ParseUrlEncodedData (post);
                if (post_data != null)
                    Request.SetWwwFormData (post_data);
            }

            IOStream.DisableReading ();
            Server.RunTransaction (this);
        }
Exemplo n.º 9
0
        private void OnHeaders(IOStream stream, byte [] data)
        {
            string h = Encoding.ASCII.GetString (data);
            StringReader reader = new StringReader (h);

            string verb;
            string path;
            string version;

            string line = reader.ReadLine ();
            ParseStartLine (line, out verb, out path, out version);

            HttpHeaders headers = new HttpHeaders ();
            headers.Parse (reader);

            Request = new HttpRequest (this, headers, verb, path, Version_1_1_Supported (version));
            Response = new HttpResponse (this, Encoding.ASCII);

            if (headers.ContentLength != null && headers.ContentLength > 0) {
                    long cl = (long) headers.ContentLength;
                if (cl < MAX_BUFFERED_CONTENT_LENGTH) {
                    HandleBody ();
                    return;
                } else {
                    HandleLargeBody ();
                    return;
                }
            }

            stream.DisableReading ();
            Server.RunTransaction (this);
        }
Exemplo n.º 10
0
 private void OnClose(IOStream stream)
 {
 }