0N/A/*
2362N/A * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4092605
0N/A * @summary Test HttpURLConnection setIfModifiedSince
0N/A *
0N/A */
0N/A
0N/Aimport java.net.*;
0N/Aimport java.io.*;
0N/A
0N/Apublic class Modified implements Runnable {
0N/A
0N/A ServerSocket ss;
0N/A
0N/A public void run() {
0N/A try {
0N/A Socket s = ss.accept();
0N/A boolean gotIfModified = false;
0N/A
0N/A BufferedReader in = new BufferedReader(
0N/A new InputStreamReader(s.getInputStream()) );
0N/A
0N/A String str = null;
0N/A do {
0N/A str = in.readLine();
0N/A if (str.startsWith("If-Modified-Since")) {
0N/A gotIfModified = true;
0N/A }
0N/A if (str.equals("")) {
0N/A break;
0N/A }
0N/A } while (str != null);
0N/A
0N/A PrintStream out = new PrintStream(
0N/A new BufferedOutputStream(
0N/A s.getOutputStream() ));
0N/A
0N/A if (gotIfModified) {
0N/A out.print("HTTP/1.1 304 Not Modified\r\n");
0N/A } else {
0N/A out.print("HTTP/1.1 200 OK\r\n");
0N/A }
0N/A
0N/A out.print("Content-Type: text/html\r\n");
0N/A out.print("Connection: close\r\n");
0N/A out.print("\r\n");
0N/A out.flush();
0N/A
0N/A s.close();
0N/A
0N/A } catch (Exception e) {
0N/A e.printStackTrace();
0N/A }
0N/A }
0N/A
0N/A Modified() throws Exception {
0N/A
0N/A ss = new ServerSocket(0);
0N/A Thread thr = new Thread(this);
0N/A thr.start();
0N/A
0N/A URL testURL = new URL("http://localhost:" + ss.getLocalPort() +
0N/A "/index.html");
0N/A URLConnection URLConn = testURL.openConnection();
0N/A HttpURLConnection httpConn;
0N/A
0N/A if (URLConn instanceof HttpURLConnection) {
0N/A httpConn = (HttpURLConnection)URLConn;
0N/A httpConn.setAllowUserInteraction(false);
0N/A httpConn.setIfModifiedSince(9990000000000L);
0N/A int response = httpConn.getResponseCode();
0N/A if (response != 304)
0N/A throw new RuntimeException("setModifiedSince failure.");
0N/A }
0N/A }
0N/A
0N/A public static void main(String args[]) throws Exception {
0N/A new Modified();
0N/A }
0N/A}