Package kilim.http

Class HttpSession

All Implemented Interfaces:
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.
  • Field Details

    • pre

      static byte[] pre
    • post

      static byte[] post
  • Constructor Details

    • HttpSession

      public HttpSession()
  • Method Details

    • readRequest

      public HttpRequest readRequest(HttpRequest req) throws 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:
      IOException
      Pausable
    • sendResponse

      public void sendResponse(HttpResponse resp) throws 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:
      IOException
      Pausable
    • 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:
      IOException
      Pausable
    • 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 request
      resp - the response
      file - the file to send
      contentType - 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, File file, String... bases) throws IOException, Pausable
      Throws:
      IOException
      Pausable