From 8b4084c337d0f2b8409efa3deabaded4ebf6c9fb Mon Sep 17 00:00:00 2001 From: "gagan%netscape.com" Date: Fri, 11 Jun 1999 06:21:16 +0000 Subject: [PATCH] Added the test server for testing anamalous responses from HTTP servers. For more details read http://lxr.mozilla.org/mozilla/source/netwerk/testserver/docs/help.html --- netwerk/testserver/Connection.java | 98 ++++++++++++++ netwerk/testserver/ScriptFile.java | 190 ++++++++++++++++++++++++++++ netwerk/testserver/TestServer.java | 76 +++++++++++ netwerk/testserver/docs/bar.html | 6 + netwerk/testserver/docs/foo.html | 5 + netwerk/testserver/docs/generic.res | 2 + netwerk/testserver/docs/help.html | 58 +++++++++ netwerk/testserver/docs/urlmap | 97 ++++++++++++++ tools/testserver/Connection.java | 98 ++++++++++++++ tools/testserver/ScriptFile.java | 190 ++++++++++++++++++++++++++++ tools/testserver/TestServer.java | 76 +++++++++++ tools/testserver/docs/bar.html | 6 + tools/testserver/docs/foo.html | 5 + tools/testserver/docs/generic.res | 2 + tools/testserver/docs/help.html | 58 +++++++++ tools/testserver/docs/urlmap | 97 ++++++++++++++ 16 files changed, 1064 insertions(+) create mode 100644 netwerk/testserver/Connection.java create mode 100644 netwerk/testserver/ScriptFile.java create mode 100644 netwerk/testserver/TestServer.java create mode 100644 netwerk/testserver/docs/bar.html create mode 100644 netwerk/testserver/docs/foo.html create mode 100644 netwerk/testserver/docs/generic.res create mode 100644 netwerk/testserver/docs/help.html create mode 100644 netwerk/testserver/docs/urlmap create mode 100644 tools/testserver/Connection.java create mode 100644 tools/testserver/ScriptFile.java create mode 100644 tools/testserver/TestServer.java create mode 100644 tools/testserver/docs/bar.html create mode 100644 tools/testserver/docs/foo.html create mode 100644 tools/testserver/docs/generic.res create mode 100644 tools/testserver/docs/help.html create mode 100644 tools/testserver/docs/urlmap diff --git a/netwerk/testserver/Connection.java b/netwerk/testserver/Connection.java new file mode 100644 index 00000000000..c35f7813eef --- /dev/null +++ b/netwerk/testserver/Connection.java @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +import java.io.*; +import java.net.*; + +class Connection extends Thread { + + public static final boolean DEBUG = true; + public Socket client; + protected BufferedReader in; + protected PrintWriter out; + + final static String SERVER = "HTTP Test Server/1.1"; + + public Connection(Socket client_socket) { + client = client_socket; + + if (DEBUG) + { + System.out.println( + "---------------------------------------------------------"); + System.out.println(client); + } + try { + in = new BufferedReader(new InputStreamReader( + client.getInputStream())); + out = new PrintWriter(client.getOutputStream()); + this.start(); + } + catch (IOException e) { + try { + client.close(); + } + catch (IOException another) { + } + System.out.println("Exception while getting socket streams." + + e); + } + } + + final public void run() { + + String line = null; + String firstline = null; + request = new StringBuffer(); + + int len = 0; + try { + while(true) { + line = in.readLine(); + if (line == null) + break; + if (firstline == null) + firstline = new String(line); + len = line.length(); + if (len == 0) + break; + request.append(line); + request.append("\n"); + if (DEBUG) + System.out.println(line); + } + // This will appropriately write all the stuff based + // on the first line and the script file + ScriptFile sf = new ScriptFile(this, firstline, out); + out.flush(); + // mark for garbage collect + sf = null; + } // try + catch (IOException e) { + System.out.println("Some problem while communicating. " + e); + } + finally { + try { + client.close(); + } + catch (IOException e2) { + } + } + } + StringBuffer request; +} diff --git a/netwerk/testserver/ScriptFile.java b/netwerk/testserver/ScriptFile.java new file mode 100644 index 00000000000..bf20c462353 --- /dev/null +++ b/netwerk/testserver/ScriptFile.java @@ -0,0 +1,190 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +import java.io.*; +import java.util.Date; +/* + ScriptFile class reads off the script file and sets up the list + of delimiters. +*/ + +class ScriptFile { + + public static final String URLMAP = new String("docs/urlmap"); + + public ScriptFile(Connection c, String req, PrintWriter stream ) { + con = c; + request = req; + out = stream; + if (out == null) + out = new PrintWriter(System.out); + file = URLMAP; + try { + Parse(); + } + catch (IOException e) + { + out.println("HTTP/1.1 500 Server Error\n\n"); + out.println("Failed with this exception-"); + out.println(e); + } + out.flush(); + } + + public ScriptFile(String f) { + file = f; + out = new PrintWriter(System.out); + try { + Parse(); + } + catch (FileNotFoundException e) + { + out.println("HTTP/1.1 404 File Not Found\n\n"); + out.println("File not found!"); + out.println(e); + } + catch (IOException e) + { + out.println("HTTP/1.1 500 Server Error\n\n"); + out.println("Failed with this exception-"); + out.println(e); + } + out.flush(); + } + + public void Parse () throws IOException { + + if ((request == null) || (request.length() == 0) || request.startsWith("GET / ")) + { + WriteDefaultResponse(); + return; + } + + boolean outDirty = false; + if (file != null) + { + DataInputStream in = + new DataInputStream( + new BufferedInputStream( + new FileInputStream(file))); + + String s = new String(); + while((s = in.readLine())!= null) + { + s.trim(); + /* Skip comments */ + if ((s.length() == 0) || (s.charAt(0) == '#')) + continue; + if (s.startsWith("START")) { + // Check to see if this was in the requested URL + String filename = new String ("GET " + s.substring(6)); + if (request.startsWith(filename)) + { + continue; + } + else// Else skipto past the END + { + while (!s.startsWith("END")) + { + s = in.readLine(); + if (s != null) + { + s.trim(); + } + else + break; + } + } + } + else if (s.startsWith("INCLUDE")) { + outDirty = true; + WriteOutFile("docs/" + s.substring(8)); + } + else if (s.startsWith("CRLF")) { + outDirty = true; + out.println(); + } + else if (s.startsWith("END")) { + // ignore should never have appeared here though! + continue; + } + } + in.close(); + + if (outDirty) + { + out.flush(); + } + else + WriteDefaultResponse(); + } + } + + public static void main(String args[]) { + if (args.length >= 1) { + ScriptFile sf = new ScriptFile(args[0]); + /* Detect change stuff; + File f = new File(args[0]); + long lastMod = f.lastModified(); + while (f.lastModified() == lastMod) { + } + sf.Parse(); + */ + } + } + + protected void WriteOutFile(String filename) throws IOException { + DataInputStream incl = + new DataInputStream( + new BufferedInputStream( + new FileInputStream(filename))); + // This doesn't have to be line wise... change later TODO + String s; + while ((s = incl.readLine()) != null) + { + out.println(s); + } + incl.close(); + } + + protected void WriteDefaultResponse() throws IOException { + WriteOutFile("docs/generic.res"); + out.println("Date: " + (new Date()).toString()); + if (file != null) + { + File f = new File(file); + out.println("Last-modified: " + (new Date(f.lastModified())).toString()); + } + out.println("\n"); // prints 2 + if (con != null) + { + out.println("

