예제 #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(Parser 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.
            Console.WriteLine ("ERROR: '{0}'", message);
            throw new System.Exception (message);
        }
예제 #2
0
        protected override int OnHeadersComplete(Parser parser)
        {
            base.OnHeadersComplete (parser);

            StatusCode = parser.StatusCode;

            if (Request.Method == Method.Head)
                return 1;
            return 0;
        }
예제 #3
0
 public int RaiseOnHeadersComplete(Parser p)
 {
     return Raise (OnHeadersComplete, p);
 }
예제 #4
0
 public void RaiseOnHeaderField(Parser p, ByteBuffer buf, int pos, int len)
 {
     Raise (OnHeaderField, p, buf, pos, len);
 }
예제 #5
0
 public void RaiseOnFragment(Parser p, ByteBuffer buf, int pos, int len)
 {
     Raise (OnFragment, p, buf, pos, len);
 }
예제 #6
0
        private int Raise(DataCallback cb, Parser p, ByteBuffer buf, int pos, int len)
        {
            if (cb == null || pos == -1)
                return 0;

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

                RaiseOnError (p, e.Message, buf, pos);
                return -1;
            }
        }
예제 #7
0
 public void RaiseOnBody(Parser p, ByteBuffer buf, int pos, int len)
 {
     Raise (OnBody, p, buf, pos, len);
 }
예제 #8
0
 public void RaiseOnQueryString(Parser p, ByteBuffer buf, int pos, int len)
 {
     Raise (OnQueryString, p, buf, pos, len);
 }
예제 #9
0
        private int Raise(Callback cb, Parser p)
        {
            if (cb == null)
                return 0;

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

                RaiseOnError (p, e.Message, null, -1);
                return -1;
            }
        }
예제 #10
0
 public void RaiseOnMessageComplete(Parser p)
 {
     Raise (OnMessageComplete, p);
 }
예제 #11
0
 public void RaiseOnPath(Parser p, ByteBuffer buf, int pos, int len)
 {
     Raise (OnPath, p, buf, pos, len);
 }
예제 #12
0
 public void RaiseOnMessageBegin(Parser p)
 {
     Raise (OnMessageBegin, p);
 }
예제 #13
0
 public void RaiseOnHeaderValue(Parser p, ByteBuffer buf, int pos, int len)
 {
     Raise (OnHeaderValue, p, buf, pos, len);
 }
예제 #14
0
        private int OnQueryString(Parser parser, ByteBuffer data, int pos, int len)
        {
            string str = Encoding.ASCII.GetString (data.Bytes, pos, len);

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

            str = Utility.UrlDecode (str, Encoding.ASCII);
            Path = Path == null ? str : String.Concat (Path, str);
            return 0;
        }
예제 #16
0
        protected override void OnFinishedReading(Parser parser)
        {
            base.OnFinishedReading (parser);

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

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

            Transaction.OnRequestReady ();
        }