From 2e66e54425eaa08d9ae1f5e02ca0c9de8e14b20b Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 24 Feb 2012 11:26:50 +0100 Subject: [PATCH] 370387 - SafariWebsocketDraft0Test failure during build. The reason for the failure of this test was that a BufferedReader was used to read the header lines. However, the buffered reader may have read and buffered also the hixie bytes and subsequently, when the test was trying to read the hixie bytes directly from the input stream (and not from the buffered reader), the read was timing out. Fixed by always using the input stream to read the header and hixie bytes. --- .../jetty/websocket/helper/SafariD00.java | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/helper/SafariD00.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/helper/SafariD00.java index 3b5d8fd0b82..69f18c26cf3 100644 --- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/helper/SafariD00.java +++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/helper/SafariD00.java @@ -15,9 +15,6 @@ *******************************************************************************/ package org.eclipse.jetty.websocket.helper; -import static org.hamcrest.Matchers.*; - -import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -35,6 +32,8 @@ import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.StdErrLog; import org.junit.Assert; +import static org.hamcrest.Matchers.is; + public class SafariD00 { private static final Logger LOG = Log.getLogger(SafariD00.class); @@ -56,7 +55,7 @@ public class SafariD00 /** * Open the Socket to the destination endpoint and - * + * * @return the open java Socket. * @throws IOException */ @@ -75,7 +74,7 @@ public class SafariD00 /** * Issue an Http websocket (Draft-0) upgrade request (using an example request captured from OSX/Safari) - * + * * @throws UnsupportedEncodingException */ public void issueHandshake() throws IOException @@ -103,23 +102,22 @@ public class SafariD00 out.write(buf,0,buf.length); out.flush(); - // Read HTTP 101 Upgrade / Handshake Response - InputStreamReader reader = new InputStreamReader(in); - BufferedReader br = new BufferedReader(reader); - socket.setSoTimeout(10000); - LOG.debug("Reading http header"); - boolean foundEnd = false; - String line; - while (!foundEnd) + // Read HTTP 101 Upgrade / Handshake Response + InputStreamReader reader = new InputStreamReader(in); + + LOG.debug("Reading http headers"); + int crlfs = 0; + while (true) { - line = br.readLine(); - // System.out.printf("RESP: %s%n",line); - if (line.length() == 0) - { - foundEnd = true; - } + int read = in.read(); + if (read == '\r' || read == '\n') + ++crlfs; + else + crlfs = 0; + if (crlfs == 4) + break; } // Read expected handshake hixie bytes