Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 1.88 KB

02.0.0 Request Lifecycle.md

File metadata and controls

32 lines (22 loc) · 1.88 KB

Request Lifecycle

Every time a user visits a page on your site, they create a request, using HTTP, and get a response, also over HTTP. The HttpRequest and HttpResponse form the basics of any request from the client - we read the input (HttpRequest) and write the output (HttpResponse).

Each request goes through the following lifecycle:

  • We set up the HttpContext object with our HttpRequest and HttpResponse.

  • This HttpContext is then passed through the various modules:

    • Each UFRequestMiddleware, in order.
    • Each UFRequestHandler, in order.
    • Each UFResponseMiddleware, in order.
    • Each UFLogHandler, in order.

    Each module has can change some details of the HttpContext, or mark parts of the request as complete. For example, a request middleware could load a result from the cache, write it to the HttpResponse, and so mark the request as complete, so no further processing is required.

    If an error is encountered, then the HttpContext is then passed through:

    • Each UFErrorHandler, in order. The given error value is also passed to the error handler.
    • Each UFLogHandler, in order.
  • Once each module has run it's course, we flush the HttpResponse to the client, and wrap up the request.

Platform Differences

  • On PHP, for every request, a UfrontApplication is created, a HttpContext is created, and the request is executed.
  • Neko without neko.Web.cacheModule behaves the same as PHP.
  • Neko with neko.Web.cacheModule will load the UfrontApplication on the first request, and keep one copy alive for each thread. For each request, one of the existing threads will be used, the HttpContext will be created, and the request will be executed.
  • On Node JS, a UfrontApplication is created, and a HttpServer launched. Each HTTP request from the server is then converted to a HttpContext and executed accordingly.