Refactored HttpConnection.cs
This commit is contained in:
parent
fe28277f14
commit
16f5c03b95
@ -52,21 +52,6 @@ namespace WebSocketSharp.Net
|
||||
{
|
||||
internal sealed class HttpConnection
|
||||
{
|
||||
#region Internal Enums
|
||||
|
||||
enum InputState {
|
||||
RequestLine,
|
||||
Headers
|
||||
}
|
||||
|
||||
enum LineState {
|
||||
None,
|
||||
CR,
|
||||
LF
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Const Fields
|
||||
|
||||
private const int _bufferSize = 8192;
|
||||
@ -107,14 +92,14 @@ namespace WebSocketSharp.Net
|
||||
_secure = listener.IsSecure;
|
||||
|
||||
var netStream = new NetworkStream (socket, false);
|
||||
if (!_secure) {
|
||||
_stream = netStream;
|
||||
}
|
||||
else {
|
||||
if (_secure) {
|
||||
var sslStream = new SslStream (netStream, false);
|
||||
sslStream.AuthenticateAsServer (listener.Certificate);
|
||||
_stream = sslStream;
|
||||
}
|
||||
else {
|
||||
_stream = netStream;
|
||||
}
|
||||
|
||||
_timeout = 90000; // 90k ms for first request, 15k ms from then on.
|
||||
_timer = new Timer (onTimeout, this, Timeout.Infinite, Timeout.Infinite);
|
||||
@ -216,7 +201,7 @@ namespace WebSocketSharp.Net
|
||||
read = conn._stream.EndRead (asyncResult);
|
||||
conn._requestBuffer.Write (conn._buffer, 0, read);
|
||||
if (conn._requestBuffer.Length > 32768) {
|
||||
conn.SendError ();
|
||||
conn.SendError ("Bad request", 400);
|
||||
conn.Close (true);
|
||||
|
||||
return;
|
||||
@ -253,7 +238,7 @@ namespace WebSocketSharp.Net
|
||||
}
|
||||
|
||||
if (!conn._epListener.BindContext (conn._context)) {
|
||||
conn.SendError ("Invalid host.", 400);
|
||||
conn.SendError ("Invalid host", 400);
|
||||
conn.Close (true);
|
||||
|
||||
return;
|
||||
|
49
websocket-sharp/Net/InputState.cs
Normal file
49
websocket-sharp/Net/InputState.cs
Normal file
@ -0,0 +1,49 @@
|
||||
#region License
|
||||
/*
|
||||
* InputState.cs
|
||||
*
|
||||
* This code is derived from System.Net.HttpConnection.cs of Mono
|
||||
* (http://www.mono-project.com).
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
|
||||
* Copyright (c) 2014 sta.blockhead
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
#region Authors
|
||||
/*
|
||||
* Authors:
|
||||
* - Gonzalo Paniagua Javier <gonzalo@novell.com>
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace WebSocketSharp.Net
|
||||
{
|
||||
internal enum InputState
|
||||
{
|
||||
RequestLine,
|
||||
Headers
|
||||
}
|
||||
}
|
50
websocket-sharp/Net/LineState.cs
Normal file
50
websocket-sharp/Net/LineState.cs
Normal file
@ -0,0 +1,50 @@
|
||||
#region License
|
||||
/*
|
||||
* LineState.cs
|
||||
*
|
||||
* This code is derived from System.Net.HttpConnection.cs of Mono
|
||||
* (http://www.mono-project.com).
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
|
||||
* Copyright (c) 2014 sta.blockhead
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
#region Authors
|
||||
/*
|
||||
* Authors:
|
||||
* - Gonzalo Paniagua Javier <gonzalo@novell.com>
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace WebSocketSharp.Net
|
||||
{
|
||||
internal enum LineState
|
||||
{
|
||||
None,
|
||||
CR,
|
||||
LF
|
||||
}
|
||||
}
|
@ -129,6 +129,8 @@
|
||||
<Compile Include="Net\HttpDigestIdentity.cs" />
|
||||
<Compile Include="Net\NetworkCredential.cs" />
|
||||
<Compile Include="Server\WebSocketServiceManager.cs" />
|
||||
<Compile Include="Net\InputState.cs" />
|
||||
<Compile Include="Net\LineState.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user