@@ -112,12 +112,22 @@ public void parseHandshake() {
112112 if (this .handshakeType == ClientServerType .SERVER ) {
113113 int sp1 = line .indexOf (" " );
114114 int sp2 = line .indexOf (" " ,sp1 +1 );
115- String httpVersion = line .substring (0 ,sp1 );
115+ String httpVersion = line .substring (0 ,sp1 );
116116 String statusCode = line .substring (sp1 +1 ,sp2 );
117117 String reasonPhrase = line .substring (sp2 +1 ,line .length ());
118- put ("http-version" , httpVersion );
119- put ("status-code" , statusCode );
120- put ("reason-phrase" , reasonPhrase );
118+ String httpVersionKey = "HTTP-Version" ;
119+ String statusCodeKey = "Status-Code" ;
120+ String reasonPhraseKey = "Reason-Phrase" ;
121+
122+ if (this .handshakeDraft == Draft .DRAFT76 ) {
123+ httpVersionKey = httpVersionKey .toLowerCase ();
124+ statusCodeKey = statusCodeKey .toLowerCase ();
125+ reasonPhraseKey = reasonPhraseKey .toLowerCase ();
126+ }
127+
128+ put (httpVersionKey , httpVersion );
129+ put (statusCodeKey , statusCode );
130+ put (reasonPhraseKey , reasonPhrase );
121131 }
122132
123133 if (this .handshakeType == ClientServerType .CLIENT ) {
@@ -126,9 +136,20 @@ public void parseHandshake() {
126136 String method = line .substring (0 ,sp1 );
127137 String requestURI = line .substring (sp1 +1 ,sp2 );
128138 String httpVersion = line .substring (sp2 +1 ,line .length ());
129- put ("method" , method );
130- put ("request-uri" , requestURI );
131- put ("http-version" , httpVersion );
139+ String methodKey = "Method" ;
140+ String requestURIKey = "Request-URI" ;
141+ String httpVersionKey = "HTTP-Version" ;
142+
143+
144+ if (this .handshakeDraft == Draft .DRAFT76 ) {
145+ methodKey = methodKey .toLowerCase ();
146+ requestURIKey = httpVersionKey .toLowerCase ();
147+ httpVersionKey = httpVersionKey .toLowerCase ();
148+ }
149+
150+ put (methodKey , method );
151+ put (requestURIKey , requestURI );
152+ put (httpVersionKey , httpVersion );
132153 }
133154
134155 // parse fields
@@ -206,10 +227,10 @@ public void buildHandshake() {
206227 "Connection: Upgrade\r \n " ;
207228
208229 if (this .handshakeDraft == Draft .DRAFT75 ) {
209- responseHandshake += "WebSocket-Origin: " + getProperty ("origin " ) + "\r \n " +
210- "WebSocket-Location: ws://" + getProperty ("host " ) + getProperty ("request-uri " ) + "\r \n " ;
230+ responseHandshake += "WebSocket-Origin: " + getProperty ("Origin " ) + "\r \n " +
231+ "WebSocket-Location: ws://" + getProperty ("Host " ) + getProperty ("Request-URI " ) + "\r \n " ;
211232 if (containsKey ("WebSocket-Protocol" )) {
212- responseHandshake += "WebSocket-Protocol: " + getProperty ("websocket-protocol " ) + "\r \n " ;
233+ responseHandshake += "WebSocket-Protocol: " + getProperty ("Websocket-Protocol " ) + "\r \n " ;
213234 }
214235 }
215236
@@ -243,14 +264,18 @@ public void buildHandshake() {
243264
244265 if (this .handshakeType == ClientServerType .CLIENT ) {
245266
246- String requestHandshake = "GET " + getProperty ("request-uri" ) + " HTTP/1.1\r \n " +
267+ String requestURI = (getDraft () == Draft .DRAFT75 ) ? getProperty ("Request-URI" ) : getProperty ("request-uri" );
268+ String host = (getDraft () == Draft .DRAFT75 ) ? getProperty ("Host" ) : getProperty ("host" );
269+ String origin = (getDraft () == Draft .DRAFT75 ) ? getProperty ("Origin" ) : getProperty ("origin" );
270+
271+ String requestHandshake = "GET " + requestURI + " HTTP/1.1\r \n " +
247272 "Upgrade: WebSocket\r \n " +
248273 "Connection: Upgrade\r \n " +
249- "Host: " + getProperty ( " host" ) + "\r \n " +
250- "Origin: " + getProperty ( " origin" ) + "\r \n " ;
274+ "Host: " + host + "\r \n " +
275+ "Origin: " + origin + "\r \n " ;
251276
252- if (getDraft () == Draft .DRAFT75 && containsKey ("websocket-protocol " )) {
253- requestHandshake += "WebSocket-Protocol: " + getProperty ("websocket-protocol " ) + "\r \n " ;
277+ if (getDraft () == Draft .DRAFT75 && containsKey ("Websocket-Protocol " )) {
278+ requestHandshake += "WebSocket-Protocol: " + getProperty ("Websocket-Protocol " ) + "\r \n " ;
254279 }
255280
256281 if (getDraft () == Draft .DRAFT76 ) {
0 commit comments