Jibble Web Server

An extremely small Java web server

Download WebServerLite.jar (9.6kb)

Contents

Introduction

Jibble Web Server is an extremely small web server written in Java.  It correctly supports a variety of file types, allowing delivery of multimedia web content and allows many HTTP requests to be dealt with simultaneously.

This is an example implementation that I have written based on my lectures given to first year Computer Science undergraduates at the University of Kent, UK. This shows what can be achived with some of the material covered in the lecture notes.

Main Features

How big is the program?

The entire web server is less than 10kb in size.  To be precise, it is only 9599 bytes in size, which is smaller than this document and fairly impressive considering the features that have been squeezed in.

Content type support

The web server is aware of and supports the following content types: -

Content type Recognised filename extensions
application/postscript ai ps eps
application/rtf rtf
audio/basic au snd
application/octet-stream bin dms lha lzh exe class
application/msword doc
application/pdf pdf
application/powerpoint ppt
application/smil smi smil sml
application/x-javascript js
application/zip zip
audio/midi midi kar
audio/mpeg mpga mp2 mp3
audio/x-wav wav
image/gif gif
image/ief ief
image/jpeg jpeg jpg jpe
image/png png
image/tiff tiff tif
model/vrml wrl vrml
text/css css
text/html html htm shtml shtm stm sht
text/plain txt inf nfo
text/xml xml dtd
video/mpeg mpeg mpg mpe
video/x-msvideo avi

Any unrecognised file types will be delivered with the application/octet-stream content type.

Running the web server

The web server is packaged in a single small jar file for ease of use.  You will need Java runtime version 1.2 or later installed in order to execute the web server.

To execute the web server, issue the following command: -

java -jar WebServerLite.jar

This will start the web server on the default port (80) and your web root directory will be the current directory.

To change the port number and location of the web root directory, you can execute the web server with optional parameters: -

java -jar WebServerLite.jar c:\inetpub\wwwroot 8080

Note that you must have installed a Java Runtime Environment in order to run Java programs. Please read this guide on How to set up Java if you need help.

Directory browsing and index pages

Accessing a directory via the web server will present you with a browsable directory listing of all files in the logical web directory.  Users will be prevented from obtaining any directory listings or viewing any files that are not reachable by descending from the web root directory.

The exception to this is if the directory contains a file recognised to be an index page, in which case the contents of that file will be delivered to the client.

The known index page names are (in order): -

  1. index.html
  2. index.htm
  3. index.shtml
  4. index.shtm
  5. index.stm
  6. index.sht

Server Side Includes

The web server provides limited SSI support in the form of the "#include" element.  Any file with an extension of .shtml, .shtm, .stm or .sht will be processed by the SSI engine.  Such pages may include the "#include file" directive in order to include the contents of another file on the page.  If the included file also has a recognised SSI filename extension, then it too will be processed.  The inclusion process will be cleanly halted if a circular inclusion pattern is detected.

To include another file on a page with this web server, you must use the exact following syntax: -

<!--#include file="filename.inc" -->

This will caused the comment to be replaced with the contents of the file called filename.inc before it is delivered to the client.

Please note that all filenames must be relative to the location of the SSI page from which they are included.  It is also important to note that files outside of the web root directory may also be included.  This is only meant to be a personal web server, so that feature has been provided to make it easier for you to include files from other places on the same disk partition.

Server-side scripting

Server-side scripting allows a web server to deliver dynamic pages.  These are typically generated on-the-fly by running a script on the web server in order to produce HTML dynamically.  This web server supports the execution of scripts if their path under the web root directory contains the string "cgi-bin".  All scripts must be executable in order to be processed by the web server.  If you are running the web server on Microsoft Windows, then you can test that the server-side scripting works by placing the following batch file in a directory called cgi-bin: -

cgi_test.bat

@echo Content-Type: text/html
@echo.
@echo If you can read this, then your CGI jibble is set up properly!
@echo ^<p^>Server variables: -
@echo ^<pre^>
@set

To try out the above script, make sure it is saved in a directory called cgi-bin, under your web root directory.  Now if you access this file via a web browser, rather than seeing the contents of the file, you should (fingers crossed!) see the output from executing the batch file.  This should give you a page that displays the text "If you can read this, then your CGI jibble is set up properly!", followed by a list of the server variables.  These typically show you what sort of web browser the client is using, etc.

Logging

All HTTP requests, whether successful or not, will be logged to the standard output.  You may find it useful to redirect this to a file for later analysis.

Each log entry is time stamped and is in the following format: -

[Sat Dec 08 20:16:25 GMT 2001] 127.0.0.1 "GET / HTTP/1.1" 200

Each line in the log consists, in order, of a timestamp, the I.P. address of the remote host, the raw request and finally a number to represent the status of the request.

Typical request status values: -

Code Meaning
200 OK
403 Forbidden
404 File Not Found
405 Method Not Allowed
000 Reserved for error messages from the web server

Miscellaneous jibble

The web server responds to HTTP/1.0 and HTTP/1.1 GET requests with HTTP/1.0.  Connection to the client is terminated if an unrecognised request is received.

The server processes and stores all headers sent within the client's request.  These are currently not used but may be used in future releases of this web server.

An HTTP 200 (OK) response is issued in response to the client's request if the file or directory was found and readable.  If the directory does not contain an index page, the server then proceeds to deliver an HTML-formatted page describing the files in the directory.  Otherwise, the appropriate file is delivered to the client with a suitable content type.

Attempts to trick the server into requesting a file or directory that is not reachable by descending the web root directory are dealt with by issuing the client with an HTTP 403 (Forbidden) response.

If a file or directory does not exist, the server issues the client with an HTTP 404 (File Not Found) response.

The web server does not currently perform any server-side caching of files.

There is currently no limit to the number of simultaneous connections that the web server can accept.

Feel free to email me feature requests or ideas for improvement of the next incarnation of this web server - nothing too bulky, mind! :-) Feature requests may be emailed to the address at the bottom of this page.

Who made it?

Jibble Web Server was made by Paul Mutton, who wanted a simple and small web server to be able to deliver web pages and other content from nearly any platform.

The idea behind keeping the web server small was twofold.  Firstly, it saves a lot of storage resources and it means people can download it in no time at all.  Secondly, reducing the total amount of code makes it much easier to ensure that the server is secure (although I would be foolish to ever make any such guarantees, despite the care taken to strive towards this).

To keep the main jar file small, the source-code is not included. The source-code can be downloaded separately in WebServerFull.jar.

Licensing

This software product is OSI Certified Open Source Software, available under the GNU General Public License (GPL). Since the GPL may be too restrictive for use in proprietary applications, a commercial license is also provided.

Purchase a commercial license for this software.

 

Search this site

 

Copyright Paul Mutton 2001-2013
http://www.jibble.org/
Feedback welcomed
email

~
Dreamhost
Web Hosting

~
Dreamhost
Web Hosting