Package kilim.http
Class HttpSession
java.lang.Object
kilim.Task
kilim.nio.SessionTask
kilim.http.HttpSession
- All Implemented Interfaces:
Runnable,EventSubscriber,Fiber.Worker
- Direct Known Subclasses:
HttpFileServer,HttpSession.StringSession,KilimMvc.Session,SimpleHttpServer.SimpleHttpSession
Responsible for creating an HTTPRequest object out of raw bytes from a socket, and for sending an HTTPResponse object
in its entirety.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic classNested classes/interfaces inherited from class kilim.Task
Task.Fork, Task.Invoke<TT>, Task.Spawn<TT> -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static byte[](package private) static byte[]Fields 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, String... bases) voidproblem(HttpResponse resp, byte[] statusCode, String htmlMsg) Send an error page to the client.readRequest(HttpRequest req) Reads the socket, parses the HTTP headers and the body (including chunks) into the req object.intsendFile(HttpRequest req, HttpResponse resp, File file, String contentType) send a file with content length to the clientvoidsendResponse(HttpResponse resp) Send the response object in its entirety, and mark it for reuse.Methods inherited from class kilim.nio.SessionTask
closeMethods inherited from class kilim.Task
checkKill, dump, equals, errNotWoven, errNotWoven, errorExit, errorExit, execute, 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
-
pre
static byte[] pre -
post
static byte[] post
-
-
Constructor Details
-
HttpSession
public HttpSession()
-
-
Method Details
-
readRequest
Reads the socket, parses the HTTP headers and the body (including chunks) into the req object.- Parameters:
req- . The HttpRequest object is reset before filling it in.- Returns:
- the supplied request object. This is to encourage buffer reuse.
- Throws:
IOExceptionPausable
-
sendResponse
Send the response object in its entirety, and mark it for reuse. Often, the resp object may only contain the header, and the body is sent separately. It is the caller's responsibility to make sure that the body matches the header (in terms of encoding, length, chunking etc.)- Throws:
IOExceptionPausable
-
problem
public void problem(HttpResponse resp, byte[] statusCode, String htmlMsg) throws IOException, Pausable Send an error page to the client.- Parameters:
resp- The response object.statusCode- See HttpResponse.ST*htmlMsg- The body of the message that gives more detail.- Throws:
IOExceptionPausable
-
sendFile
public int sendFile(HttpRequest req, HttpResponse resp, File file, String contentType) throws Pausable send a file with content length to the client- Parameters:
req- the requestresp- the responsefile- the file to sendcontentType- if non-null, set the content type- Returns:
- 0 on success, 1 for not found, 2 for couldn't send
- Throws:
Pausable
-
check
- Throws:
IOExceptionPausable
-