'use strict';

/* lib/handshake.js
 * WebSocket handshake.
 * * */

module.exports = exports = function(){

};

exports._headers = function(raw){
  if (raw instanceof Buffer) raw = raw.toString('utf-8');
  let chunks = raw.split(/\r?\n/),
      headers = { 0:chunks[0] }, chunk = null,
      toObj = /^(.+?):\s?/;

  for (let i = 1; i < chunks.length; i++) {
    chunk = chunks[i].split(toObj);
    headers[chunk[1].toLowerCase()] = chunk[2];
  }

  return headers;
};

@@ -8,16 +8,51 @@
 rict';%0A%0A
+const crypto = require('crypto');%0A%0A
 /* lib/h
@@ -132,19 +132,200 @@
 unction(
-)%7B%0A
+data)%7B%0A  if (this.state === 'start') %7B%0A    let headers = exports._headers(data);%0A    console.log(headers%5B'sec-websocket-key'%5D);%0A  %7D else if (this.state === 'handshake:response') %7B%0A%0A  %7D
 %0A%7D;%0A%0Aexp
@@ -559,16 +559,20 @@
 s.length
+ - 1
 ; i++) %7B
@@ -611,16 +611,42 @@
 bj);%0A   
+ if (chunk%5B1%5D && chunk%5B2%5D)
  headers

Fix header parsing and add test