private void ProcessM3u8(HttpListenerContext context, JT1078AVInfo jT1078AVInfo) { if (authorization.Authorization(context, out IPrincipal principal)) { hLSRequestManager.HandleHlsRequest(context, principal, jT1078AVInfo); } }
public Task StartAsync(CancellationToken cancellationToken) { if (!HttpListener.IsSupported) { Logger.LogWarning("Windows XP SP2 or Server 2003 is required to use the HttpListener class."); return(Task.CompletedTask); } listener = new HttpListener(); listener.AuthenticationSchemes = AuthenticationSchemes.Anonymous; try { listener.Prefixes.Add($"http://*:{Configuration.HttpPort}/"); listener.Start(); } catch (System.Net.HttpListenerException ex) { Logger.LogWarning(ex, $"{ex.Message}:使用cmd命令[netsh http add urlacl url=http://*:{Configuration.HttpPort}/ user=Everyone]"); } Logger.LogInformation($"JT1078 Http Server start at {IPAddress.Any}:{Configuration.HttpPort}."); Task.Factory.StartNew(async() => { while (listener.IsListening) { var context = await listener.GetContextAsync(); try { await Task.Run(async() => { IPrincipal principal = null; if (context.Request.RawUrl.Contains(".ts") || authorization.Authorization(context, out principal)) { await ProcessRequestAsync(context, principal); } else { await context.Http401(); } }); } catch (Exception ex) { await context.Http500(); Logger.LogError(ex, ex.StackTrace); } } }, cancellationToken); return(Task.CompletedTask); }
void HandleHttpRequest(IChannelHandlerContext ctx, IFullHttpRequest req) { // Handle a bad request. if (!req.Result.IsSuccess) { SendHttpResponse(ctx, req, new DefaultFullHttpResponse(Http11, BadRequest)); return; } if ("/favicon.ico".Equals(req.Uri)) { var res = new DefaultFullHttpResponse(Http11, NotFound); SendHttpResponse(ctx, req, res); return; } if (iJT1078Authorization.Authorization(req, out var principal)) { if (req.Uri.StartsWith(WebsocketPath)) { // Handshake var wsFactory = new WebSocketServerHandshakerFactory(GetWebSocketLocation(req), null, true, 5 * 1024 * 1024); this.handshaker = wsFactory.NewHandshaker(req); if (this.handshaker == null) { WebSocketServerHandshakerFactory.SendUnsupportedVersionResponse(ctx.Channel); } else { this.handshaker.HandshakeAsync(ctx.Channel, req); jT1078HttpSessionManager.TryAdd(principal.Identity.Name, ctx.Channel); httpMiddleware?.Next(ctx, req, principal); } } else { jT1078HttpSessionManager.TryAdd(principal.Identity.Name, ctx.Channel); httpMiddleware?.Next(ctx, req, principal); } } else { SendHttpResponse(ctx, req, new DefaultFullHttpResponse(Http11, Unauthorized)); return; } }
public Task StartAsync(CancellationToken cancellationToken) { if (!HttpListener.IsSupported) { Logger.LogWarning("Windows XP SP2 or Server 2003 is required to use the HttpListener class."); return(Task.CompletedTask); } listener = new HttpListener(); listener.AuthenticationSchemes = AuthenticationSchemes.Anonymous; listener.Prefixes.Add($"http://*:{Configuration.HttpPort}/"); listener.Start(); Logger.LogInformation($"JT1078 Http Server start at {IPAddress.Any}:{Configuration.HttpPort}."); Task.Factory.StartNew(async() => { while (listener.IsListening) { var context = await listener.GetContextAsync(); try { if (authorization.Authorization(context, out var principal)) { //new JT1078HttpContext(context, principal); //todo:session manager await ProcessRequestAsync(context); } else { await Http401(context); } } catch (Exception ex) { await Http500(context); Logger.LogError(ex, ex.StackTrace); } } }, cancellationToken); return(Task.CompletedTask); }