aboutsummaryrefslogtreecommitdiff
path: root/SocketHttpListener/Net/HttpConnection.cs
diff options
context:
space:
mode:
Diffstat (limited to 'SocketHttpListener/Net/HttpConnection.cs')
-rw-r--r--SocketHttpListener/Net/HttpConnection.cs54
1 files changed, 16 insertions, 38 deletions
diff --git a/SocketHttpListener/Net/HttpConnection.cs b/SocketHttpListener/Net/HttpConnection.cs
index 4fc9a468c..f11cb0725 100644
--- a/SocketHttpListener/Net/HttpConnection.cs
+++ b/SocketHttpListener/Net/HttpConnection.cs
@@ -3,19 +3,15 @@ using System.IO;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
+using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.IO;
-using Microsoft.Extensions.Logging;
-using MediaBrowser.Model.Net;
using MediaBrowser.Model.System;
-using MediaBrowser.Model.Text;
-using SocketHttpListener.Primitives;
-using System.Security.Authentication;
-
-using System.Threading;
+using Microsoft.Extensions.Logging;
namespace SocketHttpListener.Net
{
sealed class HttpConnection
@@ -46,11 +42,12 @@ namespace SocketHttpListener.Net
private readonly ILogger _logger;
private readonly ICryptoProvider _cryptoProvider;
private readonly IStreamHelper _streamHelper;
- private readonly ITextEncoding _textEncoding;
private readonly IFileSystem _fileSystem;
private readonly IEnvironmentInfo _environment;
- public HttpConnection(ILogger logger, Socket socket, HttpEndPointListener epl, bool secure, X509Certificate cert, ICryptoProvider cryptoProvider, IStreamHelper streamHelper, ITextEncoding textEncoding, IFileSystem fileSystem, IEnvironmentInfo environment)
+ public HttpConnection(ILogger logger, Socket socket, HttpEndPointListener epl, bool secure,
+ X509Certificate cert, ICryptoProvider cryptoProvider, IStreamHelper streamHelper, IFileSystem fileSystem,
+ IEnvironmentInfo environment)
{
_logger = logger;
this._socket = socket;
@@ -59,7 +56,6 @@ namespace SocketHttpListener.Net
this.cert = cert;
_cryptoProvider = cryptoProvider;
_streamHelper = streamHelper;
- _textEncoding = textEncoding;
_fileSystem = fileSystem;
_environment = environment;
@@ -91,13 +87,7 @@ namespace SocketHttpListener.Net
}
}
- public Stream Stream
- {
- get
- {
- return _stream;
- }
- }
+ public Stream Stream => _stream;
public async Task Init()
{
@@ -130,18 +120,12 @@ namespace SocketHttpListener.Net
_position = 0;
_inputState = InputState.RequestLine;
_lineState = LineState.None;
- _context = new HttpListenerContext(this, _textEncoding);
+ _context = new HttpListenerContext(this);
}
- public bool IsClosed
- {
- get { return (_socket == null); }
- }
+ public bool IsClosed => (_socket == null);
- public int Reuses
- {
- get { return _reuses; }
- }
+ public int Reuses => _reuses;
public IPEndPoint LocalEndPoint
{
@@ -155,20 +139,14 @@ namespace SocketHttpListener.Net
}
}
- public IPEndPoint RemoteEndPoint
- {
- get { return _socket.RemoteEndPoint as IPEndPoint; }
- }
+ public IPEndPoint RemoteEndPoint => _socket.RemoteEndPoint as IPEndPoint;
- public bool IsSecure
- {
- get { return secure; }
- }
+ public bool IsSecure => secure;
public ListenerPrefix Prefix
{
- get { return _prefix; }
- set { _prefix = value; }
+ get => _prefix;
+ set => _prefix = value;
}
private void OnTimeout(object unused)
@@ -232,7 +210,7 @@ namespace SocketHttpListener.Net
private static void OnRead(IAsyncResult ares)
{
- HttpConnection cnc = (HttpConnection)ares.AsyncState;
+ var cnc = (HttpConnection)ares.AsyncState;
cnc.OnReadInternal(ares);
}
@@ -447,7 +425,7 @@ namespace SocketHttpListener.Net
else
str = string.Format("<h1>{0}</h1>", description);
- byte[] error = _textEncoding.GetDefaultEncoding().GetBytes(str);
+ byte[] error = Encoding.UTF8.GetBytes(str);
response.Close(error, false);
}
catch