1784N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
1784N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1784N/A *
1784N/A * This code is free software; you can redistribute it and/or modify it
1784N/A * under the terms of the GNU General Public License version 2 only, as
1784N/A * published by the Free Software Foundation.
1784N/A *
1784N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1784N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1784N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1784N/A * version 2 for more details (a copy is included in the LICENSE file that
1784N/A * accompanied this code).
1784N/A *
1784N/A * You should have received a copy of the GNU General Public License version
1784N/A * 2 along with this work; if not, write to the Free Software Foundation,
1784N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1784N/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.
1784N/A */
1784N/A/**
1784N/A * @test
1784N/A * @bug 6890349
1784N/A * @run main/othervm B6890349
1784N/A * @summary Light weight HTTP server
1784N/A */
1784N/A
1784N/Aimport java.net.*;
1784N/Aimport java.io.*;
1784N/A
1784N/Apublic class B6890349 extends Thread {
1784N/A public static final void main(String[] args) throws Exception {
1784N/A
1784N/A try {
1784N/A ServerSocket server = new ServerSocket (0);
1784N/A int port = server.getLocalPort();
1784N/A System.out.println ("listening on " + port);
1784N/A B6890349 t = new B6890349 (server);
1784N/A t.start();
1784N/A URL u = new URL ("http://127.0.0.1:"+port+"/foo\nbar");
1784N/A HttpURLConnection urlc = (HttpURLConnection)u.openConnection ();
1784N/A InputStream is = urlc.getInputStream();
1784N/A throw new RuntimeException ("Test failed");
1784N/A } catch (IOException e) {
1784N/A System.out.println ("OK");
1784N/A }
1784N/A }
1784N/A
1784N/A ServerSocket server;
1784N/A
1784N/A B6890349 (ServerSocket server) {
1784N/A this.server = server;
1784N/A }
1784N/A
1784N/A String resp = "HTTP/1.1 200 Ok\r\nContent-length: 0\r\n\r\n";
1784N/A
1784N/A public void run () {
1784N/A try {
1784N/A Socket s = server.accept ();
1784N/A OutputStream os = s.getOutputStream();
1784N/A os.write (resp.getBytes());
1784N/A } catch (IOException e) {
1784N/A System.out.println (e);
1784N/A }
1784N/A }
1784N/A}