mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
update responses
This commit is contained in:
parent
23691e181b
commit
7815d65e5c
@ -79,12 +79,6 @@ namespace SocketHttpListener.Net
|
||||
private int _trailerState;
|
||||
private List<Chunk> _chunks;
|
||||
|
||||
public ChunkStream(byte[] buffer, int offset, int size, WebHeaderCollection headers)
|
||||
: this(headers)
|
||||
{
|
||||
Write(buffer, offset, size);
|
||||
}
|
||||
|
||||
public ChunkStream(WebHeaderCollection headers)
|
||||
{
|
||||
_headers = headers;
|
||||
@ -102,13 +96,6 @@ namespace SocketHttpListener.Net
|
||||
_chunks.Clear();
|
||||
}
|
||||
|
||||
public void WriteAndReadBack(byte[] buffer, int offset, int size, ref int read)
|
||||
{
|
||||
if (offset + read > 0)
|
||||
Write(buffer, offset, offset + read);
|
||||
read = Read(buffer, offset, size);
|
||||
}
|
||||
|
||||
public int Read(byte[] buffer, int offset, int size)
|
||||
{
|
||||
return ReadFromChunks(buffer, offset, size);
|
||||
@ -143,6 +130,9 @@ namespace SocketHttpListener.Net
|
||||
|
||||
public void Write(byte[] buffer, int offset, int size)
|
||||
{
|
||||
// Note, the logic here only works when offset is 0 here.
|
||||
// Otherwise, it would treat "size" as the end offset instead of an actual byte count from offset.
|
||||
|
||||
if (offset < size)
|
||||
InternalWrite(buffer, ref offset, size);
|
||||
}
|
||||
|
@ -122,11 +122,19 @@ namespace SocketHttpListener.Net
|
||||
try
|
||||
{
|
||||
int nread = base.EndRead(base_ares);
|
||||
if (nread == 0)
|
||||
{
|
||||
_no_more_data = true;
|
||||
ares._count = rb.InitialCount - rb.Count;
|
||||
ares.Complete();
|
||||
return;
|
||||
}
|
||||
|
||||
_decoder.Write(ares._buffer, ares._offset, nread);
|
||||
nread = _decoder.Read(rb.Buffer, rb.Offset, rb.Count);
|
||||
rb.Offset += nread;
|
||||
rb.Count -= nread;
|
||||
if (rb.Count == 0 || !_decoder.WantMore || nread == 0)
|
||||
if (rb.Count == 0 || !_decoder.WantMore)
|
||||
{
|
||||
_no_more_data = !_decoder.WantMore && nread == 0;
|
||||
ares._count = rb.InitialCount - rb.Count;
|
||||
@ -164,7 +172,7 @@ namespace SocketHttpListener.Net
|
||||
asyncResult.AsyncWaitHandle.WaitOne();
|
||||
|
||||
if (ares._error != null)
|
||||
throw new HttpListenerException((int)HttpStatusCode.BadRequest, "Bad Request");
|
||||
throw new HttpListenerException((int)HttpStatusCode.BadRequest, "Operation aborted");
|
||||
|
||||
return ares._count;
|
||||
}
|
||||
|
@ -268,7 +268,8 @@ namespace SocketHttpListener.Net
|
||||
|
||||
if (!_epl.BindContext(_context))
|
||||
{
|
||||
SendError("Invalid host", 400);
|
||||
const int NotFoundErrorCode = 404;
|
||||
SendError(HttpStatusDescription.Get(NotFoundErrorCode), NotFoundErrorCode);
|
||||
Close(true);
|
||||
return;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ namespace SocketHttpListener.Net
|
||||
HttpListenerContext context;
|
||||
bool is_chunked;
|
||||
bool ka_set;
|
||||
bool keep_alive;
|
||||
bool? _keepAlive;
|
||||
|
||||
private readonly ITextEncoding _textEncoding;
|
||||
|
||||
@ -525,29 +525,35 @@ namespace SocketHttpListener.Net
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ka_set)
|
||||
return keep_alive;
|
||||
|
||||
ka_set = true;
|
||||
// 1. Connection header
|
||||
// 2. Protocol (1.1 == keep-alive by default)
|
||||
// 3. Keep-Alive header
|
||||
string cnc = headers["Connection"];
|
||||
if (!String.IsNullOrEmpty(cnc))
|
||||
if (!_keepAlive.HasValue)
|
||||
{
|
||||
keep_alive = (0 == String.Compare(cnc, "keep-alive", StringComparison.OrdinalIgnoreCase));
|
||||
string header = Headers["Proxy-Connection"];
|
||||
if (string.IsNullOrEmpty(header))
|
||||
{
|
||||
header = Headers["Connection"];
|
||||
}
|
||||
else if (version == HttpVersion.Version11)
|
||||
if (string.IsNullOrEmpty(header))
|
||||
{
|
||||
keep_alive = true;
|
||||
if (ProtocolVersion >= HttpVersion.Version11)
|
||||
{
|
||||
_keepAlive = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
cnc = headers["keep-alive"];
|
||||
if (!String.IsNullOrEmpty(cnc))
|
||||
keep_alive = (0 != String.Compare(cnc, "closed", StringComparison.OrdinalIgnoreCase));
|
||||
header = Headers["Keep-Alive"];
|
||||
_keepAlive = !string.IsNullOrEmpty(header);
|
||||
}
|
||||
return keep_alive;
|
||||
}
|
||||
else
|
||||
{
|
||||
header = header.ToLower(CultureInfo.InvariantCulture);
|
||||
_keepAlive =
|
||||
header.IndexOf("close", StringComparison.OrdinalIgnoreCase) < 0 ||
|
||||
header.IndexOf("keep-alive", StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
return _keepAlive.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,10 +66,7 @@ namespace SocketHttpListener.Net
|
||||
}
|
||||
}
|
||||
|
||||
public bool CompletedSynchronously
|
||||
{
|
||||
get { return (_synchRead == _count); }
|
||||
}
|
||||
public bool CompletedSynchronously => false;
|
||||
|
||||
public bool IsCompleted
|
||||
{
|
||||
|
26
SocketHttpListener/Net/UriScheme.cs
Normal file
26
SocketHttpListener/Net/UriScheme.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SocketHttpListener.Net
|
||||
{
|
||||
internal class UriScheme
|
||||
{
|
||||
public const string File = "file";
|
||||
public const string Ftp = "ftp";
|
||||
public const string Gopher = "gopher";
|
||||
public const string Http = "http";
|
||||
public const string Https = "https";
|
||||
public const string News = "news";
|
||||
public const string NetPipe = "net.pipe";
|
||||
public const string NetTcp = "net.tcp";
|
||||
public const string Nntp = "nntp";
|
||||
public const string Mailto = "mailto";
|
||||
public const string Ws = "ws";
|
||||
public const string Wss = "wss";
|
||||
|
||||
public const string SchemeDelimiter = "://";
|
||||
}
|
||||
}
|
@ -82,6 +82,7 @@
|
||||
<Compile Include="Net\HttpStreamAsyncResult.cs" />
|
||||
<Compile Include="Net\HttpVersion.cs" />
|
||||
<Compile Include="Net\ListenerPrefix.cs" />
|
||||
<Compile Include="Net\UriScheme.cs" />
|
||||
<Compile Include="Net\WebHeaderCollection.cs" />
|
||||
<Compile Include="Net\WebHeaderEncoding.cs" />
|
||||
<Compile Include="Net\WebSockets\HttpListenerWebSocketContext.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user