|
|
|
@ -7,6 +7,7 @@ using ServiceStack.Web;
|
|
|
|
|
using SocketHttpListener.Net;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
@ -18,14 +19,11 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
|
|
|
|
private HttpListener _listener;
|
|
|
|
|
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly Action<string> _endpointListener;
|
|
|
|
|
private readonly string _certificatePath;
|
|
|
|
|
|
|
|
|
|
public WebSocketSharpListener(ILogger logger, Action<string> endpointListener,
|
|
|
|
|
string certificatePath)
|
|
|
|
|
public WebSocketSharpListener(ILogger logger, string certificatePath)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_endpointListener = endpointListener;
|
|
|
|
|
_certificatePath = certificatePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -80,7 +78,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
|
|
|
|
{
|
|
|
|
|
var request = context.Request;
|
|
|
|
|
|
|
|
|
|
LogHttpRequest(request);
|
|
|
|
|
LogRequest(_logger, request);
|
|
|
|
|
|
|
|
|
|
if (request.IsWebSocketRequest)
|
|
|
|
|
{
|
|
|
|
@ -96,24 +94,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
|
|
|
|
return RequestHandler(httpReq, request.Url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Logs the HTTP request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
private void LogHttpRequest(HttpListenerRequest request)
|
|
|
|
|
{
|
|
|
|
|
var endpoint = request.LocalEndPoint;
|
|
|
|
|
|
|
|
|
|
if (endpoint != null)
|
|
|
|
|
{
|
|
|
|
|
var address = endpoint.ToString();
|
|
|
|
|
|
|
|
|
|
_endpointListener(address);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LogRequest(_logger, request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProcessWebSocketRequest(HttpListenerContext ctx)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@ -183,7 +163,35 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
private static void LogRequest(ILogger logger, HttpListenerRequest request)
|
|
|
|
|
{
|
|
|
|
|
logger.Info("{0} {1}. UserAgent: {2}", (request.IsWebSocketRequest ? "WS" : "HTTP " + request.HttpMethod), request.Url, request.UserAgent ?? string.Empty);
|
|
|
|
|
var url = request.Url.ToString();
|
|
|
|
|
var extension = Path.GetExtension(url);
|
|
|
|
|
|
|
|
|
|
if (string.Equals(extension, ".js", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (string.Equals(extension, ".css", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (string.Equals(extension, ".woff", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (string.Equals(extension, ".woff2", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (string.Equals(extension, ".ttf", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (string.Equals(extension, ".html", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.Info("{0} {1}. UserAgent: {2}", (request.IsWebSocketRequest ? "WS" : "HTTP " + request.HttpMethod), url, request.UserAgent ?? string.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleError(Exception ex, HttpListenerContext context)
|
|
|
|
|