Commits

Dmitry Grebeniuk  committed 13d848e

websockets: removed masking for server-to-client messages

  • Participants
  • Parent commits bddad9e

Comments (0)

Files changed (1)

File src/amall_http.ml

       in
       let len = String.length body in
       let () = assert (fh.len = Int64.of_int len) in
-      let hdr_len = 6 +
+      let hdr_len = 2 +
         (if len <= 125
          then 0
          else if len < 0x10000
           ; msg.[9] := Char.chr ( len         land 0xFF)
           )
       in
-      let masking_key_str = fh.masking_key in
-      let () = String.blit masking_key_str 0 msg (hdr_len - 4) 4 in
-      let rec mask_body src_i dst_i =
-        if src_i = len
-        then ()
-        else
-          ( msg.[dst_i] := Char.chr
-             (     (Char.code body.[src_i])
-              lxor (Char.code (masking_key_str.[src_i land 0b11]))
-             )
-          ; mask_body (src_i + 1) (dst_i + 1)
-          )
-      in
-      let () = mask_body 0 hdr_len in
+      let () = String.blit body 0 msg hdr_len len in
       (* IO.write (in lwt and in direct io) is atomic *)
       IO.write sock.ch msg >>% fun () ->
       IO.flush sock.ch