title: Websocket handshake Sec-WebSocket-Accept header value is incorrect
body: <p>I'm writing a c++ websocket server, dev tools on chrome says sec-websocket-accept header value is incorrect. I've tested for days and it all seems fine. The client closes with readystate 3 without the websocket onopen being called although it shows as 101 in chrome dev tools.</p>
  <p>This is my code for calculating the keys</p>
  <pre><code>string magickey = &quot;258EAFA5-E914-47DA-95CA-C5AB0DC85B11&quot;;
  string key = msgkey.append(magickey);
  
  unsigned char* sha_str = SHA1(reinterpret_cast&lt;const unsigned char*&gt;(key.c_str()), key.length(), nullptr);
  string acceptkey = base64_encode(reinterpret_cast&lt;const unsigned char*&gt;(sha_str), strlen((char*)sha_str));
  
  string handshake_response = &quot;HTTP/1.1 101 Switching Protocols\r\n&quot;;
  handshake_response.append(&quot;Upgrade: websocket\r\n&quot;);
  handshake_response.append(&quot;Connection: Upgrade\r\n&quot;);
  handshake_response.append(&quot;Sec-WebSocket-Accept: &quot;+acceptkey+&quot;\r\n&quot;);
  handshake_response.append(&quot;\r\n&quot;);  
  </code></pre>
  <p>Chrome Response</p>
  <pre><code>HTTP/1.1 101 Switching Protocols  
  Upgrade: websocket  
  Connection: Upgrade  
  Sec-WebSocket-Accept: 5T5MvxP1iz40vLpi3kQs/ifDaCo=  
  </code></pre>
  <p>Chrome Request</p>
  <pre><code>GET ws://localhost:4897/echo HTTP/1.1  
  Host: localhost:4897  
  Connection: Upgrade  
  Pragma: no-cache  
  Cache-Control: no-cache  
  Upgrade: websocket  
  Origin: http://localhost  
  Sec-WebSocket-Version: 13  
  User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36  
  Accept-Encoding: gzip, deflate, sdch  
  Accept-Language: en-US,en;q=0.8  
  Sec-WebSocket-Key: LKF8lHGznbKGIgO1UzAOhg==  
  Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits  
  </code></pre>
  <p>It says &quot;Error during WebSocket handshake: Incorrect 'Sec-WebSocket-Accept' header value&quot;.</p>
  <p>Chrome also shows one additional frame received size 79 bytes opcode -1.</p>
  <p>Thanks Heaps!</p>