Package kilim.examples
Class HttpFileServer
java.lang.Object
kilim.Task
kilim.nio.SessionTask
kilim.http.HttpSession
kilim.examples.HttpFileServer
- All Implemented Interfaces:
Runnable,EventSubscriber,Fiber.Worker
A simple file server over http
Usage: Run java kilim.examples.HttpFileServer [base directory name] From a browser, go to "http://localhost:7262".
A HttpFileServer object is a SessionTask, and is thus a thin wrapper over the socket connection. Its execute() method
is called once on connection establishment. The HttpRequest and HttpResponse objects are wrappers over a bytebuffer,
and unrelated to the socket. The request object is "filled in" by HttpSession.readRequest() and the response object
is sent by HttpSession.sendResponse(). The rest of the code is related to the mechanics of file serving, common to
Kilim and non-Kilim approaches alike. The objective of this example is merely to demonstrate Kilim API, not to have a
fully functioning file server.
-
Nested Class Summary
Nested classes/interfaces inherited from class kilim.http.HttpSession
HttpSession.StringRouter, HttpSession.StringSessionNested classes/interfaces inherited from class kilim.Task
Task.Fork, Task.Invoke<TT>, Task.Spawn<TT> -
Field Summary
FieldsFields inherited from class kilim.nio.SessionTask
endpointFields inherited from class kilim.Task
done, exitResult, fiber, id, pauseReason, running, scheduler, timer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancheck(HttpResponse resp, File file) voidexecute()private StringgetRelPath(File file) static voidstatic Stringvoidproblem(File file, HttpResponse resp, byte[] statusCode, String msg) voidsendDirectory(HttpResponse resp, File file, boolean headOnly) voidsendFile(HttpResponse resp, File file, boolean headOnly) private FileurlToPath(HttpRequest req) static voidusage()Methods inherited from class kilim.http.HttpSession
check, problem, readRequest, sendFile, sendResponseMethods inherited from class kilim.nio.SessionTask
closeMethods inherited from class kilim.Task
checkKill, dump, equals, errNotWoven, errNotWoven, errorExit, errorExit, execute, exit, exit, fork, getCurrentTask, getExecutionThread, getPauseReason, getScheduler, getStackDepth, getState, getTid, hashCode, id, idledown, informOnExit, invoke, isDone, join, joinb, onEvent, pause, pause, pinToThread, prePin, resume, resumeOnScheduler, run, setPauseReason, setScheduler, setTid, shutdown, sleep, spawn, spawn, start, toString, unpinFromThread, yield, yield
-
Field Details
-
baseDirectory
-
baseDirectoryName
-
mimeTypes
-
-
Constructor Details
-
HttpFileServer
public HttpFileServer()
-
-
Method Details
-
main
- Throws:
IOException
-
usage
public static void usage() -
execute
-
urlToPath
-
check
- Throws:
IOExceptionPausable
-
sendFile
- Throws:
IOExceptionPausable
-
sendDirectory
public void sendDirectory(HttpResponse resp, File file, boolean headOnly) throws Pausable, IOException - Throws:
PausableIOException
-
problem
public void problem(File file, HttpResponse resp, byte[] statusCode, String msg) throws IOException, Pausable - Throws:
IOExceptionPausable
-
getRelPath
- Throws:
IOException
-
mimeType
-