コード例 #1
0
ファイル: HttpTransaction.cs プロジェクト: silk/manos
        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);
        }
コード例 #2
0
ファイル: HttpServer.cs プロジェクト: KevinT/manos
        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);
            }
        }
コード例 #3
0
ファイル: HttpTransaction.cs プロジェクト: silk/manos
        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);
        }
コード例 #4
0
ファイル: HttpTransaction.cs プロジェクト: silk/manos
        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);
        }
コード例 #5
0
ファイル: HttpTransaction.cs プロジェクト: silk/manos
 public static void BeginTransaction(HttpServer server, IOStream stream, Socket socket, HttpConnectionCallback cb)
 {
     HttpTransaction transaction = new HttpTransaction (server, stream, socket, cb);
 }
コード例 #6
0
ファイル: HttpServer.cs プロジェクト: jcbozonier/manos
        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));
            }
        }
コード例 #7
0
 public void Write(IOStream stream)
 {
     stream.SendFile (file, callback);
 }
コード例 #8
0
ファイル: HttpTransaction.cs プロジェクト: jcbozonier/manos
        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);
        }
コード例 #9
0
ファイル: HttpTransaction.cs プロジェクト: jcbozonier/manos
        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);
        }
コード例 #10
0
ファイル: HttpTransaction.cs プロジェクト: jcbozonier/manos
 private void OnClose(IOStream stream)
 {
 }