mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-02-14 08:32:22 +00:00
make controller project portable
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Text;
|
||||
using MediaBrowser.Model.Services;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
{
|
||||
@@ -857,28 +858,28 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
return output.ToString();
|
||||
}
|
||||
|
||||
public static NameValueCollection ParseQueryString(string query)
|
||||
public static QueryParamCollection ParseQueryString(string query)
|
||||
{
|
||||
return ParseQueryString(query, Encoding.UTF8);
|
||||
}
|
||||
|
||||
public static NameValueCollection ParseQueryString(string query, Encoding encoding)
|
||||
public static QueryParamCollection ParseQueryString(string query, Encoding encoding)
|
||||
{
|
||||
if (query == null)
|
||||
throw new ArgumentNullException("query");
|
||||
if (encoding == null)
|
||||
throw new ArgumentNullException("encoding");
|
||||
if (query.Length == 0 || (query.Length == 1 && query[0] == '?'))
|
||||
return new NameValueCollection();
|
||||
return new QueryParamCollection();
|
||||
if (query[0] == '?')
|
||||
query = query.Substring(1);
|
||||
|
||||
NameValueCollection result = new HttpQSCollection();
|
||||
QueryParamCollection result = new QueryParamCollection();
|
||||
ParseQueryString(query, encoding, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static void ParseQueryString(string query, Encoding encoding, NameValueCollection result)
|
||||
internal static void ParseQueryString(string query, Encoding encoding, QueryParamCollection result)
|
||||
{
|
||||
if (query.Length == 0)
|
||||
return;
|
||||
|
||||
@@ -5,8 +5,8 @@ using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using MediaBrowser.Model.Services;
|
||||
using ServiceStack;
|
||||
using ServiceStack.Web;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
{
|
||||
@@ -83,7 +83,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
}
|
||||
}
|
||||
|
||||
public NameValueCollection Form
|
||||
public QueryParamCollection Form
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -155,14 +155,15 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
throw new HttpRequestValidationException(msg);
|
||||
}
|
||||
|
||||
static void ValidateNameValueCollection(string name, NameValueCollection coll)
|
||||
static void ValidateNameValueCollection(string name, QueryParamCollection coll)
|
||||
{
|
||||
if (coll == null)
|
||||
return;
|
||||
|
||||
foreach (string key in coll.Keys)
|
||||
foreach (var pair in coll)
|
||||
{
|
||||
string val = coll[key];
|
||||
var key = pair.Name;
|
||||
var val = pair.Value;
|
||||
if (val != null && val.Length > 0 && IsInvalidString(val))
|
||||
ThrowValidationException(name, key, val);
|
||||
}
|
||||
@@ -348,7 +349,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
}
|
||||
}
|
||||
}
|
||||
class WebROCollection : NameValueCollection
|
||||
class WebROCollection : QueryParamCollection
|
||||
{
|
||||
bool got_id;
|
||||
int id;
|
||||
@@ -369,28 +370,29 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
}
|
||||
public void Protect()
|
||||
{
|
||||
IsReadOnly = true;
|
||||
//IsReadOnly = true;
|
||||
}
|
||||
|
||||
public void Unprotect()
|
||||
{
|
||||
IsReadOnly = false;
|
||||
//IsReadOnly = false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
foreach (string key in AllKeys)
|
||||
foreach (var pair in this)
|
||||
{
|
||||
if (result.Length > 0)
|
||||
result.Append('&');
|
||||
|
||||
var key = pair.Name;
|
||||
if (key != null && key.Length > 0)
|
||||
{
|
||||
result.Append(key);
|
||||
result.Append('=');
|
||||
}
|
||||
result.Append(Get(key));
|
||||
result.Append(pair.Value);
|
||||
}
|
||||
|
||||
return result.ToString();
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
using MediaBrowser.Controller.Net;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Server.Implementations.Logging;
|
||||
using ServiceStack;
|
||||
using ServiceStack.Web;
|
||||
using SocketHttpListener.Net;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -11,6 +9,8 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Services;
|
||||
using ServiceStack;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
{
|
||||
@@ -102,12 +102,19 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
{
|
||||
var endpoint = ctx.Request.RemoteEndPoint.ToString();
|
||||
var url = ctx.Request.RawUrl;
|
||||
var queryString = new NameValueCollection(ctx.Request.QueryString ?? new NameValueCollection());
|
||||
var queryString = ctx.Request.QueryString ?? new NameValueCollection();
|
||||
|
||||
var queryParamCollection = new QueryParamCollection();
|
||||
|
||||
foreach (var key in queryString.AllKeys)
|
||||
{
|
||||
queryParamCollection[key] = queryString[key];
|
||||
}
|
||||
|
||||
var connectingArgs = new WebSocketConnectingEventArgs
|
||||
{
|
||||
Url = url,
|
||||
QueryString = queryString,
|
||||
QueryString = queryParamCollection,
|
||||
Endpoint = endpoint
|
||||
};
|
||||
|
||||
@@ -127,7 +134,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
WebSocketConnected(new WebSocketConnectEventArgs
|
||||
{
|
||||
Url = url,
|
||||
QueryString = queryString,
|
||||
QueryString = queryParamCollection,
|
||||
WebSocket = new SharpWebSocket(webSocketContext.WebSocket, _logger),
|
||||
Endpoint = endpoint
|
||||
});
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Funq;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Services;
|
||||
using ServiceStack;
|
||||
using ServiceStack.Host;
|
||||
using ServiceStack.Web;
|
||||
using SocketHttpListener.Net;
|
||||
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 MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
{
|
||||
@@ -27,8 +33,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
_memoryStreamProvider = memoryStreamProvider;
|
||||
this.request = httpContext.Request;
|
||||
this.response = new WebSocketSharpResponse(logger, httpContext.Response, this);
|
||||
|
||||
this.RequestPreferences = new RequestPreferences(this);
|
||||
}
|
||||
|
||||
public HttpListenerRequest HttpRequest
|
||||
@@ -53,8 +57,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
|
||||
public RequestAttributes RequestAttributes { get; set; }
|
||||
|
||||
public IRequestPreferences RequestPreferences { get; private set; }
|
||||
|
||||
public T TryResolve<T>()
|
||||
{
|
||||
if (typeof(T) == typeof(IHttpRequest))
|
||||
@@ -324,22 +326,34 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
get { return request.UserAgent; }
|
||||
}
|
||||
|
||||
private NameValueCollectionWrapper headers;
|
||||
public INameValueCollection Headers
|
||||
private QueryParamCollection headers;
|
||||
public QueryParamCollection Headers
|
||||
{
|
||||
get { return headers ?? (headers = new NameValueCollectionWrapper(request.Headers)); }
|
||||
get { return headers ?? (headers = ToQueryParams(request.Headers)); }
|
||||
}
|
||||
|
||||
private NameValueCollectionWrapper queryString;
|
||||
public INameValueCollection QueryString
|
||||
private QueryParamCollection queryString;
|
||||
public QueryParamCollection QueryString
|
||||
{
|
||||
get { return queryString ?? (queryString = new NameValueCollectionWrapper(MyHttpUtility.ParseQueryString(request.Url.Query))); }
|
||||
get { return queryString ?? (queryString = MyHttpUtility.ParseQueryString(request.Url.Query)); }
|
||||
}
|
||||
|
||||
private NameValueCollectionWrapper formData;
|
||||
public INameValueCollection FormData
|
||||
private QueryParamCollection formData;
|
||||
public QueryParamCollection FormData
|
||||
{
|
||||
get { return formData ?? (formData = new NameValueCollectionWrapper(this.Form)); }
|
||||
get { return formData ?? (formData = this.Form); }
|
||||
}
|
||||
|
||||
private QueryParamCollection ToQueryParams(NameValueCollection collection)
|
||||
{
|
||||
var result = new QueryParamCollection();
|
||||
|
||||
foreach (var key in collection.AllKeys)
|
||||
{
|
||||
result[key] = collection[key];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool IsLocal
|
||||
|
||||
@@ -5,20 +5,21 @@ using System.Net;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using ServiceStack;
|
||||
using ServiceStack.Host;
|
||||
using ServiceStack.Web;
|
||||
using HttpListenerResponse = SocketHttpListener.Net.HttpListenerResponse;
|
||||
using IHttpResponse = MediaBrowser.Model.Services.IHttpResponse;
|
||||
using IRequest = MediaBrowser.Model.Services.IRequest;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
{
|
||||
public class WebSocketSharpResponse : IHttpResponse
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly HttpListenerResponse response;
|
||||
private readonly HttpListenerResponse _response;
|
||||
|
||||
public WebSocketSharpResponse(ILogger logger, HttpListenerResponse response, IRequest request)
|
||||
{
|
||||
_logger = logger;
|
||||
this.response = response;
|
||||
this._response = response;
|
||||
Items = new Dictionary<string, object>();
|
||||
Request = request;
|
||||
}
|
||||
@@ -28,28 +29,28 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
public Dictionary<string, object> Items { get; private set; }
|
||||
public object OriginalResponse
|
||||
{
|
||||
get { return response; }
|
||||
get { return _response; }
|
||||
}
|
||||
|
||||
public int StatusCode
|
||||
{
|
||||
get { return this.response.StatusCode; }
|
||||
set { this.response.StatusCode = value; }
|
||||
get { return this._response.StatusCode; }
|
||||
set { this._response.StatusCode = value; }
|
||||
}
|
||||
|
||||
public string StatusDescription
|
||||
{
|
||||
get { return this.response.StatusDescription; }
|
||||
set { this.response.StatusDescription = value; }
|
||||
get { return this._response.StatusDescription; }
|
||||
set { this._response.StatusDescription = value; }
|
||||
}
|
||||
|
||||
public string ContentType
|
||||
{
|
||||
get { return response.ContentType; }
|
||||
set { response.ContentType = value; }
|
||||
get { return _response.ContentType; }
|
||||
set { _response.ContentType = value; }
|
||||
}
|
||||
|
||||
public ICookies Cookies { get; set; }
|
||||
//public ICookies Cookies { get; set; }
|
||||
|
||||
public void AddHeader(string name, string value)
|
||||
{
|
||||
@@ -59,22 +60,22 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
return;
|
||||
}
|
||||
|
||||
response.AddHeader(name, value);
|
||||
_response.AddHeader(name, value);
|
||||
}
|
||||
|
||||
public string GetHeader(string name)
|
||||
{
|
||||
return response.Headers[name];
|
||||
return _response.Headers[name];
|
||||
}
|
||||
|
||||
public void Redirect(string url)
|
||||
{
|
||||
response.Redirect(url);
|
||||
_response.Redirect(url);
|
||||
}
|
||||
|
||||
public Stream OutputStream
|
||||
{
|
||||
get { return response.OutputStream; }
|
||||
get { return _response.OutputStream; }
|
||||
}
|
||||
|
||||
public object Dto { get; set; }
|
||||
@@ -82,9 +83,9 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
public void Write(string text)
|
||||
{
|
||||
var bOutput = System.Text.Encoding.UTF8.GetBytes(text);
|
||||
response.ContentLength64 = bOutput.Length;
|
||||
_response.ContentLength64 = bOutput.Length;
|
||||
|
||||
var outputStream = response.OutputStream;
|
||||
var outputStream = _response.OutputStream;
|
||||
outputStream.Write(bOutput, 0, bOutput.Length);
|
||||
Close();
|
||||
}
|
||||
@@ -97,7 +98,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
|
||||
try
|
||||
{
|
||||
this.response.CloseOutputStream(_logger);
|
||||
this._response.CloseOutputStream(_logger);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -113,7 +114,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
|
||||
public void Flush()
|
||||
{
|
||||
response.OutputStream.Flush();
|
||||
_response.OutputStream.Flush();
|
||||
}
|
||||
|
||||
public bool IsClosed
|
||||
@@ -127,19 +128,19 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
//you can happily set the Content-Length header in Asp.Net
|
||||
//but HttpListener will complain if you do - you have to set ContentLength64 on the response.
|
||||
//workaround: HttpListener throws "The parameter is incorrect" exceptions when we try to set the Content-Length header
|
||||
response.ContentLength64 = contentLength;
|
||||
_response.ContentLength64 = contentLength;
|
||||
}
|
||||
|
||||
public void SetCookie(Cookie cookie)
|
||||
{
|
||||
var cookieStr = cookie.AsHeaderValue();
|
||||
response.Headers.Add(HttpHeaders.SetCookie, cookieStr);
|
||||
_response.Headers.Add(HttpHeaders.SetCookie, cookieStr);
|
||||
}
|
||||
|
||||
public bool SendChunked
|
||||
{
|
||||
get { return response.SendChunked; }
|
||||
set { response.SendChunked = value; }
|
||||
get { return _response.SendChunked; }
|
||||
set { _response.SendChunked = value; }
|
||||
}
|
||||
|
||||
public bool KeepAlive { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user