pygmy.handlers
Class FileHandler
java.lang.Object
pygmy.core.AbstractHandler
pygmy.handlers.FileHandler
- All Implemented Interfaces:
- Handler
public class FileHandler
- extends AbstractHandler
- implements Handler
This is the most basic Handler of a web server. It serves up files from a specified directory. For all urls
matching the url-prefix parameter, it translates those into files on the root files system starting at the root
parameter. It does pay attention to the Range http header parameter, and will send a range of bytes from a
request file. It also sets the file-path request property to the translate local system path of the file.
Other handlers could use this so that they don't have to translate the URL into a path. This handler ignores
directory requests, but will serve up default files ( like index.html, if the config parameter is set ). It does
not provide a directory listing see DirectoryHandler
for that functionality.
url-prefix | The prefix to filter request urls. | None | Yes |
root | A local system path to the root of the folder to share. | None | Yes |
default-file | The name of the default file that should be used if no file is specified in the URL. | index.html | No |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
log
public static final java.util.logging.Logger log
ROOT_OPTION
public static final ConfigOption ROOT_OPTION
DEFAULT_FILE_OPTION
public static final ConfigOption DEFAULT_FILE_OPTION
IF_MODIFIED
public static final java.lang.String IF_MODIFIED
- See Also:
- Constant Field Values
LAST_MODIFIED_KEY
public static final java.lang.String LAST_MODIFIED_KEY
- See Also:
- Constant Field Values
RANGE_HEADER_KEY
public static final java.lang.String RANGE_HEADER_KEY
- See Also:
- Constant Field Values
FileHandler
public FileHandler()
initialize
public boolean initialize(java.lang.String handlerName,
Server server)
- Specified by:
initialize
in interface Handler
- Overrides:
initialize
in class AbstractHandler
handleBody
protected boolean handleBody(HttpRequest request,
HttpResponse response)
throws java.io.IOException
- Overrides:
handleBody
in class AbstractHandler
- Throws:
java.io.IOException
sendFile
public static void sendFile(HttpRequest request,
HttpResponse response,
java.io.File file,
java.lang.String type)
throws java.io.IOException
- Throws:
java.io.IOException