Inheritance: HttpParser.RawHttpParser
Exemplo n.º 1
0
		public static String DumpParser (HttpParser p)
		{
			StringBuilder builder = new StringBuilder();
    
			// the stuff up to the break is ephermeral and only meaningful
			// while the parser is parsing. In general, this method is 
			// probably only useful during debugging.

			/*
			builder.Append("state :"); builder.Append(p.state); builder.Append("\n");
			builder.Append("header_state :"); builder.Append(p.header_state); builder.Append("\n");
			builder.Append("strict :"); builder.Append(p.strict); builder.Append("\n");
			builder.Append("index :"); builder.Append(p.index); builder.Append("\n");
			builder.Append("flags :"); builder.Append(p.flags); builder.Append("\n");
			builder.Append("nread :"); builder.Append(p.nread); builder.Append("\n");
			builder.Append("content_length :"); builder.Append(p.content_length); builder.Append("\n");


			builder.Append("type :"); builder.Append(p.type); builder.Append("\n");
			builder.Append("http_major :"); builder.Append(p.http_major); builder.Append("\n");
			builder.Append("http_minor :"); builder.Append(p.http_minor); builder.Append("\n");
			builder.Append("status_code :"); builder.Append(p.status_code); builder.Append("\n");
			builder.Append("method :"); builder.Append(p.method); builder.Append("\n");
			builder.Append("upgrade :"); builder.Append(p.upgrade); builder.Append("\n");
			*/

			return builder.ToString();

		}
Exemplo n.º 2
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, MemoryStream 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);
		}
Exemplo n.º 3
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, MemoryStream 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);
        }
Exemplo n.º 4
0
        public Parser(HttpParserType type)
        {
            unsafe
            {
                HttpParserSettings settings = new HttpParserSettings();
                settings.on_message_begin = OnMessageBegin;
                settings.on_message_complete = OnMessageComplete;
                settings.on_url = OnUrl;
                settings.on_header_field = OnHeaderField;
                settings.on_header_value = OnHeaderValue;
                settings.on_headers_complete = OnHeadersComplete;
                settings.on_body = OnBody;

                _parser = new HttpParser(settings, type);
            }
        }
Exemplo n.º 5
0
        public Parser(HttpParserType type)
        {
            unsafe
            {
                HttpParserSettings settings = new HttpParserSettings();
                settings.on_message_begin    = OnMessageBegin;
                settings.on_message_complete = OnMessageComplete;
                settings.on_url              = OnUrl;
                settings.on_header_field     = OnHeaderField;
                settings.on_header_value     = OnHeaderValue;
                settings.on_headers_complete = OnHeadersComplete;
                settings.on_body             = OnBody;

                _parser = new HttpParser(settings, type);
            }
        }
