public EventHttpMultiworkerListener(EventHttpListener.RequestCallback cb, int workers) { if (workers < 1) throw new ArgumentException("Invalid number of workers"); _cb = cb; _workerCount = workers; }
public EventHttpRequest(EventHttpListener listener, IntPtr handle) { _listener = listener; _handle = new EvHttpRequest(handle); Method = Commands[Event.EvHttpRequestGetCommand(_handle)]; Uri = Marshal.PtrToStringAnsi(Event.EvHttpRequestGetUri(_handle)); var pHost = Event.EvHttpRequestGetHost(_handle); if (pHost != IntPtr.Zero) Host = Marshal.PtrToStringAnsi(pHost); Headers = EvKeyValuePair.ExtractDictinary(Event.EvHttpRequestGetInputHeaders(_handle)); IEnumerable<string> host; if (Headers.TryGetValue("Host", out host)) Host = host.First().Split(':')[0]; var evBuffer = new EvBuffer(Event.EvHttpRequestGetInputBuffer(_handle), false); if (!evBuffer.IsInvalid) { var len = Event.EvBufferGetLength(evBuffer).ToInt32(); RequestBody = new byte[len]; Event.EvBufferRemove(evBuffer, RequestBody, new IntPtr(len)); } var conn = Event.EvHttpRequestGetConnection(_handle); IntPtr pHostString = IntPtr.Zero; ushort port = 0; Event.EvHttpConnectionGetPeer(conn, ref pHostString, ref port); UserHostAddress = Marshal.PtrToStringAnsi(pHostString); _listener.IncreaseRequestCounter(); }
public void ServerShouldStopListening() { using ( var server = new EventHttpListener(r => r.Respond(System.Net.HttpStatusCode.OK, new Dictionary<string, string>(), new byte[0]))) { server.Start("127.0.0.1", _freePort); server.StopListeningAsync().Wait(); CheckPortIsStillFree(); } }
public void TestServerListening() { using ( var server = new EventHttpListener(r => r.Respond(System.Net.HttpStatusCode.OK, new Dictionary<string, string>(), new byte[0]))) { server.Start("127.0.0.1", _freePort); var wc = new WebClient(); wc.DownloadData(_urlBase); } CheckPortIsStillFree(); }
public void ServerShouldWaitForPendingRequests() { using ( var server = new EventHttpListener (r => ThreadPool.QueueUserWorkItem(_ => { Thread.Sleep(1000); r.Respond(HttpStatusCode.OK, new Dictionary<string, string>(), new byte[0]); }))) { server.Start ("127.0.0.1", _freePort); new WebClient().DownloadDataAsync(new Uri(_urlBase)); Thread.Sleep(100); var task = server.Shutdown(); Thread.Sleep(500); Assert.False(task.IsCompleted); Assert.True(task.Wait(4000)); } }
public EventHttpRequest(EventHttpListener listener, IntPtr handle) { _listener = listener; _handle = new EvHttpRequest(handle); Method = Commands[Event.EvHttpRequestGetCommand(_handle)]; Uri = Marshal.PtrToStringAnsi(Event.EvHttpRequestGetUri(_handle)); var pHost = Event.EvHttpRequestGetHost(_handle); if (pHost != IntPtr.Zero) { Host = Marshal.PtrToStringAnsi(pHost); } Headers = EvKeyValuePair.ExtractDictinary(Event.EvHttpRequestGetInputHeaders(_handle)); IEnumerable <string> host; if (Headers.TryGetValue("Host", out host)) { Host = host.First().Split(':')[0]; } var evBuffer = new EvBuffer(Event.EvHttpRequestGetInputBuffer(_handle), false); if (!evBuffer.IsInvalid) { var len = Event.EvBufferGetLength(evBuffer).ToInt32(); RequestBody = new byte[len]; Event.EvBufferRemove(evBuffer, RequestBody, new IntPtr(len)); } var conn = Event.EvHttpRequestGetConnection(_handle); IntPtr pHostString = IntPtr.Zero; ushort port = 0; Event.EvHttpConnectionGetPeer(conn, ref pHostString, ref port); UserHostAddress = Marshal.PtrToStringAnsi(pHostString); _listener.IncreaseRequestCounter(); }
public void Start() { _listener = new EventHttpListener(RequestHandler); _listener.Start(_host, (ushort) _port); }
public void Dispose() { _listener.Dispose (); _listener = null; }
static void Main(string[] args) { var host = new EventHttpListener(Handler); host.Start(args[0], ushort.Parse(args[1]), int.Parse(args[2])); }