Package kilim.http
Class HttpSession
- java.lang.Object
-
- kilim.Task
-
- kilim.nio.SessionTask
-
- kilim.http.HttpSession
-
- All Implemented Interfaces:
java.lang.Runnable,EventSubscriber,Fiber.Worker
- Direct Known Subclasses:
HttpFileServer,HttpSession.StringSession,KilimMvc.Session,SimpleHttpServer.SimpleHttpSession
public class HttpSession extends SessionTask
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 Classes Modifier and Type Class Description static interfaceHttpSession.StringRouterstatic classHttpSession.StringSession-
Nested classes/interfaces inherited from class kilim.Task
Task.Fork, Task.Invoke<TT>, Task.Spawn<TT>
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static byte[]post(package private) static byte[]pre-
Fields inherited from class kilim.nio.SessionTask
endpoint
-
Fields inherited from class kilim.Task
done, exitResult, fiber, id, pauseReason, running, scheduler, timer
-
-
Constructor Summary
Constructors Constructor Description HttpSession()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheck(HttpResponse resp, java.io.File file, java.lang.String... bases)voidproblem(HttpResponse resp, byte[] statusCode, java.lang.String htmlMsg)Send an error page to the client.HttpRequestreadRequest(HttpRequest req)Reads the socket, parses the HTTP headers and the body (including chunks) into the req object.intsendFile(HttpRequest req, HttpResponse resp, java.io.File file, java.lang.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
close
-
Methods 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
-
-
-
-
Method Detail
-
readRequest
public HttpRequest readRequest(HttpRequest req) throws java.io.IOException, Pausable
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:
java.io.IOExceptionPausable
-
sendResponse
public void sendResponse(HttpResponse resp) throws java.io.IOException, Pausable
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:
java.io.IOExceptionPausable
-
problem
public void problem(HttpResponse resp, byte[] statusCode, java.lang.String htmlMsg) throws java.io.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:
java.io.IOExceptionPausable
-
sendFile
public int sendFile(HttpRequest req, HttpResponse resp, java.io.File file, java.lang.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
public boolean check(HttpResponse resp, java.io.File file, java.lang.String... bases) throws java.io.IOException, Pausable
- Throws:
java.io.IOExceptionPausable
-
-