public void GotRequest(Object stateinfo) { WebServer.thread_info state_data = (WebServer.thread_info)stateinfo; HttpListenerContext ctx = state_data.ctx; //check for /nxt if (ctx.Request.Url.LocalPath.Length == 4 && ctx.Request.Url.LocalPath.Substring(0, 4) == "/nxt") { tryTunnel(ctx); } //check for api else if (ctx.Request.Url.LocalPath.Length >= 4 && ctx.Request.Url.LocalPath.Substring(0, 4) == "/api") { string method = ctx.Request.Url.LocalPath.Substring(5); //Get the params Dictionary <string, string> data = new Dictionary <string, string>(); if (ctx.Request.QueryString.AllKeys.Length > 0) { if (ctx.Request.QueryString.AllKeys[0] != null) { data = (Dictionary <string, string>)ctx.Request.QueryString.ToDictionary(); } } var apiproc = new api.APIProcessor(); apiproc.processAPI(method, data); sendResponse(ctx, apiproc.dataForRemote); } else { sendUI(ctx.Request.Url.LocalPath, ctx); } bool bWaitingToKill = true; while (bWaitingToKill) { try { ctx.Response.OutputStream.Close(); bWaitingToKill = false; } catch { Thread.Sleep(10); } } state_data.reset_event.Set(); }
public void GotRequest(Object stateinfo) { WebServer.thread_info state_data = (WebServer.thread_info)stateinfo; HttpListenerContext ctx = state_data.ctx; //check for /nxt if (ctx.Request.Url.LocalPath.Length == 4 && ctx.Request.Url.LocalPath.Substring(0,4) == "/nxt") { tryTunnel(ctx); } //check for api else if (ctx.Request.Url.LocalPath.Length >= 4 && ctx.Request.Url.LocalPath.Substring(0,4) == "/api") { string method = ctx.Request.Url.LocalPath.Substring(5); //Get the params Dictionary<string,string> data = new Dictionary<string,string>(); if (ctx.Request.QueryString.AllKeys.Length > 0) { if (ctx.Request.QueryString.AllKeys[0] != null) data = (Dictionary<string,string>)ctx.Request.QueryString.ToDictionary(); } var apiproc = new api.APIProcessor(); apiproc.processAPI(method, data); sendResponse(ctx, apiproc.dataForRemote); } else { sendUI(ctx.Request.Url.LocalPath, ctx); } bool bWaitingToKill = true; while (bWaitingToKill) { try { ctx.Response.OutputStream.Close(); bWaitingToKill = false; } catch { Thread.Sleep(10); } } state_data.reset_event.Set(); }