示例#1
0
        public void Receive(AdkSocketConnection connection)
        {
            if (fContentLength == -1)
            {
                MemoryStream initialBuffer =
                    new MemoryStream
                        (connection.RawBuffer, 0, connection.RawBufferLength, false, false);
                AdkHttpHeadersReader reader = new AdkHttpHeadersReader(initialBuffer);
                ParseRequestLine(reader);
                ParseHeaders(reader);
                // This server does not support transfer encoding
                if (this.Headers["Transfer-Encoding"] != null)
                {
                    throw new AdkHttpException
                              (AdkHttpStatusCode.ServerError_501_Not_Implemented,
                              "'Transfer-Encoding' is not supported");
                }


                IPEndPoint endPoint = (IPEndPoint)connection.Socket.LocalEndPoint;
                string     host     = fHeaders["Host"];
                if (host == null)
                {
                    host = endPoint.Address.ToString();
                }
                else
                {
                    int loc = host.IndexOf(':');
                    if (loc > 0)
                    {
                        host = host.Substring(0, loc);
                    }
                }
                // TODO: Implement better parsing of the query string. This will sometimes blow up when it shouldn't.
                string []  pathAndQuery = this.Path.Split('?');
                UriBuilder builder      =
                    new UriBuilder
                        ("http", host, connection.Binding.Port, pathAndQuery[0],
                        pathAndQuery.Length > 1 ? pathAndQuery[1] : "");
                fUri = new Uri(builder.ToString());

                // Now create the request stream, but chop of the headers
                if (this.ContentLength > 0)
                {
                    fRequestStream = new MemoryStream((int)this.ContentLength);
                    fRequestStream.Write
                        (connection.RawBuffer, (int)reader.Position,
                        (int)(connection.RawBufferLength - reader.Position));
                }
            }
            else if (ReceiveComplete)
            {
                throw new AdkHttpException
                          (AdkHttpStatusCode.ClientError_400_Bad_Request,
                          "Too much data received for specified Content-Length");
            }
            else
            {
                fRequestStream.Write(connection.RawBuffer, 0, connection.RawBufferLength);
            }
        }
示例#2
0
        public void Receive( AdkSocketConnection connection )
        {
            if ( fContentLength == -1 ) {
                MemoryStream initialBuffer =
                    new MemoryStream
                        ( connection.RawBuffer, 0, connection.RawBufferLength, false, false );
                AdkHttpHeadersReader reader = new AdkHttpHeadersReader( initialBuffer );
                ParseRequestLine( reader );
                ParseHeaders( reader );
                // This server does not support transfer encoding
                if ( this.Headers["Transfer-Encoding"] != null ) {
                    throw new AdkHttpException
                        ( AdkHttpStatusCode.ServerError_501_Not_Implemented,
                          "'Transfer-Encoding' is not supported" );
                }

                IPEndPoint endPoint = (IPEndPoint) connection.Socket.LocalEndPoint;
                string host = fHeaders["Host"];
                if ( host == null ) {
                    host = endPoint.Address.ToString();
                }
                else {
                    int loc = host.IndexOf( ':' );
                    if ( loc > 0 ) {
                        host = host.Substring( 0, loc );
                    }
                }
                // TODO: Implement better parsing of the query string. This will sometimes blow up when it shouldn't.
                string [] pathAndQuery = this.Path.Split( '?' );
                UriBuilder builder =
                    new UriBuilder
                        ( "http", host, connection.Binding.Port, pathAndQuery[0],
                          pathAndQuery.Length > 1 ? pathAndQuery[1] : "" );
                fUri = new Uri( builder.ToString() );

                // Now create the request stream, but chop of the headers
                if ( this.ContentLength > 0 ) {
                    fRequestStream = new MemoryStream( (int) this.ContentLength );
                    fRequestStream.Write
                        ( connection.RawBuffer, (int) reader.Position,
                          (int) (connection.RawBufferLength - reader.Position) );
                }
            }
            else if ( ReceiveComplete ) {
                throw new AdkHttpException
                    ( AdkHttpStatusCode.ClientError_400_Bad_Request,
                      "Too much data received for specified Content-Length" );
            }
            else {
                fRequestStream.Write( connection.RawBuffer, 0, connection.RawBufferLength );
            }
        }