@@ -18,9 +18,9 @@ public abstract class Draft {
1818
1919 public enum HandshakeState {
2020 /** Handshake matched this Draft successfully */
21- MATCHED ,
21+ MATCHED ,
2222 /** Handshake is does not match this Draft */
23- NOT_MATCHED ,
23+ NOT_MATCHED ,
2424 /** Handshake matches this Draft but is not complete */
2525 MATCHING
2626 }
@@ -29,7 +29,7 @@ public enum HandshakeState {
2929
3030 /** In some cases the handshake will be parsed different depending on whether */
3131 protected Role role = null ;
32-
32+
3333 public static ByteBuffer readLine ( ByteBuffer buf ) {
3434 ByteBuffer sbuf = ByteBuffer .allocate ( buf .remaining () );
3535 byte prev = '0' ;
@@ -45,7 +45,7 @@ public static ByteBuffer readLine( ByteBuffer buf ) {
4545
4646 }
4747 }
48- //ensure that there wont be any bytes skipped
48+ // ensure that there wont be any bytes skipped
4949 buf .position ( buf .position () - sbuf .position () );
5050 return null ;
5151 }
@@ -55,18 +55,28 @@ public static String readStringLine( ByteBuffer buf ) {
5555 return b == null ? null : Charsetfunctions .stringAscii ( b .array (), 0 , b .limit () );
5656 }
5757
58- public static HandshakeBuilder translateHandshakeHttp ( ByteBuffer buf ) throws InvalidHandshakeException {
58+ public static HandshakeBuilder translateHandshakeHttp ( ByteBuffer buf , Role role ) throws InvalidHandshakeException {
5959 HandshakedataImpl1 draft = new HandshakedataImpl1 ();
6060
6161 String line = readStringLine ( buf );
6262 if ( line == null )
6363 throw new InvalidHandshakeException ( "could not match http status line" );
6464
6565 String [] firstLineTokens = line .split ( " " );// eg. GET / HTTP/1.1
66- if ( firstLineTokens .length < 3 ) {
66+
67+ if ( role == Role .CLIENT && firstLineTokens .length == 4 ) {
68+ // translating/parsing the response from the SERVER
69+ draft .setHttpVersion ( firstLineTokens [ 0 ] );
70+ draft .setHttpStatus ( Short .parseShort ( firstLineTokens [ 1 ] ) );
71+ draft .setHttpStatusMessage ( firstLineTokens [ 2 ] + ' ' + firstLineTokens [ 3 ] );
72+ } else if ( role == Role .SERVER && firstLineTokens .length == 3 ) {
73+ // translating/parsing the request from the CLIENT
74+ draft .setMethod ( firstLineTokens [ 0 ] );
75+ draft .setResourceDescriptor ( firstLineTokens [ 1 ] );
76+ draft .setHttpVersion ( firstLineTokens [ 2 ] );
77+ } else {
6778 throw new InvalidHandshakeException ( "could not match http status line" );
6879 }
69- draft .setResourceDescriptor ( firstLineTokens [ 1 ] );
7080
7181 line = readStringLine ( buf );
7282 while ( line != null && line .length () > 0 ) {
@@ -139,19 +149,19 @@ public List<ByteBuffer> createHandshake( Handshakedata handshakedata, Role ownro
139149 public abstract List <Framedata > translateFrame ( ByteBuffer buffer ) throws InvalidDataException ;
140150
141151 public Handshakedata translateHandshake ( ByteBuffer buf ) throws InvalidHandshakeException {
142- return translateHandshakeHttp ( buf );
152+ return translateHandshakeHttp ( buf , role );
143153 }
144154
145155 public int checkAlloc ( int bytecount ) throws LimitExedeedException , InvalidDataException {
146156 if ( bytecount < 0 )
147157 throw new InvalidDataException ( CloseFrame .PROTOCOL_ERROR , "Negative count" );
148158 return bytecount ;
149159 }
150-
151- public void setParseMode ( Role role ){
160+
161+ public void setParseMode ( Role role ) {
152162 this .role = role ;
153163 }
154164
155165 public abstract boolean hasCloseHandshake ();
156166
157- }
167+ }
0 commit comments