aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations
diff options
context:
space:
mode:
authorClaus Vium <clausvium@gmail.com>2019-02-27 14:23:39 +0100
committerClaus Vium <clausvium@gmail.com>2019-02-27 14:23:39 +0100
commit27e7e792b3d95912787c613f849548809d48f6b1 (patch)
tree4088af01b46efb0881ba43db33bb60f56ca91911 /Emby.Server.Implementations
parent91afaaf8fe43035bb4832da44b6d6741d2815fb5 (diff)
Replace some usage of QueryParamCollection
Diffstat (limited to 'Emby.Server.Implementations')
-rw-r--r--Emby.Server.Implementations/HttpServer/HttpListenerHost.cs7
-rw-r--r--Emby.Server.Implementations/HttpServer/HttpResultFactory.cs19
-rw-r--r--Emby.Server.Implementations/HttpServer/WebSocketConnection.cs3
-rw-r--r--Emby.Server.Implementations/Net/WebSocketConnectEventArgs.cs3
-rw-r--r--Emby.Server.Implementations/Services/ServiceHandler.cs2
-rw-r--r--Emby.Server.Implementations/Session/SessionWebSocketListener.cs3
-rw-r--r--Emby.Server.Implementations/SocketSharp/RequestMono.cs2
-rw-r--r--Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs6
-rw-r--r--Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs12
-rw-r--r--Emby.Server.Implementations/SocketSharp/WebSocketSharpResponse.cs83
10 files changed, 28 insertions, 112 deletions
diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
index 2abc6c2f4f..70753e5634 100644
--- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
+++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
@@ -22,6 +22,7 @@ using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Internal;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
@@ -154,7 +155,7 @@ namespace Emby.Server.Implementations.HttpServer
{
OnReceive = ProcessWebSocketMessageReceived,
Url = e.Url,
- QueryString = e.QueryString ?? new QueryParamCollection()
+ QueryString = e.QueryString ?? new QueryCollection()
};
connection.Closed += Connection_Closed;
@@ -606,8 +607,8 @@ namespace Emby.Server.Implementations.HttpServer
}
finally
{
- httpRes.Close();
-
+ // TODO
+ httpRes.IsClosed = true;
stopWatch.Stop();
var elapsed = stopWatch.Elapsed;
if (elapsed.TotalMilliseconds > 500)
diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs
index 09cdbc3c26..52c8221f68 100644
--- a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs
+++ b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs
@@ -16,6 +16,8 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Primitives;
+using Microsoft.Net.Http.Headers;
using IRequest = MediaBrowser.Model.Services.IRequest;
using MimeTypes = MediaBrowser.Model.Net.MimeTypes;
@@ -246,9 +248,9 @@ namespace Emby.Server.Implementations.HttpServer
private static string GetCompressionType(IRequest request)
{
- var acceptEncoding = request.Headers["Accept-Encoding"];
+ var acceptEncoding = request.Headers["Accept-Encoding"].ToString();
- if (acceptEncoding != null)
+ if (string.IsNullOrEmpty(acceptEncoding))
{
//if (_brotliCompressor != null && acceptEncoding.IndexOf("br", StringComparison.OrdinalIgnoreCase) != -1)
// return "br";
@@ -424,12 +426,12 @@ namespace Emby.Server.Implementations.HttpServer
/// </summary>
private object GetCachedResult(IRequest requestContext, IDictionary<string, string> responseHeaders, StaticResultOptions options)
{
- bool noCache = (requestContext.Headers.Get("Cache-Control") ?? string.Empty).IndexOf("no-cache", StringComparison.OrdinalIgnoreCase) != -1;
+ bool noCache = (requestContext.Headers[HeaderNames.CacheControl].ToString()).IndexOf("no-cache", StringComparison.OrdinalIgnoreCase) != -1;
AddCachingHeaders(responseHeaders, options.CacheDuration, noCache, options.DateLastModified);
if (!noCache)
{
- DateTime.TryParse(requestContext.Headers.Get("If-Modified-Since"), out var ifModifiedSinceHeader);
+ DateTime.TryParse(requestContext.Headers[HeaderNames.IfModifiedSince], out var ifModifiedSinceHeader);
if (IsNotModified(ifModifiedSinceHeader, options.CacheDuration, options.DateLastModified))
{
@@ -530,7 +532,7 @@ namespace Emby.Server.Implementations.HttpServer
options.ResponseHeaders = options.ResponseHeaders ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
var contentType = options.ContentType;
- if (!string.IsNullOrEmpty(requestContext.Headers.Get("If-Modified-Since")))
+ if (!StringValues.IsNullOrEmpty(requestContext.Headers[HeaderNames.IfModifiedSince]))
{
// See if the result is already cached in the browser
var result = GetCachedResult(requestContext, options.ResponseHeaders, options);
@@ -548,7 +550,7 @@ namespace Emby.Server.Implementations.HttpServer
AddCachingHeaders(responseHeaders, options.CacheDuration, false, options.DateLastModified);
AddAgeHeader(responseHeaders, options.DateLastModified);
- var rangeHeader = requestContext.Headers.Get("Range");
+ var rangeHeader = requestContext.Headers["Range"];
if (!isHeadRequest && !string.IsNullOrEmpty(options.Path))
{
@@ -610,11 +612,6 @@ namespace Emby.Server.Implementations.HttpServer
}
/// <summary>
- /// The us culture
- /// </summary>
- private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
-
- /// <summary>
/// Adds the caching responseHeaders.
/// </summary>
private void AddCachingHeaders(IDictionary<string, string> responseHeaders, TimeSpan? cacheDuration,
diff --git a/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs b/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs
index e9d0bac74d..2bf460bd11 100644
--- a/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs
+++ b/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs
@@ -8,6 +8,7 @@ using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
+using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using UtfUnknown;
@@ -67,7 +68,7 @@ namespace Emby.Server.Implementations.HttpServer
/// Gets or sets the query string.
/// </summary>
/// <value>The query string.</value>
- public QueryParamCollection QueryString { get; set; }
+ public IQueryCollection QueryString { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="WebSocketConnection" /> class.
diff --git a/Emby.Server.Implementations/Net/WebSocketConnectEventArgs.cs b/Emby.Server.Implementations/Net/WebSocketConnectEventArgs.cs
index 666f1f6011..e3047d3926 100644
--- a/Emby.Server.Implementations/Net/WebSocketConnectEventArgs.cs
+++ b/Emby.Server.Implementations/Net/WebSocketConnectEventArgs.cs
@@ -1,6 +1,7 @@
using System;
using System.Net.WebSockets;
using MediaBrowser.Model.Services;
+using Microsoft.AspNetCore.Http;
namespace Emby.Server.Implementations.Net
{
@@ -15,7 +16,7 @@ namespace Emby.Server.Implementations.Net
/// Gets or sets the query string.
/// </summary>
/// <value>The query string.</value>
- public QueryParamCollection QueryString { get; set; }
+ public IQueryCollection QueryString { get; set; }
/// <summary>
/// Gets or sets the web socket.
/// </summary>
diff --git a/Emby.Server.Implementations/Services/ServiceHandler.cs b/Emby.Server.Implementations/Services/ServiceHandler.cs
index 7e836e22c3..3c8adfc983 100644
--- a/Emby.Server.Implementations/Services/ServiceHandler.cs
+++ b/Emby.Server.Implementations/Services/ServiceHandler.cs
@@ -154,7 +154,7 @@ namespace Emby.Server.Implementations.Services
{
if (name == null) continue; //thank you ASP.NET
- var values = request.QueryString.GetValues(name);
+ var values = request.QueryString[name];
if (values.Count == 1)
{
map[name] = values[0];
diff --git a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
index 24903f5e8c..a551433ed9 100644
--- a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
+++ b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
@@ -5,6 +5,7 @@ using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
+using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.Session
@@ -62,7 +63,7 @@ namespace Emby.Server.Implementations.Session
}
}
- private SessionInfo GetSession(QueryParamCollection queryString, string remoteEndpoint)
+ private SessionInfo GetSession(IQueryCollection queryString, string remoteEndpoint)
{
if (queryString == null)
{
diff --git a/Emby.Server.Implementations/SocketSharp/RequestMono.cs b/Emby.Server.Implementations/SocketSharp/RequestMono.cs
index 113f76b10b..f73adc5ff8 100644
--- a/Emby.Server.Implementations/SocketSharp/RequestMono.cs
+++ b/Emby.Server.Implementations/SocketSharp/RequestMono.cs
@@ -118,8 +118,6 @@ namespace Emby.Server.Implementations.SocketSharp
public string Authorization => StringValues.IsNullOrEmpty(request.Headers["Authorization"]) ? null : request.Headers["Authorization"].ToString();
- protected bool validate_cookies { get; set; }
- protected bool validate_query_string { get; set; }
protected bool validate_form { get; set; }
protected bool checked_form { get; set; }
diff --git a/Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs b/Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs
index 77469244b9..9f046c3fd0 100644
--- a/Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs
+++ b/Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs
@@ -52,12 +52,10 @@ using Microsoft.Extensions.Logging;
var endpoint = ctx.Connection.RemoteIpAddress.ToString();
var url = ctx.Request.GetDisplayUrl();
- var queryString = new QueryParamCollection(ctx.Request.Query);
-
var connectingArgs = new WebSocketConnectingEventArgs
{
Url = url,
- QueryString = queryString,
+ QueryString = ctx.Request.Query,
Endpoint = endpoint
};
@@ -73,7 +71,7 @@ using Microsoft.Extensions.Logging;
WebSocketConnected(new WebSocketConnectEventArgs
{
Url = url,
- QueryString = queryString,
+ QueryString = ctx.Request.Query,
WebSocket = socket,
Endpoint = endpoint
});
diff --git a/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs b/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs
index bddccf68ba..24fd36062f 100644
--- a/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs
+++ b/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs
@@ -13,7 +13,6 @@ using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
using IHttpFile = MediaBrowser.Model.Services.IHttpFile;
using IHttpRequest = MediaBrowser.Model.Services.IHttpRequest;
-using IHttpResponse = MediaBrowser.Model.Services.IHttpResponse;
using IResponse = MediaBrowser.Model.Services.IResponse;
namespace Emby.Server.Implementations.SocketSharp
@@ -21,7 +20,7 @@ namespace Emby.Server.Implementations.SocketSharp
public partial class WebSocketSharpRequest : IHttpRequest
{
private readonly HttpRequest request;
- private readonly IHttpResponse response;
+ private readonly IResponse response;
public WebSocketSharpRequest(HttpRequest httpContext, HttpResponse response, string operationName, ILogger logger)
{
@@ -34,11 +33,9 @@ namespace Emby.Server.Implementations.SocketSharp
public HttpRequest HttpRequest => request;
- public object OriginalRequest => request;
-
public IResponse Response => response;
- public IHttpResponse HttpResponse => response;
+ public IResponse HttpResponse => response;
public string OperationName { get; set; }
@@ -396,10 +393,9 @@ namespace Emby.Server.Implementations.SocketSharp
public string UserAgent => request.Headers[HeaderNames.UserAgent];
- public QueryParamCollection Headers => new QueryParamCollection(request.Headers);
+ public IHeaderDictionary Headers => request.Headers;
- private QueryParamCollection queryString;
- public QueryParamCollection QueryString => queryString ?? (queryString = new QueryParamCollection(request.Query));
+ public IQueryCollection QueryString => request.Query;
public bool IsLocal => string.Equals(request.HttpContext.Connection.LocalIpAddress.ToString(), request.HttpContext.Connection.RemoteIpAddress.ToString());
diff --git a/Emby.Server.Implementations/SocketSharp/WebSocketSharpResponse.cs b/Emby.Server.Implementations/SocketSharp/WebSocketSharpResponse.cs
index f9ecb52a55..c4fbaddd3e 100644
--- a/Emby.Server.Implementations/SocketSharp/WebSocketSharpResponse.cs
+++ b/Emby.Server.Implementations/SocketSharp/WebSocketSharpResponse.cs
@@ -1,23 +1,18 @@
using System;
using System.Collections.Generic;
using System.IO;
-using System.Net;
-using System.Net.Sockets;
using System.Runtime.InteropServices;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
-using Emby.Server.Implementations;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
-using IHttpResponse = MediaBrowser.Model.Services.IHttpResponse;
using IRequest = MediaBrowser.Model.Services.IRequest;
namespace Emby.Server.Implementations.SocketSharp
{
- public class WebSocketSharpResponse : IHttpResponse
+ public class WebSocketSharpResponse : IResponse
{
private readonly ILogger _logger;
@@ -51,42 +46,7 @@ namespace Emby.Server.Implementations.SocketSharp
set => _response.ContentType = value;
}
- public QueryParamCollection Headers => new QueryParamCollection(_response.Headers);
-
- private static string AsHeaderValue(Cookie cookie)
- {
- DateTime defaultExpires = DateTime.MinValue;
-
- var path = cookie.Expires == defaultExpires
- ? "/"
- : cookie.Path ?? "/";
-
- var sb = new StringBuilder();
-
- sb.Append($"{cookie.Name}={cookie.Value};path={path}");
-
- if (cookie.Expires != defaultExpires)
- {
- sb.Append($";expires={cookie.Expires:R}");
- }
-
- if (!string.IsNullOrEmpty(cookie.Domain))
- {
- sb.Append($";domain={cookie.Domain}");
- }
-
- if (cookie.Secure)
- {
- sb.Append(";Secure");
- }
-
- if (cookie.HttpOnly)
- {
- sb.Append(";HttpOnly");
- }
-
- return sb.ToString();
- }
+ public IHeaderDictionary Headers => _response.Headers;
public void AddHeader(string name, string value)
{
@@ -111,51 +71,14 @@ namespace Emby.Server.Implementations.SocketSharp
public Stream OutputStream => _response.Body;
- public void Close()
- {
- if (!this.IsClosed)
- {
- this.IsClosed = true;
-
- try
- {
- var response = this._response;
-
- var outputStream = response.Body;
-
- // This is needed with compression
- outputStream.Flush();
- outputStream.Dispose();
- }
- catch (SocketException)
- {
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Error in HttpListenerResponseWrapper");
- }
- }
- }
-
public bool IsClosed
{
get;
- private set;
- }
-
- public void SetCookie(Cookie cookie)
- {
- var cookieStr = AsHeaderValue(cookie);
- _response.Headers.Add("Set-Cookie", cookieStr);
+ set;
}
public bool SendChunked { get; set; }
- public bool KeepAlive { get; set; }
-
- public void ClearCookies()
- {
- }
const int StreamCopyToBufferSize = 81920;
public async Task TransmitFile(string path, long offset, long count, FileShareMode fileShareMode, IFileSystem fileSystem, IStreamHelper streamHelper, CancellationToken cancellationToken)
{