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); } }
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); }
private void HandleRequest(SecureSocket incomingClient, string alpnSelectedProtocol, bool backToHttp11, IDictionary <string, object> handshakeResult) { if (backToHttp11 || alpnSelectedProtocol == Protocols.Http1) { Http2Logger.LogDebug("Sending with http11"); Http11Manager.Http11SendResponse(incomingClient); return; } if (GetSessionHeaderAndVerifyIt(incomingClient)) { OpenHttp2Session(incomingClient, handshakeResult); } else { Http2Logger.LogError("Client has wrong session header. It was disconnected"); incomingClient.Close(); } }