Пример #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);
        }