The Free Software Media System - Server Backend & API
Reorder elements
Bond-009cb9e50b2eae1
diff --git a/Jellyfin.Server/SocketSharp/RequestMono.cs b/Jellyfin.Server/SocketSharp/RequestMono.csindex dd38b058b1..fe8e8242a6 100644--- a/Jellyfin.Server/SocketSharp/RequestMono.cs+++ b/Jellyfin.Server/SocketSharp/RequestMono.cs@@ -185,6 +185,7 @@ namespace Jellyfin.Server.SocketSharpfor (int idx = 1; idx < len; idx++){char next = val[idx];+// See http://secunia.com/advisories/14325if (current == '<' || current == '\xff1c'){@@ -556,15 +557,23 @@ namespace Jellyfin.Server.SocketSharp}}+ private const byte LF = (byte)'\n';++ private const byte CR = (byte)'\r';+private Stream data;+private string boundary;- private byte[] boundary_bytes;++ private byte[] boundaryBytes;+private byte[] buffer;- private bool at_eof;++ private bool atEof;+private Encoding encoding;- private StringBuilder sb;- private const byte LF = (byte)'\n', CR = (byte)'\r';+ private StringBuilder sb;// See RFC 2046// In the case of multipart entities, in which one or more different@@ -580,12 +589,48 @@ namespace Jellyfin.Server.SocketSharp{this.data = data;boundary = b;- boundary_bytes = encoding.GetBytes(b);- buffer = new byte[boundary_bytes.Length + 2]; // CRLF or '--'+ boundaryBytes = encoding.GetBytes(b);+ buffer = new byte[boundaryBytes.Length + 2]; // CRLF or '--'this.encoding = encoding;sb = new StringBuilder();}+ public Element ReadNextElement()+ {+ if (atEof || ReadBoundary())+ {+ return null;+ }++ var elem = new Element();+ string header;+ while ((header = ReadHeaders()) != null)+ {+ if (StrUtils.StartsWith(header, "Content-Disposition:", true))+ {+ elem.Name = GetContentDispositionAttribute(header, "name");+ elem.Filename = StripPath(GetContentDispositionAttributeWithEncoding(header, "filename"));+ }+ else if (StrUtils.StartsWith(header, "Content-Type:", true))+ {+ elem.ContentType = header.Substring("Content-Type:".Length).Trim();+ elem.Encoding = GetEncoding(elem.ContentType);+ }+ }++ long start = 0;+ start = data.Position;+ elem.Start = start;+ long pos = MoveToNextBoundary();+ if (pos == -1)+ {+ return null;+ }++ elem.Length = pos - start;+ return elem;+ }+private string ReadLine(){// CRLF or LF are ok as line endings.@@ -774,7 +819,7 @@ namespace Jellyfin.Server.SocketSharpreturn -1;}- if (!CompareBytes(boundary_bytes, buffer))+ if (!CompareBytes(boundaryBytes, buffer)){state = 0;data.Position = retval + 2;@@ -790,7 +835,7 @@ namespace Jellyfin.Server.SocketSharpif (buffer[bl - 2] == '-' && buffer[bl - 1] == '-'){- at_eof = true;+ atEof = true;}else if (buffer[bl - 2] != CR || buffer[bl - 1] != LF){@@ -824,42 +869,6 @@ namespace Jellyfin.Server.SocketSharpreturn retval;}- public Element ReadNextElement()- {- if (at_eof || ReadBoundary())- {- return null;- }-- var elem = new Element();- string header;- while ((header = ReadHeaders()) != null)- {- if (StrUtils.StartsWith(header, "Content-Disposition:", true))- {- elem.Name = GetContentDispositionAttribute(header, "name");- elem.Filename = StripPath(GetContentDispositionAttributeWithEncoding(header, "filename"));- }- else if (StrUtils.StartsWith(header, "Content-Type:", true))- {- elem.ContentType = header.Substring("Content-Type:".Length).Trim();- elem.Encoding = GetEncoding(elem.ContentType);- }- }-- long start = 0;- start = data.Position;- elem.Start = start;- long pos = MoveToNextBoundary();- if (pos == -1)- {- return null;- }-- elem.Length = pos - start;- return elem;- }-private static string StripPath(string path){if (path == null || path.Length == 0)diff --git a/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs b/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.csindex 6de678b86c..56e5c73d61 100644--- a/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs+++ b/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs@@ -18,6 +18,7 @@ namespace Jellyfin.Server.SocketSharppublic class WebSocketSharpResponse : IHttpResponse{private readonly ILogger _logger;+private readonly HttpListenerResponse _response;public WebSocketSharpResponse(ILogger logger, HttpListenerResponse response, IRequest request)@@ -29,7 +30,9 @@ namespace Jellyfin.Server.SocketSharp}public IRequest Request { get; private set; }+public Dictionary<string, object> Items { get; private set; }+public object OriginalResponse => _response;public int StatusCode@@ -50,7 +53,7 @@ namespace Jellyfin.Server.SocketSharpset => _response.ContentType = value;}- // public ICookies Cookies { get; set; }+ public QueryParamCollection Headers => _response.Headers;public void AddHeader(string name, string value){@@ -63,8 +66,6 @@ namespace Jellyfin.Server.SocketSharp_response.AddHeader(name, value);}- public QueryParamCollection Headers => _response.Headers;-public string GetHeader(string name){return _response.Headers[name];