Exemplo n.º 1
0
        public static void ParseHeaders( Request request, ConsumableSegment<byte> buffer )
        {
            request.Headers = new Dictionary<string, string>( StringComparer.CurrentCultureIgnoreCase );
            var length = buffer.Length;
            
            while ( MoveToNextByteIfAble( buffer ) && buffer.Offset + 4 < length && AreHeadersFinished( buffer ) )
            {
                var headerName = ParseValue( buffer, COLON );
                var value = ParseValue( buffer, CR ).Trim();
                if( headerName.Equals( "Connection" ) && value.Equals( "Keep-Alive" ) )
                    request.KeepAlive = true;
                request.Headers.Add( headerName, value );
            }

            var host = "";
            if( request.Headers.TryGetValue( "Host", out host ) )
                request.BaseUri = string.Format( "{0}://{1}", request.Scheme, host );
            
            while ( MoveToNextByteIfAble( buffer ) && ( buffer.Array[buffer.Offset] == CR || buffer.Array[buffer.Offset] == LF ) )
            {
                
            }

            request.HeadersComplete = true;
            request.Parse = PassBodySegmentOn;
        }
Exemplo n.º 2
0
 public static void ParseLine( Request request, ConsumableSegment<byte> buffer )
 {
     GetMethod( request, buffer );
     GetUri( request, buffer );
     GetVersion( request, buffer );
     request.Parse = ParseHeaders;
 }
Exemplo n.º 3
0
 public static void PopulateRequest( Request request, ConsumableSegment<byte> arraySegment )
 {
     while( arraySegment.Count > 0 )
         request.Parse( request, arraySegment );
 }
Exemplo n.º 4
0
 public static void PassBodySegmentOn( Request request, ConsumableSegment<byte> buffer )
 {
     if( request.HandleExtraBytes != null )
             request.HandleExtraBytes( buffer, request.CanHaveBody );
         buffer.Offset += buffer.Count;
 }
Exemplo n.º 5
0
        public static IEnumerable<string> GetSegments( Request request )
        {
            string requestUri = request.RequestUri;
            var uriLength = requestUri.Length;
            if ( uriLength < 2 )
                yield break;

            var index = 1;
            var length = 0;
            var start = index;

            while ( index < uriLength )
            {
                while ( index < uriLength && requestUri[index] != SLASH )
                {
                    length++;
                    index++;
                }

                yield return requestUri.Substring( start, length );

                index++;
                start = index;
                length = 0;
            }
        }
Exemplo n.º 6
0
 public static void GetVersion( Request request, ConsumableSegment<byte> buffer )
 {
     request.Scheme = ParseValue( buffer, SLASH );
     request.Version = ParseValue( buffer, CR );
     request.KeepAlive = request.Version.Equals( "1.1" );
 }
Exemplo n.º 7
0
 public static void ParsePathAndQuery( Request request, string pathAndQuery )
 {
     var pathLength = 1;
     var index = 0;
     var length = pathAndQuery.Length;
     while( ++index < length && pathAndQuery[index] != QMARK )
     {
         pathLength++;
     }
     request.RequestUri = pathAndQuery.Substring( 0, pathLength );
     request.PathSegments = GetSegments( request ).ToList();
     index++;
     var queryString = index > length ? "" : pathAndQuery.Substring( index );
     request.QueryString = queryString;
     request.Parameters = GetParameters( queryString );
 }
Exemplo n.º 8
0
 public static void GetAbsoluteUri( Request request, ConsumableSegment<byte> buffer )
 {
     request.BaseUri = ParseBaseUri( buffer );
     var pathAndQuery = ParseValue( buffer, SPACE );
     ParsePathAndQuery( request, pathAndQuery );
 }
Exemplo n.º 9
0
 public static void GetRelativeUri( Request request, ConsumableSegment<byte> buffer )
 {
     var pathAndQuery = ParseValue( buffer, SPACE );
     ParsePathAndQuery( request, pathAndQuery );
 }
Exemplo n.º 10
0
 public static void GetUri( Request request, ConsumableSegment<byte> buffer )
 {
     if( buffer.Array[ buffer.Offset ] == SLASH )
         GetRelativeUri( request, buffer );
     else
         GetAbsoluteUri( request, buffer );
 }
Exemplo n.º 11
0
 public static void GetMethod( Request request, ConsumableSegment<byte> buffer )
 {
     request.Method = ParseValue( buffer, SPACE );
 }