34 |
34 |
35 import jdk.test.lib.net.URIBuilder; |
35 import jdk.test.lib.net.URIBuilder; |
36 |
36 |
37 public class SetIfModifiedSince { |
37 public class SetIfModifiedSince { |
38 static volatile boolean successfulHeaderCheck = false; |
38 static volatile boolean successfulHeaderCheck = false; |
|
39 static final String MARKER = "A-test-name"; |
39 |
40 |
40 static class XServer extends Thread { |
41 static class XServer extends Thread { |
41 ServerSocket srv; |
42 ServerSocket srv; |
42 Socket s; |
43 Socket s; |
43 InputStream is; |
44 InputStream is; |
50 Socket getSocket () { |
51 Socket getSocket () { |
51 return (s); |
52 return (s); |
52 } |
53 } |
53 |
54 |
54 public void run() { |
55 public void run() { |
55 try { |
56 boolean foundMarker = false; |
|
57 while (!foundMarker) { |
56 String x; |
58 String x; |
57 s = srv.accept (); |
59 try { |
58 is = s.getInputStream (); |
60 s = srv.accept(); |
59 BufferedReader r = new BufferedReader(new InputStreamReader(is)); |
61 System.out.println("Server: accepting connection from: " + s); |
60 os = s.getOutputStream (); |
62 is = s.getInputStream (); |
61 while ((x=r.readLine()) != null) { |
63 } catch (IOException io) { |
62 String header = "If-Modified-Since: "; |
64 System.err.println("Server: Failed to accept connection: " + io); |
63 if (x.startsWith(header)) { |
65 io.printStackTrace(); |
64 if (x.charAt(header.length()) == '?') { |
66 try { srv.close(); } catch (IOException ioc) { } |
65 s.close (); |
67 break; |
66 srv.close (); // or else the HTTPURLConnection will retry |
68 } |
67 throw new RuntimeException |
69 try { |
68 ("Invalid HTTP date specification"); |
70 BufferedReader r = new BufferedReader(new InputStreamReader(is)); |
|
71 os = s.getOutputStream (); |
|
72 boolean foundHeader; |
|
73 while ((x=r.readLine()) != null) { |
|
74 String testname = MARKER + ": "; |
|
75 String header = "If-Modified-Since: "; |
|
76 if (x.startsWith(header)) { |
|
77 foundHeader = true; |
|
78 System.out.println("Server: found header: " + x); |
|
79 if (x.charAt(header.length()) == '?') { |
|
80 s.close (); |
|
81 srv.close (); // or else the HTTPURLConnection will retry |
|
82 throw new RuntimeException |
|
83 ("Invalid HTTP date specification"); |
|
84 } |
|
85 if (foundMarker) break; |
|
86 } else if (x.startsWith(testname)) { |
|
87 foundMarker = true; |
|
88 System.out.println("Server: found marker: " + x); |
69 } |
89 } |
70 break; |
|
71 } |
90 } |
72 } |
91 successfulHeaderCheck = true; |
73 successfulHeaderCheck = true; |
92 s.close (); |
74 s.close (); |
93 // only close server if connected from this test. |
75 srv.close (); // or else the HTTPURLConnection will retry |
94 if (foundMarker) { |
76 } catch (IOException e) {} |
95 srv.close (); // or else the HTTPURLConnection will retry |
|
96 } |
|
97 } catch (IOException e) {} |
|
98 } |
77 } |
99 } |
78 } |
100 } |
79 |
101 |
80 public static void main(String[] args) throws Exception { |
102 public static void main(String[] args) throws Exception { |
81 Locale reservedLocale = Locale.getDefault(); |
103 Locale reservedLocale = Locale.getDefault(); |
92 .loopback() |
114 .loopback() |
93 .port(port) |
115 .port(port) |
94 .path("/index.html") |
116 .path("/index.html") |
95 .toURLUnchecked(); |
117 .toURLUnchecked(); |
96 URLConnection urlc = url.openConnection(Proxy.NO_PROXY); |
118 URLConnection urlc = url.openConnection(Proxy.NO_PROXY); |
|
119 urlc.setRequestProperty(MARKER, "SetIfModifiedSince"); |
97 urlc.setIfModifiedSince (10000000); |
120 urlc.setIfModifiedSince (10000000); |
98 InputStream is = urlc.getInputStream (); |
121 InputStream is = urlc.getInputStream (); |
99 int i = 0, c; |
122 int i = 0, c; |
100 Thread.sleep(5000); |
123 Thread.sleep(5000); |
101 if (!successfulHeaderCheck) { |
124 if (!successfulHeaderCheck) { |