Rec'd. the following request-

"); + out.println("
");
+                out.println(con.request);
+                out.println("
"); + out.println("From- " + con.client); + } + } + + String file = null; + // The string associated with this script occurence + + String request; + PrintWriter out; + Connection con; +} diff --git a/netwerk/testserver/TestServer.java b/netwerk/testserver/TestServer.java new file mode 100644 index 00000000000..15afb9f941d --- /dev/null +++ b/netwerk/testserver/TestServer.java @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +import java.io.*; +import java.net.*; + +public class TestServer extends Thread { + + final static int DEFAULT_PORT = 4321; + + protected int port; + protected ServerSocket listen_socket; + + public static void fail(Exception e, String msg) { + System.err.println(msg + ":" + e); + e.printStackTrace(); + } + + public TestServer() { + this(DEFAULT_PORT); + } + + public TestServer(int port) { + this.port = port; + try { + listen_socket = new ServerSocket(port); + } + catch (IOException e) { + fail(e, "Exception creating server socket"); + } + System.out.println("Server: listening on port " + port); + this.start(); + } + + public void run() { + try { + while (true) { + Socket client_socket = listen_socket.accept(); + Connection c = new Connection(client_socket); + } + } + catch (IOException e) { + fail(e, "Exception while listening"); + } + } + + public static void main(String args[]) { + int port = DEFAULT_PORT; + if (args.length == 1) { + try { + port = Integer.parseInt(args[0]); + } + catch (NumberFormatException e) { + port = DEFAULT_PORT; + } + } + new TestServer(port); + } + +} + diff --git a/netwerk/testserver/docs/bar.html b/netwerk/testserver/docs/bar.html new file mode 100644 index 00000000000..3f8513ae734 --- /dev/null +++ b/netwerk/testserver/docs/bar.html @@ -0,0 +1,6 @@ + + +
--------
+This is bar.html + + diff --git a/netwerk/testserver/docs/foo.html b/netwerk/testserver/docs/foo.html new file mode 100644 index 00000000000..8ce5c1b33a4 --- /dev/null +++ b/netwerk/testserver/docs/foo.html @@ -0,0 +1,5 @@ + + +This is foo.html + + diff --git a/netwerk/testserver/docs/generic.res b/netwerk/testserver/docs/generic.res new file mode 100644 index 00000000000..4d6ab7dcfbe --- /dev/null +++ b/netwerk/testserver/docs/generic.res @@ -0,0 +1,2 @@ +HTTP/1.1 200 OK +Server: HTTP Test Server/1.1 diff --git a/netwerk/testserver/docs/help.html b/netwerk/testserver/docs/help.html new file mode 100644 index 00000000000..910ebc166ce --- /dev/null +++ b/netwerk/testserver/docs/help.html @@ -0,0 +1,58 @@ + + + Help file for HTTP TestServer/1.1 + + + +

Help file for HTTP TestServer/1.1

+The HTTP TestServer is a simple server written to test some special HTTP +behaviour. It is based on a script file (docs/urlmap) and can be easily +extended to add special response situations.

+ +To compile this you will need any version of JDK >1.1.2. Just compile them +with command-

javac *.java
+And then run the server with command-
java TestServer [port]
+The port is optional and if not specified defaults to 4321. +Assuming that the server is running on http://foo:4321/ +Use the following URLs to retrieve special responses. In order to create +your own special case- telnet to foo, and edit the docs/urlmap file to +handle special cases and then add info here about it. +

+

+ + + + + + + + + +
http://foo:4321/helpThis help file.
http://foo:4321/Default echo of the server. Prints the request out.
+The subsequent ones may be combined to generate multiple results. NOTE: This +hasn't been fixed as yet. So it wont work for now. But if it did... +You can try something fancy like- http://foo:4321/multi&close&both + +
+ + + + + + + + + + + + + + + +
http://foo:4321/multiReturns a multipart message. 
http://foo:4321/closeReturns "Connection: close" in a response header.
http://foo:4321/bothReturns the request as well as the response headers.
+ +

If you need any more help with running this server, or have suggestions +to improve it let me +know. + + diff --git a/netwerk/testserver/docs/urlmap b/netwerk/testserver/docs/urlmap new file mode 100644 index 00000000000..b89527b0e52 --- /dev/null +++ b/netwerk/testserver/docs/urlmap @@ -0,0 +1,97 @@ +# +# Foo- Copy/Paste these 9 lines to generate new cases. +# +START /foo +INCLUDE generic.res +Content-Type: text/html +CRLF +INCLUDE foo.html +END + +# +# This is a simple multipart message example +# for more complicated stuff try "complex" +# +START /multi +INCLUDE generic.res +Content-Type: multipart/mixed; boundary=ComfortablyNumb +CRLF +--ComfortablyNumb +INCLUDE foo.html +CRLF +--ComfortablyNumb +INCLUDE bar.html +--ComfortablyNumb-- +END + +# +# Send the help file to see how this server is used. +# +START /help +INCLUDE generic.res +CRLF +INCLUDE help.html +END + +# +# A more complex variation of multipart messaging. +# If this works, every code contributor to Necko +# gets a treat from me personally :) -Gagan +# +START /complex +INCLUDE generic.res +Content-Type: multipart/mixed; boundary=TheWallFromPinkFloyd +CRLF +Preamble to multipart messages. Only clients that dont handle +multipart would see this! +CRLF +--TheWallFromPinkFloyd +Content-Type: text/plain +CRLF + The Thin Ice + Another Brick In The Wall-I +CRLF +--TheWallFromPinkFloyd +Content-Type: multipart/parallel; boundary=SideTwoOfTheWall +CRLF +--SideTwoOfTheWall +Content-Type: text/plain +CRLF + Young Lust + Goodbye Cruel World +CRLF +--SideTwoOfTheWall +Content-Type: text/plain +CRLF + Another Brick In The Wall-II +--SideTwoOfTheWall-- +CRLF +--TheWallFromPinkFloyd +Content-Type: text/plain +CRLF + Another Brick In The Wall-III +--TheWallFromPinkFloyd-- +CRLF +END + +# +# Pragma: no-cache test +# +START /pragma +INCLUDE generic.res +Pragma: no-cache +Content-Type: text/html +CRLF +INCLUDE foo.html +END + +# +# close: return a connection: close header +# +START /close +INCLUDE generic.res +Connection: Close +Content-Type: text/html +CRLF +INCLUDE foo.html +END diff --git a/tools/testserver/Connection.java b/tools/testserver/Connection.java new file mode 100644 index 00000000000..c35f7813eef --- /dev/null +++ b/tools/testserver/Connection.java @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +import java.io.*; +import java.net.*; + +class Connection extends Thread { + + public static final boolean DEBUG = true; + public Socket client; + protected BufferedReader in; + protected PrintWriter out; + + final static String SERVER = "HTTP Test Server/1.1"; + + public Connection(Socket client_socket) { + client = client_socket; + + if (DEBUG) + { + System.out.println( + "---------------------------------------------------------"); + System.out.println(client); + } + try { + in = new BufferedReader(new InputStreamReader( + client.getInputStream())); + out = new PrintWriter(client.getOutputStream()); + this.start(); + } + catch (IOException e) { + try { + client.close(); + } + catch (IOException another) { + } + System.out.println("Exception while getting socket streams." + + e); + } + } + + final public void run() { + + String line = null; + String firstline = null; + request = new StringBuffer(); + + int len = 0; + try { + while(true) { + line = in.readLine(); + if (line == null) + break; + if (firstline == null) + firstline = new String(line); + len = line.length(); + if (len == 0) + break; + request.append(line); + request.append("\n"); + if (DEBUG) + System.out.println(line); + } + // This will appropriately write all the stuff based + // on the first line and the script file + ScriptFile sf = new ScriptFile(this, firstline, out); + out.flush(); + // mark for garbage collect + sf = null; + } // try + catch (IOException e) { + System.out.println("Some problem while communicating. " + e); + } + finally { + try { + client.close(); + } + catch (IOException e2) { + } + } + } + StringBuffer request; +} diff --git a/tools/testserver/ScriptFile.java b/tools/testserver/ScriptFile.java new file mode 100644 index 00000000000..bf20c462353 --- /dev/null +++ b/tools/testserver/ScriptFile.java @@ -0,0 +1,190 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +import java.io.*; +import java.util.Date; +/* + ScriptFile class reads off the script file and sets up the list + of delimiters. +*/ + +class ScriptFile { + + public static final String URLMAP = new String("docs/urlmap"); + + public ScriptFile(Connection c, String req, PrintWriter stream ) { + con = c; + request = req; + out = stream; + if (out == null) + out = new PrintWriter(System.out); + file = URLMAP; + try { + Parse(); + } + catch (IOException e) + { + out.println("HTTP/1.1 500 Server Error\n\n"); + out.println("Failed with this exception-"); + out.println(e); + } + out.flush(); + } + + public ScriptFile(String f) { + file = f; + out = new PrintWriter(System.out); + try { + Parse(); + } + catch (FileNotFoundException e) + { + out.println("HTTP/1.1 404 File Not Found\n\n"); + out.println("File not found!"); + out.println(e); + } + catch (IOException e) + { + out.println("HTTP/1.1 500 Server Error\n\n"); + out.println("Failed with this exception-"); + out.println(e); + } + out.flush(); + } + + public void Parse () throws IOException { + + if ((request == null) || (request.length() == 0) || request.startsWith("GET / ")) + { + WriteDefaultResponse(); + return; + } + + boolean outDirty = false; + if (file != null) + { + DataInputStream in = + new DataInputStream( + new BufferedInputStream( + new FileInputStream(file))); + + String s = new String(); + while((s = in.readLine())!= null) + { + s.trim(); + /* Skip comments */ + if ((s.length() == 0) || (s.charAt(0) == '#')) + continue; + if (s.startsWith("START")) { + // Check to see if this was in the requested URL + String filename = new String ("GET " + s.substring(6)); + if (request.startsWith(filename)) + { + continue; + } + else// Else skipto past the END + { + while (!s.startsWith("END")) + { + s = in.readLine(); + if (s != null) + { + s.trim(); + } + else + break; + } + } + } + else if (s.startsWith("INCLUDE")) { + outDirty = true; + WriteOutFile("docs/" + s.substring(8)); + } + else if (s.startsWith("CRLF")) { + outDirty = true; + out.println(); + } + else if (s.startsWith("END")) { + // ignore should never have appeared here though! + continue; + } + } + in.close(); + + if (outDirty) + { + out.flush(); + } + else + WriteDefaultResponse(); + } + } + + public static void main(String args[]) { + if (args.length >= 1) { + ScriptFile sf = new ScriptFile(args[0]); + /* Detect change stuff; + File f = new File(args[0]); + long lastMod = f.lastModified(); + while (f.lastModified() == lastMod) { + } + sf.Parse(); + */ + } + } + + protected void WriteOutFile(String filename) throws IOException { + DataInputStream incl = + new DataInputStream( + new BufferedInputStream( + new FileInputStream(filename))); + // This doesn't have to be line wise... change later TODO + String s; + while ((s = incl.readLine()) != null) + { + out.println(s); + } + incl.close(); + } + + protected void WriteDefaultResponse() throws IOException { + WriteOutFile("docs/generic.res"); + out.println("Date: " + (new Date()).toString()); + if (file != null) + { + File f = new File(file); + out.println("Last-modified: " + (new Date(f.lastModified())).toString()); + } + out.println("\n"); // prints 2 + if (con != null) + { + out.println("

Rec'd. the following request-

"); + out.println("
");
+                out.println(con.request);
+                out.println("
"); + out.println("From- " + con.client); + } + } + + String file = null; + // The string associated with this script occurence + + String request; + PrintWriter out; + Connection con; +} diff --git a/tools/testserver/TestServer.java b/tools/testserver/TestServer.java new file mode 100644 index 00000000000..15afb9f941d --- /dev/null +++ b/tools/testserver/TestServer.java @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +import java.io.*; +import java.net.*; + +public class TestServer extends Thread { + + final static int DEFAULT_PORT = 4321; + + protected int port; + protected ServerSocket listen_socket; + + public static void fail(Exception e, String msg) { + System.err.println(msg + ":" + e); + e.printStackTrace(); + } + + public TestServer() { + this(DEFAULT_PORT); + } + + public TestServer(int port) { + this.port = port; + try { + listen_socket = new ServerSocket(port); + } + catch (IOException e) { + fail(e, "Exception creating server socket"); + } + System.out.println("Server: listening on port " + port); + this.start(); + } + + public void run() { + try { + while (true) { + Socket client_socket = listen_socket.accept(); + Connection c = new Connection(client_socket); + } + } + catch (IOException e) { + fail(e, "Exception while listening"); + } + } + + public static void main(String args[]) { + int port = DEFAULT_PORT; + if (args.length == 1) { + try { + port = Integer.parseInt(args[0]); + } + catch (NumberFormatException e) { + port = DEFAULT_PORT; + } + } + new TestServer(port); + } + +} + diff --git a/tools/testserver/docs/bar.html b/tools/testserver/docs/bar.html new file mode 100644 index 00000000000..3f8513ae734 --- /dev/null +++ b/tools/testserver/docs/bar.html @@ -0,0 +1,6 @@ + + +
--------
+This is bar.html + + diff --git a/tools/testserver/docs/foo.html b/tools/testserver/docs/foo.html new file mode 100644 index 00000000000..8ce5c1b33a4 --- /dev/null +++ b/tools/testserver/docs/foo.html @@ -0,0 +1,5 @@ + + +This is foo.html + + diff --git a/tools/testserver/docs/generic.res b/tools/testserver/docs/generic.res new file mode 100644 index 00000000000..4d6ab7dcfbe --- /dev/null +++ b/tools/testserver/docs/generic.res @@ -0,0 +1,2 @@ +HTTP/1.1 200 OK +Server: HTTP Test Server/1.1 diff --git a/tools/testserver/docs/help.html b/tools/testserver/docs/help.html new file mode 100644 index 00000000000..910ebc166ce --- /dev/null +++ b/tools/testserver/docs/help.html @@ -0,0 +1,58 @@ + + + Help file for HTTP TestServer/1.1 + + + +

Help file for HTTP TestServer/1.1

+The HTTP TestServer is a simple server written to test some special HTTP +behaviour. It is based on a script file (docs/urlmap) and can be easily +extended to add special response situations.

+ +To compile this you will need any version of JDK >1.1.2. Just compile them +with command-

javac *.java
+And then run the server with command-
java TestServer [port]
+The port is optional and if not specified defaults to 4321. +Assuming that the server is running on http://foo:4321/ +Use the following URLs to retrieve special responses. In order to create +your own special case- telnet to foo, and edit the docs/urlmap file to +handle special cases and then add info here about it. +

+

+ + + + + + + + + +
http://foo:4321/helpThis help file.
http://foo:4321/Default echo of the server. Prints the request out.
+The subsequent ones may be combined to generate multiple results. NOTE: This +hasn't been fixed as yet. So it wont work for now. But if it did... +You can try something fancy like- http://foo:4321/multi&close&both + +
+ + + + + + + + + + + + + + + +
http://foo:4321/multiReturns a multipart message. 
http://foo:4321/closeReturns "Connection: close" in a response header.
http://foo:4321/bothReturns the request as well as the response headers.
+ +

If you need any more help with running this server, or have suggestions +to improve it let me +know. + + diff --git a/tools/testserver/docs/urlmap b/tools/testserver/docs/urlmap new file mode 100644 index 00000000000..b89527b0e52 --- /dev/null +++ b/tools/testserver/docs/urlmap @@ -0,0 +1,97 @@ +# +# Foo- Copy/Paste these 9 lines to generate new cases. +# +START /foo +INCLUDE generic.res +Content-Type: text/html +CRLF +INCLUDE foo.html +END + +# +# This is a simple multipart message example +# for more complicated stuff try "complex" +# +START /multi +INCLUDE generic.res +Content-Type: multipart/mixed; boundary=ComfortablyNumb +CRLF +--ComfortablyNumb +INCLUDE foo.html +CRLF +--ComfortablyNumb +INCLUDE bar.html +--ComfortablyNumb-- +END + +# +# Send the help file to see how this server is used. +# +START /help +INCLUDE generic.res +CRLF +INCLUDE help.html +END + +# +# A more complex variation of multipart messaging. +# If this works, every code contributor to Necko +# gets a treat from me personally :) -Gagan +# +START /complex +INCLUDE generic.res +Content-Type: multipart/mixed; boundary=TheWallFromPinkFloyd +CRLF +Preamble to multipart messages. Only clients that dont handle +multipart would see this! +CRLF +--TheWallFromPinkFloyd +Content-Type: text/plain +CRLF + The Thin Ice + Another Brick In The Wall-I +CRLF +--TheWallFromPinkFloyd +Content-Type: multipart/parallel; boundary=SideTwoOfTheWall +CRLF +--SideTwoOfTheWall +Content-Type: text/plain +CRLF + Young Lust + Goodbye Cruel World +CRLF +--SideTwoOfTheWall +Content-Type: text/plain +CRLF + Another Brick In The Wall-II +--SideTwoOfTheWall-- +CRLF +--TheWallFromPinkFloyd +Content-Type: text/plain +CRLF + Another Brick In The Wall-III +--TheWallFromPinkFloyd-- +CRLF +END + +# +# Pragma: no-cache test +# +START /pragma +INCLUDE generic.res +Pragma: no-cache +Content-Type: text/html +CRLF +INCLUDE foo.html +END + +# +# close: return a connection: close header +# +START /close +INCLUDE generic.res +Connection: Close +Content-Type: text/html +CRLF +INCLUDE foo.html +END