SUGGESTED FIX
diff -r 8d88e694441c test/java/net/URLConnection/RedirectLimit.java
--- a/test/java/net/URLConnection/RedirectLimit.java
+++ b/test/java/net/URLConnection/RedirectLimit.java
@@ -62,24 +62,37 @@ class RedirLimitServer extends Thread {
port = ss.getLocalPort();
}
+ static final byte[] requestEnd = new byte[] {'\r', '\n', '\r', '\n' };
+
+ void readCompleteRequest(InputStream is) throws IOException {
+ int requestEndCount = 0, r;
+ while ((r = is.read()) != -1) {
+ if (r == requestEnd[requestEndCount]) {
+ requestEndCount++;
+ if (requestEndCount == 4) {
+ break;
+ }
+ } else {
+ requestEndCount = 0;
+ }
+ }
+ }
+
public void run() {
try {
ss.setSoTimeout(TIMEOUT);
for (int i=0; i<NUM_REDIRECTS; i++) {
try (Socket s = ss.accept()) {
s.setSoTimeout(TIMEOUT);
- InputStream is = s.getInputStream();
- OutputStream os = s.getOutputStream();
- is.read();
+ readCompleteRequest(s.getInputStream());
String reply = reply1 + port + "/redirect" + i + reply2;
- os.write(reply.getBytes());
+ s.getOutputStream().write(reply.getBytes());
}
}
try (Socket s = ss.accept()) {
- InputStream is = s.getInputStream();
- OutputStream os = s.getOutputStream();
- is.read();
- os.write(reply3.getBytes());
+ s.setSoTimeout(TIMEOUT);
+ readCompleteRequest(s.getInputStream());
+ s.getOutputStream().write(reply3.getBytes());
}
} catch (Exception e) {
e.printStackTrace();
Similar changes for Redirect307Test.java
|