Extend the IHttpServer interface to avoid the typecasting

This commit is contained in:
Claus Vium 2019-02-26 21:27:02 +01:00
parent f1c93ae618
commit e342b7bc71
3 changed files with 24 additions and 16 deletions

View File

@ -655,7 +655,7 @@ namespace Emby.Server.Implementations
return; return;
} }
await ((HttpListenerHost)HttpServer).ProcessWebSocketRequest(context).ConfigureAwait(false); await HttpServer.ProcessWebSocketRequest(context).ConfigureAwait(false);
} }
public async Task ExecuteHttpHandlerAsync(HttpContext context, Func<Task> next) public async Task ExecuteHttpHandlerAsync(HttpContext context, Func<Task> next)
{ {
@ -670,7 +670,7 @@ namespace Emby.Server.Implementations
var localPath = context.Request.Path.ToString(); var localPath = context.Request.Path.ToString();
var req = new WebSocketSharpRequest(request, response, request.Path, Logger); var req = new WebSocketSharpRequest(request, response, request.Path, Logger);
await ((HttpListenerHost)HttpServer).RequestHandler(req, request.GetDisplayUrl(), request.Host.ToString(), localPath, CancellationToken.None).ConfigureAwait(false); await HttpServer.RequestHandler(req, request.GetDisplayUrl(), request.Host.ToString(), localPath, CancellationToken.None).ConfigureAwait(false);
} }
protected virtual IHttpClient CreateHttpClient() protected virtual IHttpClient CreateHttpClient()

View File

@ -1,9 +1,7 @@
using System; using System;
using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Emby.Server.Implementations.Net; using Emby.Server.Implementations.Net;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
namespace Emby.Server.Implementations.HttpServer namespace Emby.Server.Implementations.HttpServer
@ -28,18 +26,6 @@ namespace Emby.Server.Implementations.HttpServer
/// <value>The web socket handler.</value> /// <value>The web socket handler.</value>
Action<WebSocketConnectEventArgs> WebSocketConnected { get; set; } Action<WebSocketConnectEventArgs> WebSocketConnected { get; set; }
/// <summary>
/// Gets or sets the web socket connecting.
/// </summary>
/// <value>The web socket connecting.</value>
Action<WebSocketConnectingEventArgs> WebSocketConnecting { get; set; }
/// <summary>
/// Starts this instance.
/// </summary>
/// <param name="urlPrefixes">The URL prefixes.</param>
void Start(IEnumerable<string> urlPrefixes);
/// <summary> /// <summary>
/// Stops this instance. /// Stops this instance.
/// </summary> /// </summary>

View File

@ -1,7 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Events; using MediaBrowser.Model.Events;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.AspNetCore.Http;
namespace MediaBrowser.Controller.Net namespace MediaBrowser.Controller.Net
{ {
@ -35,5 +38,24 @@ namespace MediaBrowser.Controller.Net
/// If set, all requests will respond with this message /// If set, all requests will respond with this message
/// </summary> /// </summary>
string GlobalResponse { get; set; } string GlobalResponse { get; set; }
/// <summary>
/// Sends the http context to the socket listener
/// </summary>
/// <param name="ctx"></param>
/// <returns></returns>
Task ProcessWebSocketRequest(HttpContext ctx);
/// <summary>
/// The HTTP request handler
/// </summary>
/// <param name="httpReq"></param>
/// <param name="urlString"></param>
/// <param name="host"></param>
/// <param name="localPath"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task RequestHandler(IHttpRequest httpReq, string urlString, string host, string localPath,
CancellationToken cancellationToken);
} }
} }