@@ -792,7 +792,8 @@ pub const WebSocket = struct {
792
792
if (! payload_head .mask )
793
793
return error .MissingMaskBit ;
794
794
795
- // TODO: Remove check here for op_head.rsv1 once compression is readded.
795
+ // TODO: Remove check here for op_head.rsv1 if compression
796
+ // is added in the future
796
797
if (@bitCast (op_head .rsv1 ) or @bitCast (op_head .rsv2 ) or @bitCast (op_head .rsv3 ))
797
798
return error .UnnegociatedReservedBits ;
798
799
@@ -804,14 +805,15 @@ pub const WebSocket = struct {
804
805
805
806
const mask : u32 = @bitCast ((try in .takeArray (4 )).* );
806
807
const payload = blk : {
807
- if (total < in .buffered ().len )
808
- break :blk try in .take (total );
808
+ if (total > in .buffer .len ) {
809
+ try ws .storage .ensureUnusedCapacity (total );
810
+ try in .streamExact (& ws .storage .writer , total );
811
+ defer ws .storage .shrinkRetainingCapacity (0 );
809
812
810
- try ws .storage .ensureUnusedCapacity (total );
811
- try in .streamExact (& ws .storage .writer , total );
812
- defer ws .storage .shrinkRetainingCapacity (0 );
813
+ break :blk ws .storage .written ();
814
+ }
813
815
814
- break :blk ws . storage . written ( );
816
+ break :blk try in . take ( total );
815
817
};
816
818
817
819
// The last item may contain a partial word of unused data.
@@ -827,9 +829,6 @@ pub const WebSocket = struct {
827
829
.binary ,
828
830
= > {
829
831
if (! op_head .fin ) {
830
- if (ws .fragment .message_type != null )
831
- return error .UnexpectedFragment ;
832
-
833
832
try ws .fragment .writeAll (payload );
834
833
ws .fragment .message_type = op_head .opcode ;
835
834
@@ -852,9 +851,6 @@ pub const WebSocket = struct {
852
851
const message_type = ws .fragment .message_type orelse return error .FragmentedControl ;
853
852
854
853
if (! op_head .fin ) {
855
- if (ws .fragment .message_type == null )
856
- return error .UnexpectedFragment ;
857
-
858
854
try ws .fragment .writeAll (payload );
859
855
continue ;
860
856
}
0 commit comments