Jetty Extras

Serving Resources from a relative path

Sometimes you may want to serve resources from a relative path, for example a sibling directory located at ../client. But paths containing .. are considered aliased and Jetty disallows these by default, as described in this policy.

If you’ve evaluated the security risks described in the link above and wish to enable aliases in paths, you can do so with allowAliases(true), eg:

sourceimport unfiltered.jetty.ContextAdder

unfiltered.jetty.Server.http(8080).
  context("/client"){ (ctx: ContextAdder) =>
    ctx.resources(new java.net.URI(
      """file:../client"""
    ).toURL).allowAliases(true)
  }.plan(myPlan).run()

Enabling Request Logs

Jetty can be configured to log all requests in Common or Extended formats with requestLogging. This is a global, not per-context, setting. At minimum you need to specify where to log to:

sourceunfiltered.jetty.Server.http(8080)
  .plan(myPlan)
  .requestLogging(
    filename = "/tmp/access.log",
    format = "some log format"
  )
  .run()
The source code for this page can be found here.