Removed the features for the per frame compression
This commit is contained in:
@@ -54,9 +54,9 @@ namespace WebSocketSharp {
|
||||
internal CloseEventArgs(PayloadData data)
|
||||
: base(Opcode.CLOSE, data)
|
||||
{
|
||||
_code = getCodeFrom(data);
|
||||
_code = getCodeFrom(data);
|
||||
_reason = getReasonFrom(data);
|
||||
_clean = false;
|
||||
_clean = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -107,19 +107,22 @@ namespace WebSocketSharp {
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private ushort getCodeFrom(PayloadData data)
|
||||
private static ushort getCodeFrom(PayloadData data)
|
||||
{
|
||||
return data.Length >= 2
|
||||
? data.ToByteArray().SubArray(0, 2).To<ushort>(ByteOrder.BIG)
|
||||
var appData = data.ApplicationData;
|
||||
return appData.Length >= 2
|
||||
? appData.SubArray(0, 2).To<ushort>(ByteOrder.BIG)
|
||||
: (ushort)CloseStatusCode.NO_STATUS_CODE;
|
||||
}
|
||||
|
||||
private string getReasonFrom(PayloadData data)
|
||||
private static string getReasonFrom(PayloadData data)
|
||||
{
|
||||
if (data.Length <= 2)
|
||||
var appData = data.ApplicationData;
|
||||
var appDataLen = appData.Length;
|
||||
if (appDataLen <= 2)
|
||||
return String.Empty;
|
||||
|
||||
var buffer = data.ToByteArray().SubArray(2, (int)(data.Length - 2));
|
||||
var buffer = appData.SubArray(2, appDataLen - 2);
|
||||
return Encoding.UTF8.GetString(buffer);
|
||||
}
|
||||
|
||||
|
@@ -50,6 +50,11 @@ namespace WebSocketSharp {
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal MessageEventArgs(Opcode type, byte[] data)
|
||||
: this(type, new PayloadData(data))
|
||||
{
|
||||
}
|
||||
|
||||
internal MessageEventArgs(Opcode type, PayloadData data)
|
||||
{
|
||||
_type = type;
|
||||
|
@@ -30,7 +30,6 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@@ -138,43 +137,6 @@ namespace WebSocketSharp {
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
internal bool Compress(CompressionMethod method)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (method == CompressionMethod.NONE)
|
||||
return false;
|
||||
|
||||
if (ExtensionData.LongLength > 0)
|
||||
return false;
|
||||
|
||||
ApplicationData = ApplicationData.Compress(method);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool Decompress(CompressionMethod method)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (method == CompressionMethod.NONE)
|
||||
return false;
|
||||
|
||||
if (ApplicationData.LongLength > 0)
|
||||
ApplicationData = ApplicationData.Decompress(method);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
@@ -76,7 +76,6 @@ namespace WebSocketSharp {
|
||||
private Object _forClose;
|
||||
private Object _forSend;
|
||||
private string _origin;
|
||||
private bool _perFrameCompress;
|
||||
private string _protocol;
|
||||
private string _protocols;
|
||||
private volatile WsState _readyState;
|
||||
@@ -98,7 +97,6 @@ namespace WebSocketSharp {
|
||||
_forClose = new Object();
|
||||
_forSend = new Object();
|
||||
_origin = String.Empty;
|
||||
_perFrameCompress = false;
|
||||
_protocol = String.Empty;
|
||||
_readyState = WsState.CONNECTING;
|
||||
}
|
||||
@@ -576,18 +574,14 @@ namespace WebSocketSharp {
|
||||
|
||||
private static WsFrame createControlFrame(Opcode opcode, PayloadData payloadData, bool client)
|
||||
{
|
||||
var mask = client ? Mask.MASK : Mask.UNMASK;
|
||||
return new WsFrame(opcode, mask, payloadData);
|
||||
return createFrame(Fin.FINAL, opcode, payloadData, false, client);
|
||||
}
|
||||
|
||||
private static WsFrame createDataFrame(
|
||||
Fin fin, Opcode opcode, PayloadData payloadData, CompressionMethod method, bool compressed, bool client)
|
||||
private static WsFrame createFrame(
|
||||
Fin fin, Opcode opcode, PayloadData payloadData, bool compressed, bool client)
|
||||
{
|
||||
var mask = client ? Mask.MASK : Mask.UNMASK;
|
||||
var compress = compressed ? CompressionMethod.NONE : method;
|
||||
var frame = new WsFrame(fin, opcode, mask, payloadData, compress);
|
||||
if (compressed)
|
||||
frame.PerMessageCompressed = true;
|
||||
var frame = new WsFrame(fin, opcode, mask, payloadData, compressed);
|
||||
|
||||
return frame;
|
||||
}
|
||||
@@ -716,18 +710,6 @@ namespace WebSocketSharp {
|
||||
return true;
|
||||
}
|
||||
|
||||
// As server
|
||||
private static bool isPerFrameCompressExtension(string value)
|
||||
{
|
||||
if (value.Equals("deflate-frame"))
|
||||
return true;
|
||||
|
||||
if (value.Equals("perframe-compress; method=deflate"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// As server
|
||||
private bool isValidHostHeader()
|
||||
{
|
||||
@@ -776,10 +758,7 @@ namespace WebSocketSharp {
|
||||
if (!contFrame.IsContinuation)
|
||||
return false;
|
||||
|
||||
if (contFrame.IsCompressed)
|
||||
contFrame.Decompress(_compression);
|
||||
|
||||
dest.WriteBytes(contFrame.PayloadData.ToByteArray());
|
||||
dest.WriteBytes(contFrame.PayloadData.ApplicationData);
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -921,10 +900,11 @@ namespace WebSocketSharp {
|
||||
if (frame.IsCompressed && _compression == CompressionMethod.NONE)
|
||||
return false;
|
||||
|
||||
if (frame.IsCompressed)
|
||||
frame.Decompress(_compression);
|
||||
var data = frame.IsCompressed
|
||||
? new PayloadData(frame.PayloadData.ApplicationData.Decompress(_compression))
|
||||
: frame.PayloadData;
|
||||
|
||||
onMessage(new MessageEventArgs(frame.Opcode, frame.PayloadData));
|
||||
onMessage(new MessageEventArgs(frame.Opcode, data));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -938,8 +918,10 @@ namespace WebSocketSharp {
|
||||
if (frame.IsFinal)
|
||||
return false;
|
||||
|
||||
// First fragment
|
||||
if (frame.IsData && !(frame.IsCompressed && _compression == CompressionMethod.NONE))
|
||||
bool incorrect = !frame.IsData ||
|
||||
frame.IsCompressed && _compression == CompressionMethod.NONE;
|
||||
|
||||
if (!incorrect)
|
||||
processFragments(frame);
|
||||
else
|
||||
processIncorrectFrame();
|
||||
@@ -951,15 +933,12 @@ namespace WebSocketSharp {
|
||||
{
|
||||
using (var merge = new MemoryStream())
|
||||
{
|
||||
if (first.IsCompressed && _perFrameCompress)
|
||||
first.Decompress(_compression);
|
||||
|
||||
merge.WriteBytes(first.PayloadData.ToByteArray());
|
||||
merge.WriteBytes(first.PayloadData.ApplicationData);
|
||||
if (!mergeFragments(merge))
|
||||
return;
|
||||
|
||||
byte[] data;
|
||||
if (_compression != CompressionMethod.NONE && !_perFrameCompress)
|
||||
if (_compression != CompressionMethod.NONE)
|
||||
{
|
||||
data = merge.DecompressToArray(_compression);
|
||||
}
|
||||
@@ -969,7 +948,7 @@ namespace WebSocketSharp {
|
||||
data = merge.ToArray();
|
||||
}
|
||||
|
||||
onMessage(new MessageEventArgs(first.Opcode, new PayloadData(data)));
|
||||
onMessage(new MessageEventArgs(first.Opcode, data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1032,26 +1011,11 @@ namespace WebSocketSharp {
|
||||
{
|
||||
var e = extension.Trim();
|
||||
var tmp = e.RemovePrefix("x-webkit-");
|
||||
if (!compress)
|
||||
if (!compress && isCompressExtension(tmp, CompressionMethod.DEFLATE))
|
||||
{
|
||||
if (isPerFrameCompressExtension(tmp))
|
||||
{
|
||||
_perFrameCompress = true;
|
||||
_compression = CompressionMethod.DEFLATE;
|
||||
compress = true;
|
||||
}
|
||||
|
||||
if (!compress && isCompressExtension(tmp, CompressionMethod.DEFLATE))
|
||||
{
|
||||
_compression = CompressionMethod.DEFLATE;
|
||||
compress = true;
|
||||
}
|
||||
|
||||
if (compress)
|
||||
{
|
||||
buffer.Add(e);
|
||||
continue;
|
||||
}
|
||||
_compression = CompressionMethod.DEFLATE;
|
||||
compress = true;
|
||||
buffer.Add(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1216,7 +1180,7 @@ namespace WebSocketSharp {
|
||||
|
||||
private void send(Opcode opcode, Stream stream)
|
||||
{
|
||||
if (_compression == CompressionMethod.NONE || _perFrameCompress)
|
||||
if (_compression == CompressionMethod.NONE)
|
||||
{
|
||||
send(opcode, stream, false);
|
||||
return;
|
||||
@@ -1255,8 +1219,7 @@ namespace WebSocketSharp {
|
||||
|
||||
private bool send(Fin fin, Opcode opcode, byte[] data, bool compressed)
|
||||
{
|
||||
var frame = createDataFrame(
|
||||
fin, opcode, new PayloadData(data), _compression, compressed, _client);
|
||||
var frame = createFrame(fin, opcode, new PayloadData(data), compressed, _client);
|
||||
return send(frame);
|
||||
}
|
||||
|
||||
|
@@ -63,12 +63,12 @@ namespace WebSocketSharp {
|
||||
}
|
||||
|
||||
public WsFrame(Fin fin, Opcode opcode, Mask mask, PayloadData payloadData)
|
||||
: this(fin, opcode, mask, payloadData, CompressionMethod.NONE)
|
||||
: this(fin, opcode, mask, payloadData, false)
|
||||
{
|
||||
}
|
||||
|
||||
public WsFrame(
|
||||
Fin fin, Opcode opcode, Mask mask, PayloadData payloadData, CompressionMethod compress)
|
||||
Fin fin, Opcode opcode, Mask mask, PayloadData payloadData, bool compressed)
|
||||
{
|
||||
if (payloadData.IsNull())
|
||||
throw new ArgumentNullException("payloadData");
|
||||
@@ -80,18 +80,14 @@ namespace WebSocketSharp {
|
||||
if (!isFinal(fin) && isControl(opcode))
|
||||
throw new ArgumentException("The control frame must not be fragmented.");
|
||||
|
||||
if (isControl(opcode) && compress != CompressionMethod.NONE)
|
||||
if (isControl(opcode) && compressed)
|
||||
throw new ArgumentException("The control frame must not be compressed.");
|
||||
|
||||
Fin = fin;
|
||||
Rsv1 = Rsv.OFF;
|
||||
Rsv2 = Rsv.OFF;
|
||||
Rsv3 = Rsv.OFF;
|
||||
Rsv1 = isData(opcode) && compressed ? Rsv.ON : Rsv.OFF;
|
||||
Opcode = opcode;
|
||||
Mask = mask;
|
||||
PayloadData = payloadData;
|
||||
if (compress != CompressionMethod.NONE)
|
||||
compressPayloadData(compress);
|
||||
|
||||
init();
|
||||
}
|
||||
@@ -219,26 +215,6 @@ namespace WebSocketSharp {
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private bool compressPayloadData(CompressionMethod method)
|
||||
{
|
||||
if (!PayloadData.Compress(method))
|
||||
return false;
|
||||
|
||||
if (IsData)
|
||||
Rsv1 = Rsv.ON;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool decompressPayloadData(CompressionMethod method)
|
||||
{
|
||||
if (!PayloadData.Decompress(method))
|
||||
return false;
|
||||
|
||||
Rsv1 = Rsv.OFF;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void dump(WsFrame frame)
|
||||
{
|
||||
var len = frame.Length;
|
||||
@@ -311,6 +287,8 @@ namespace WebSocketSharp {
|
||||
|
||||
private void init()
|
||||
{
|
||||
Rsv2 = Rsv.OFF;
|
||||
Rsv3 = Rsv.OFF;
|
||||
setPayloadLen(PayloadData.Length);
|
||||
if (IsMasked)
|
||||
maskPayloadData();
|
||||
@@ -560,19 +538,6 @@ namespace WebSocketSharp {
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
internal void Decompress(CompressionMethod method)
|
||||
{
|
||||
if (Mask == Mask.MASK)
|
||||
unmaskPayloadData();
|
||||
|
||||
if (decompressPayloadData(method))
|
||||
setPayloadLen(PayloadData.Length);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public IEnumerator<byte> GetEnumerator()
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
<Overview>
|
||||
<Assemblies>
|
||||
<Assembly Name="websocket-sharp" Version="1.0.2.4444">
|
||||
<Assembly Name="websocket-sharp" Version="1.0.2.30839">
|
||||
<AssemblyPublicKey>[00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 11 00 00 00 29 17 fb 89 fe c3 91 f7 2b cb 8b e2 61 d2 3f 05 93 6d 65 a8 9e 63 72 a6 f5 d5 2c f2 9d 20 fa 0b c0 70 6a f6 88 7e 8b 90 3f 39 f5 76 c8 48 e0 bb 7b b2 7b ed d3 10 a7 1a 0f 70 98 0f 7f f4 4b 53 09 d2 a5 ef 36 c3 56 b4 aa f0 91 72 63 25 07 89 e0 93 3e 3f 2e f2 b9 73 0e 12 15 5d 43 56 c3 f4 70 a5 89 fe f7 f6 ac 3e 77 c2 d8 d0 84 91 f4 0c d1 f3 8e dc c3 c3 b8 38 3d 0c bf 17 de 20 78 c1 ]</AssemblyPublicKey>
|
||||
<Attributes>
|
||||
<Attribute>
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user