public void HttpRequestResponse_Construction_With_Non_Timeout_Stream_Test()
        {
            Stream s = GetRequestStream("GET / HTTP/1.1", "Host: Localhost", "");
            Assert.IsFalse(s.CanTimeout);

            HttpRequestResponse httpRequestResponse = new HttpRequestResponse(s, null, null);
        }
        public void IsKeepAlive_True_Test()
        {
            MemoryStream stream = GetRequestStream("GET / HTTP/1.1", "Host: Localhost", "Connection: Keep-Alive", "");
            HttpRequestResponse httpRequestResponse = new HttpRequestResponse(stream, null, null);

            Assert.IsTrue(httpRequestResponse.Request.IsKeepAlive);
        }
        public void Empty_PostData_Test()
        {
            MemoryStream stream = GetRequestStream("POST / HTTP/1.1", "Host: Localhost", "Content-Length: 0", "");
            HttpRequestResponse httpRequestResponse = new HttpRequestResponse(stream, null, null);

            Assert.AreEqual(0, httpRequestResponse.Request.PostData.Length);
        }
        public void HttpRequestResponse_Construction_With_Non_Timeout_Stream_When_Specifying_Timeout_Test()
        {
            MockRepository mocks = new MockRepository();

            Stream s = mocks.CreateMock<Stream>();
            using(mocks.Unordered()) {
                Expect.Call(s.CanTimeout).Return(false);
            }
            mocks.ReplayAll();

            HttpRequestResponse httpRequestResponse = new HttpRequestResponse(s, null, null, 400);
        }
Пример #5
0
        /// <summary>
        /// This method processes the socket request. This is the first entry point for requested entering the aspNETserve
        /// server.
        /// </summary>
        /// <param name="async">The IAsyncResult used to aquire to Socket.</param>
        protected virtual void ProcessRequest(IAsyncResult async)
        {
            Logger.Instance.LogMemberEntry();
            Socket com = null;

            Interlocked.Increment(ref _openConnections);
            try {
                com = _sock.EndAccept(async);
                _sock.BeginAccept(new AsyncCallback(ProcessRequest), _sock);

                if (_openConnections < _maxConnections)     //if the number of open connections is "safe", then continue...

                {
                    HttpRequestResponse transaction = null;
                    do
                    {
                        int timeout = transaction == null ? _initialRequestTimeout : _keepAliveRequestTimeout; //the initial request and subsequent requests may have different timeouts
                        transaction = new HttpRequestResponse(new NetworkStream(com, false), (IPEndPoint)com.LocalEndPoint, (IPEndPoint)com.RemoteEndPoint, timeout);
                        _domainHook.ProcessTransaction(transaction);
                        transaction.Response.Flush();
                    } while (transaction.Request.IsKeepAlive); //loop while the client wants to "keep alive".
                }                                              //otherwise we want to fall through and close this socket, and decrement the connection count.
                com.Close();
            } catch (Exception ex) {
                Logger.Instance.LogException(LogLevel.Error, "Error processing request", ex);
                if (com != null)
                {
                    try {
                        com.Close();
                    } catch { }
                }
            } finally {
                Interlocked.Decrement(ref _openConnections);
                Logger.Instance.LogMemberExit();
            }
        }
Пример #6
0
        /// <summary>
        /// This method processes the socket request. This is the first entry point for requested entering the aspNETserve
        /// server.
        /// </summary>
        /// <param name="async">The IAsyncResult used to aquire to Socket.</param>
        protected virtual void ProcessRequest(IAsyncResult async)
        {
            Logger.Instance.LogMemberEntry();
            Socket com = null;
            Interlocked.Increment(ref _openConnections);
            try {
                com = _sock.EndAccept(async);
                _sock.BeginAccept(new AsyncCallback(ProcessRequest), _sock);

                if (_openConnections < _maxConnections) {   //if the number of open connections is "safe", then continue...

                    HttpRequestResponse transaction = null;
                    do {
                        int timeout = transaction == null ? _initialRequestTimeout : _keepAliveRequestTimeout; //the initial request and subsequent requests may have different timeouts
                        transaction = new HttpRequestResponse(new NetworkStream(com, false), (IPEndPoint)com.LocalEndPoint, (IPEndPoint)com.RemoteEndPoint, timeout);
                        _domainHook.ProcessTransaction(transaction);
                        transaction.Response.Flush();
                    } while (transaction.Request.IsKeepAlive);  //loop while the client wants to "keep alive".

                }   //otherwise we want to fall through and close this socket, and decrement the connection count.
                com.Close();

            } catch(Exception ex) {
                Logger.Instance.LogException(LogLevel.Error, "Error processing request", ex);
                if (com != null) {
                    try {
                        com.Close();
                    } catch { }
                }
            } finally {
                Interlocked.Decrement(ref _openConnections);
                Logger.Instance.LogMemberExit();
            }
        }
        public void PostData_On_Get_Test()
        {
            MemoryStream stream = GetRequestStream("GET / HTTP/1.1", "Host: Localhost", "");
            HttpRequestResponse httpRequestResponse = new HttpRequestResponse(stream, null, null);

            Assert.AreEqual(0, httpRequestResponse.Request.PostData.Length);
        }
        public void NonEmpty_PostData_Test()
        {
            byte[] postedData = new byte[]{4, 9, 123, 87, 182, 44, 250};

            MemoryStream stream = GetRequestStream("POST / HTTP/1.1", "Host: Localhost", "Content-Length: 7", "", Encoding.ASCII.GetString(postedData));
            HttpRequestResponse httpRequestResponse = new HttpRequestResponse(stream, null, null);

            Assert.AreEqual(postedData, httpRequestResponse.Request.PostData);
        }
 public void Url_Encoded_Urls_Test()
 {
     MemoryStream request = GetRequestStream("GET /virDir/A%20Path%20That%20Needs%20Encoding.aspx HTTP/1.1",
                                             "Host: Localhost", "");
     HttpRequestResponse httpRequestResponse = new HttpRequestResponse(request, null, null);
     Assert.AreEqual("/virDir/A Path That Needs Encoding.aspx", httpRequestResponse.Request.RawUrl);
 }
        public void Simple_Get_Request_Test()
        {
            MemoryStream stream = GetRequestStream("GET / HTTP/1.1", "Host: Localhost", "");
            HttpRequestResponse httpRequestResponse = new HttpRequestResponse(stream, null, null);

            Assert.AreEqual(httpRequestResponse.Request.HttpMethod, "GET");
            Assert.AreEqual(httpRequestResponse.Request.RawUrl, "/");
            Assert.IsFalse(httpRequestResponse.Request.IsKeepAlive);
        }
 public void Simple_Get_Request_Lacking_Host_Header_Test()
 {
     //This test should throw an exception as the Host header is required.
     //Ideally we would be able to better test for this, but for now all we
     //can do is test for the above generic exception.
     MemoryStream stream = GetRequestStream("GET / HTTP/1.1", "");
     HttpRequestResponse httpRequestResponse = new HttpRequestResponse(stream, null, null);
 }