@@ -53,18 +53,28 @@ public static String readStringLine( ByteBuffer buf ) {
5353 return b == null ? null : Charsetfunctions .stringAscii ( b .array (), 0 , b .limit () );
5454 }
5555
56- public static HandshakeBuilder translateHandshakeHttp ( ByteBuffer buf ) throws InvalidHandshakeException {
56+ public static HandshakeBuilder translateHandshakeHttp ( ByteBuffer buf , Role role ) throws InvalidHandshakeException {
5757 HandshakedataImpl1 draft = new HandshakedataImpl1 ();
5858
5959 String line = readStringLine ( buf );
6060 if ( line == null )
6161 throw new InvalidHandshakeException ( "could not match http status line" );
6262
6363 String [] firstLineTokens = line .split ( " " );// eg. GET / HTTP/1.1
64- if ( firstLineTokens .length < 3 ) {
64+
65+ if ( role == Role .CLIENT && firstLineTokens .length == 4 ) {
66+ // translating/parsing the response from the SERVER
67+ draft .setHttpVersion ( firstLineTokens [ 0 ] );
68+ draft .setHttpStatus ( Short .parseShort ( firstLineTokens [ 1 ] ) );
69+ draft .setHttpStatusMessage ( firstLineTokens [ 2 ] + ' ' + firstLineTokens [ 3 ] );
70+ } else if ( role == Role .SERVER && firstLineTokens .length == 3 ) {
71+ // translating/parsing the request from the CLIENT
72+ draft .setMethod ( firstLineTokens [ 0 ] );
73+ draft .setResourceDescriptor ( firstLineTokens [ 1 ] );
74+ draft .setHttpVersion ( firstLineTokens [ 2 ] );
75+ } else {
6576 throw new InvalidHandshakeException ( "could not match http status line" );
6677 }
67- draft .setResourceDescriptor ( firstLineTokens [ 1 ] );
6878
6979 line = readStringLine ( buf );
7080 while ( line != null && line .length () > 0 ) {
@@ -136,8 +146,8 @@ public List<ByteBuffer> createHandshake( Handshakedata handshakedata, Role ownro
136146
137147 public abstract List <Framedata > translateFrame ( ByteBuffer buffer ) throws InvalidDataException ;
138148
139- public Handshakedata translateHandshake ( ByteBuffer buf ) throws InvalidHandshakeException {
140- return translateHandshakeHttp ( buf );
149+ public Handshakedata translateHandshake ( ByteBuffer buf , Role role ) throws InvalidHandshakeException {
150+ return translateHandshakeHttp ( buf , role );
141151 }
142152
143153 public int checkAlloc ( int bytecount ) throws LimitExedeedException , InvalidDataException {
@@ -152,4 +162,4 @@ public void setParseMode( Role role ){
152162
153163 public abstract boolean hasCloseHandshake ();
154164
155- }
165+ }
0 commit comments