Exemplo n.º 6
0
        private static bool MessageNeedsEof(HttpParser parser)
        {
            if (parser.Type == HttpParserType.Request)
            {
                return(false);
            }

            if (parser.StatusCode / 100 == 1 ||                                        // 1xx e.g. Continue
                parser.StatusCode == 204 ||                                            // No Content
                parser.StatusCode == 304 ||                                            // Not Modified
                (parser.Flags & HttpParserFlags.SkipBody) == HttpParserFlags.SkipBody) // response to a HEAD request
            {
                return(false);
            }

            if ((parser.Flags & HttpParserFlags.Chunked) == HttpParserFlags.Chunked || parser.ContentLength != ulong.MaxValue)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 7
0
 unsafe int OnUrl(HttpParser parser, char* at, uint length)
 {
     if (Url != null)
     {
         string url = Marshal.PtrToStringUni((IntPtr)at, (int)length);
         Url(this, url);
     }
     return 0;
 }
Exemplo n.º 8
0
 int OnMessageBegin(HttpParser parser)
 {
     if (MessageBegin != null)
     {
         MessageBegin(this);
     }
     return 0;
 }
Exemplo n.º 9
0
 int OnHeadersComplete(HttpParser parser)
 {
     if (HeadersComplete != null)
     {
         HeadersComplete(this);
     }
     return 0;
 }
Exemplo n.º 10
0
 public void RaiseOnHeadersComplete(HttpParser p)
 {
     Raise(OnHeadersComplete, p);
 }
Exemplo n.º 11
0
 public void RaiseOnHeaderValue(HttpParser p, MemoryStream buf, int pos, int len)
 {
     Raise(OnHeaderValue, p, buf, pos, len);
 }
Exemplo n.º 12
0
 public void RaiseOnQueryString(HttpParser p, MemoryStream buf, int pos, int len)
 {
     Raise(OnQueryString, p, buf, pos, len);
 }
Exemplo n.º 13
0
 public void RaiseOnMessageComplete(HttpParser p)
 {
     Raise(OnMessageComplete, p);
 }
Exemplo n.º 14
0
        public static void Main()
        {
            string content =
            @"POST    HTTP://LIULIJIN.INFO     HTTP/1.1
            HOST:LIULIJIN.INFO
            Cookie:s=1

            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
            ";
            CodeTimer.Initialize();
            CodeTimer.Time("!", 50000, () =>
            {
                HttpParser parser = new HttpParser();
                parser.Go(content);
            });

            Console.ReadLine();
        }
Exemplo n.º 15
0
		private void Raise (HttpDataCallback cb, HttpParser p, MemoryStream buf, int pos, int len)
		{
			if (null != cb && -1 != pos)
				cb (p,buf,pos,len);
		}
Exemplo n.º 16
0
		private void Raise (HttpCallback cb, HttpParser p)
		{
			if (null != cb)
				cb (p);
		}
Exemplo n.º 17
0
		public void RaiseOnHeadersComplete (HttpParser p)
		{
			Raise (OnHeadersComplete, p);
		}
Exemplo n.º 18
0
		public void RaiseOnBody(HttpParser p, MemoryStream buf, int pos, int len)
		{
			Raise (OnBody, p, buf, pos, len);
		}
Exemplo n.º 19
0
		public void RaiseOnHeaderValue (HttpParser p, MemoryStream buf, int pos, int len)
		{
			Raise (OnHeaderValue, p, buf, pos, len);
		}
Exemplo n.º 20
0
		public void RaiseOnFragment (HttpParser p, MemoryStream buf, int pos, int len)
		{
			Raise (OnFragment, p, buf, pos, len);
		}
Exemplo n.º 21
0
		public void RaiseOnQueryString (HttpParser p, MemoryStream buf, int pos, int len)
		{
			Raise (OnQueryString, p, buf, pos, len);
		}
Exemplo n.º 22
0
 public void RaiseOnMessageBegin(HttpParser p)
 {
     Raise(OnMessageBegin, p);
 }
Exemplo n.º 23
0
 internal int on_headers_complete_wrapper(HttpParser parser)
 {
     return Convert.ToInt32(HeadersCompleted(parser));
 }
Exemplo n.º 24
0
        public static HttpParser Create(http_parser parser)
        {
            var httpParser = new HttpParser(parser);

            return(httpParser);
        }
Exemplo n.º 25
0
 internal int on_message_begin_wrapper(HttpParser parser)
 {
     return Convert.ToInt32(MessageBegan(parser));
 }
Exemplo n.º 26
0
 public void RaiseOnFragment(HttpParser p, MemoryStream buf, int pos, int len)
 {
     Raise(OnFragment, p, buf, pos, len);
 }
Exemplo n.º 27
0
 internal int on_message_complete_wrapper(HttpParser parser)
 {
     return Convert.ToInt32(MessageCompleted(parser));
 }
Exemplo n.º 28
0
 public void RaiseOnBody(HttpParser p, MemoryStream buf, int pos, int len)
 {
     Raise(OnBody, p, buf, pos, len);
 }
Exemplo n.º 29
0
 internal unsafe int on_body_wrapper(HttpParser parser, byte* at, uint length)
 {
     var data = new byte[(int)length];
     Marshal.Copy((IntPtr)at, data, 0, (int)length);
     return Convert.ToInt32(Body(parser, data));
 }
Exemplo n.º 30
0
 unsafe int OnBody(HttpParser parser, char* at, uint length)
 {
     if (Body != null)
     {
         string body = Marshal.PtrToStringUni((IntPtr)at, (int)length);
         Body(this, body);
     }
     return 0;
 }
Exemplo n.º 31
0
 internal int on_message_complete_wrapper(HttpParser parser)
 {
     return(Convert.ToInt32(MessageCompleted(parser)));
 }
Exemplo n.º 32
0
 unsafe int OnHeaderValue(HttpParser parser, char* at, uint length)
 {
     if (HeaderValue != null)
     {
         string headerValue = Marshal.PtrToStringUni((IntPtr)at, (int)length);
         HeaderValue(this, headerValue);
     }
     return 0;
 }
Exemplo n.º 33
0
 internal int on_message_begin_wrapper(HttpParser parser)
 {
     return(Convert.ToInt32(MessageBegan(parser)));
 }
Exemplo n.º 34
0
 int OnMessageComplete(HttpParser parser)
 {
     if (MessageComplete != null)
     {
         MessageComplete(this);
     }
     return 0;
 }
Exemplo n.º 35
0
		public void RaiseOnMessageBegin (HttpParser p)
		{
			Raise (OnMessageBegin, p);
		}
Exemplo n.º 36
0
 internal int on_headers_complete_wrapper(HttpParser parser)
 {
     return(Convert.ToInt32(HeadersCompleted(parser)));
 }
Exemplo n.º 37
0
		public void RaiseOnMessageComplete (HttpParser p)
		{
			Raise (OnMessageComplete, p);
		}