LambdaServlet

open class LambdaServlet(contentType: String, block: () -> String) : HttpServlet

An HttpServlet that serves the result of a lambda function as the HTTP GET response body.

Responses include Cache-Control: must-revalidate,no-cache,no-store headers. The body is encoded as UTF-8 unless contentType names a charset, and holds exactly what the lambda returned, with no line separator appended. If the lambda throws, the response is left untouched, so the container reports the error instead of an empty 200.

Only doGet is overridden, and HttpServlet answers HEAD through it, so a HEAD request runs the lambda too.

Parameters

contentType

the MIME content type for the response. Defaults to "text/plain".

block

a lambda that produces the response body string.

Inheritors

Constructors

Link copied to clipboard
constructor(contentType: String, block: () -> String)
constructor(block: () -> String)

Constructs a LambdaServlet with a default content type of "text/plain".

Properties

Link copied to clipboard
Link copied to clipboard
open val servletConfig: ServletConfig?
Link copied to clipboard
open val servletContext: ServletContext?
Link copied to clipboard
open val servletInfo: String?
Link copied to clipboard
open val servletName: String?

Functions

Link copied to clipboard
open fun destroy()
Link copied to clipboard
open fun getInitParameter(name: String?): String?
Link copied to clipboard
open fun init()
open fun init(config: ServletConfig?)
Link copied to clipboard
open fun log(msg: String?)
open fun log(message: String?, t: Throwable?)
Link copied to clipboard
open fun service(req: ServletRequest?, res: ServletResponse?)