예제 #1
0
        // this one is a little bit different:
        // the current `position` of the buffer is the location of the
        // error, `ini_pos` indicates where the position of
        // the buffer when it was passed to the `execute` method of the parser, i.e.
        // using this information and `limit` we'll know all the valid data
        // in the buffer around the error we can use to print pretty error
        // messages.
        public void RaiseOnError(HttpParser p, string message, ByteBuffer buf, int ini_pos)
        {
            if (null != OnError)
                OnError (p, message, buf, ini_pos);

            // if on_error gets called it MUST throw an exception, else the parser
            // will attempt to continue parsing, which it can't because it's
            // in an invalid state.
            throw new HttpException (message);
        }
예제 #2
0
        public HttpTransaction(HttpServer server, IOStream stream, Socket socket, HttpConnectionCallback callback)
        {
            Server = server;
            IOStream = stream;
            Socket = socket;
            ConnectionCallback = callback;

            stream.OnClose (OnClose);

            parser_settings = CreateParserSettings ();
            parser = new HttpParser ();

            stream.ReadBytes (OnBytesRead);
        }
예제 #3
0
        protected override int OnHeadersComplete(HttpParser parser)
        {
            base.OnHeadersComplete (parser);

            StatusCode = parser.StatusCode;

            if (Request.Method == HttpMethod.HTTP_HEAD)
                return 1;
            return 0;
        }
예제 #4
0
 public void RaiseOnHeaderField(HttpParser p, ByteBuffer buf, int pos, int len)
 {
     Raise (OnHeaderField, p, buf, pos, len);
 }
예제 #5
0
 public void RaiseOnBody(HttpParser p, ByteBuffer buf, int pos, int len)
 {
     Raise (OnBody, p, buf, pos, len);
 }
예제 #6
0
        private int Raise(HttpCallback cb, HttpParser p)
        {
            if (cb == null)
                return 0;

            try {
                return cb (p);
            } catch (Exception e) {
                Console.WriteLine (e);

                RaiseOnError (p, e.Message, null, -1);
                return -1;
            }
        }
예제 #7
0
 public void RaiseOnMessageComplete(HttpParser p)
 {
     Raise (OnMessageComplete, p);
 }
예제 #8
0
        private int OnQueryString(HttpParser parser, ByteBuffer data, int pos, int len)
        {
            string str = Encoding.ASCII.GetString (data.Bytes, pos, len);

            query_data_builder.Append (str);
            return 0;
        }
예제 #9
0
        public int OnHeaderField(HttpParser parser, ByteBuffer data, int pos, int len)
        {
            string str = Encoding.ASCII.GetString (data.Bytes, pos, len);

            if (current_header_value.Length != 0)
                FinishCurrentHeader ();

            current_header_field.Append (str);
            return 0;
        }
예제 #10
0
        public int OnBody(HttpParser parser, ByteBuffer data, int pos, int len)
        {
            if (body_handler == null)
                CreateBodyHandler ();

            if (body_handler != null)
                body_handler.HandleData (this, data, pos, len);

            return 0;
        }
예제 #11
0
 private void OnParserError(HttpParser parser, string message, ByteBuffer buffer, int initial_position)
 {
     Server.RemoveTransaction (this);
     IOStream.Close ();
 }
예제 #12
0
        public void OnResponseFinished()
        {
            bool disconnect = true;

            if (!NoKeepAlive) {
                string dis;
                if (Request.MinorVersion > 0 && Request.Headers.TryGetValue ("Connection", out dis))
                    disconnect = (dis == "close");
            }

            if (disconnect) {
                Request = null;
                Response = null;
                  	IOStream.Close ();
                Server.RemoveTransaction (this);
                return;
            }

            parser = new HttpParser ();
            IOStream.ReadBytes (OnBytesRead);
        }
예제 #13
0
 public void RaiseOnHeadersComplete(HttpParser p)
 {
     Raise (OnHeadersComplete, p);
 }
예제 #14
0
        protected override void OnFinishedReading(HttpParser parser)
        {
            base.OnFinishedReading (parser);

            MajorVersion = parser.Major;
            MinorVersion = parser.Minor;
            Method = parser.HttpMethod;

            if (query_data_builder.Length != 0) {
                QueryData = HttpUtility.ParseUrlEncodedData (query_data_builder.ToString ());
                query_data_builder.Length = 0;
            }

            Transaction.OnRequestReady ();
        }
예제 #15
0
        public int OnHeaderValue(HttpParser parser, ByteBuffer data, int pos, int len)
        {
            string str = Encoding.ASCII.GetString (data.Bytes, pos, len);

            if (current_header_field.Length == 0)
                throw new HttpException ("Header Value raised with no header field set.");

            current_header_value.Append (str);
            return 0;
        }
예제 #16
0
        private int OnPath(HttpParser parser, ByteBuffer data, int pos, int len)
        {
            string str = Encoding.ASCII.GetString (data.Bytes, pos, len);

            str = HttpUtility.UrlDecode (str, Encoding.ASCII);
            Path = Path == null ? str : String.Concat (Path, str);
            return 0;
        }
예제 #17
0
        private int OnHeadersComplete(HttpParser parser)
        {
            if (current_header_field.Length != 0)
                FinishCurrentHeader ();

            if (query_data.Length != 0) {
                Request.QueryData = HttpUtility.ParseUrlEncodedData (query_data.ToString ());
                query_data.Length = 0;
            }

            Request.MajorVersion = parser.Major;
            Request.MinorVersion = parser.Minor;
            Request.Method = parser.HttpMethod;

            return 0;
        }
예제 #18
0
 public void RaiseOnMessageBegin(HttpParser p)
 {
     Raise (OnMessageBegin, p);
 }
예제 #19
0
        private int OnMessageBegin(HttpParser parser)
        {
            Request = new HttpRequest (this);

            return 0;
        }
예제 #20
0
 public void RaiseOnQueryString(HttpParser p, ByteBuffer buf, int pos, int len)
 {
     Raise (OnQueryString, p, buf, pos, len);
 }
예제 #21
0
 private int OnMessageComplete(HttpParser parser)
 {
     OnFinishedReading ();
     return 0;
 }
예제 #22
0
        private int Raise(HttpDataCallback cb, HttpParser p, ByteBuffer buf, int pos, int len)
        {
            if (cb == null || pos == -1)
                return 0;

            try {
                return cb (p,buf,pos,len);
            } catch (Exception e) {
                Console.WriteLine (e);

                RaiseOnError (p, e.Message, buf, pos);
                return -1;
            }
        }
예제 #23
0
 private void OnParserError(HttpParser parser, string message, ByteBuffer buffer, int initial_position)
 {
     Console.WriteLine ("parser error: '{0}'", message);
     Server.RemoveTransaction (this);
     IOStream.Close ();
 }
예제 #24
0
 public void RaiseOnFragment(HttpParser p, ByteBuffer buf, int pos, int len)
 {
     Raise (OnFragment, p, buf, pos, len);
 }
예제 #25
0
        private int OnPath(HttpParser parser, ByteBuffer data, int pos, int len)
        {
            string str = Encoding.ASCII.GetString (data.Bytes, pos, len);

            Request.LocalPath = Request.LocalPath == null ? str : String.Concat (Request.LocalPath, str);
            return 0;
        }
예제 #26
0
 public int RaiseOnHeadersComplete(HttpParser p)
 {
     return Raise (OnHeadersComplete, p);
 }
예제 #27
0
        protected override void OnFinishedReading(HttpParser parser)
        {
            base.OnFinishedReading (parser);

            if (Completed != null)
                Completed (this);
        }