Exemple #1
0
        public void SendRequestAsync(Uri request, string method, string localPath = null, string serverPostAct = null)
        {
            if (!_socket.IsClosed)
            {
                if (_host != request.Host || _port != request.Port || _scheme != request.Scheme)
                {
                    throw new InvalidOperationException("Trying to send request to non connected address");
                }

                if (_useHttp20 == false)
                {
                    Http2Logger.LogConsole("Download with Http/1.1");

                    //Download with http11 in another thread.
                    Http11Manager.Http11DownloadResource(_socket, request);
                    return;
                }

                //Submit request if http2 was chosen
                Http2Logger.LogConsole("Submitting request");

                //Submit request in the current thread, response will be handled in the session thread.
                SubmitRequest(request, method, localPath, serverPostAct);
            }
        }
Exemple #2
0
        public void GetHttp11ResourceSuccessful()
        {
            string requestStr = ConfigurationManager.AppSettings["secureAddress"] +
                                ConfigurationManager.AppSettings["10mbTestFile"];
            Uri uri;

            Uri.TryCreate(requestStr, UriKind.Absolute, out uri);

            bool wasServerSocketClosed = false;
            bool wasClientSocketClosed = false;
            bool wasResourceDownloaded = false;

            var socketClosedRaisedEvent       = new ManualResetEvent(false);
            var resourceDownloadedRaisedEvent = new ManualResetEvent(false);

            Http11Manager.OnDownloadSuccessful += (sender, args) =>
            {
                wasResourceDownloaded = true;
                resourceDownloadedRaisedEvent.Set();
            };

            //First time event will be raised when server closes it's socket
            Http11Manager.OnSocketClosed += (sender, args) =>
            {
                if (!wasServerSocketClosed)
                {
                    wasServerSocketClosed = true;
                }
                if (!wasClientSocketClosed && wasServerSocketClosed)
                {
                    wasClientSocketClosed = true;
                }
                socketClosedRaisedEvent.Set();
            };

            var socket = GetHandshakedSocket(uri);

            //Http11 was selected
            Http11Manager.Http11DownloadResource(socket, uri);

            resourceDownloadedRaisedEvent.WaitOne(60000);
            socketClosedRaisedEvent.WaitOne(60000);

            Assert.Equal(wasResourceDownloaded, true);
            Assert.Equal(wasClientSocketClosed, true);
            Assert.Equal(wasServerSocketClosed, true);
        }