DebugRequest

class DebugRequest @JvmOverloads constructor(val path: String, val method: String, val queryParams: Map<String, List<String>> = emptyMap(), val headers: Headers = Headers.EMPTY, val body: ByteArray? = null, val contentType: MediaType? = null)

An incoming debug API request handed to DebugTab.handle.

Constructed by the Lustro runtime, but the constructor is public so consumers can build instances directly in unit tests; call cancel there to simulate the runtime giving up on a request. The path is everything after /api/v1/<tab-id>/.

Constructors

Link copied to clipboard
constructor(path: String, method: String, queryParams: Map<String, List<String>> = emptyMap(), headers: Headers = Headers.EMPTY, body: ByteArray? = null, contentType: MediaType? = null)

Properties

Link copied to clipboard

The raw request body bytes, or null if there is no body.

Link copied to clipboard

The parsed Content-Type of the body, or null if absent/unparseable.

Link copied to clipboard

The request headers. The runtime leaves out Authorization and Cookie, which carry the debug session's credentials.

Link copied to clipboard

Whether the runtime has stopped waiting for this request: it outlived the per-request timeout, so the client already got a 504, or the debug server is shutting down. Whatever DebugTab.handle returns after that is discarded, so long-running work should check this and return early.

Link copied to clipboard

The HTTP method, e.g. GET or POST.

Link copied to clipboard

The request path after /api/v1/<tab-id>/, as the request gave it, such as items/7 or seed/: "" for the tab root, both /api/v1/<tab-id> and /api/v1/<tab-id>/.

Link copied to clipboard

Query parameters, each name mapped to its ordered list of values.

Functions

Link copied to clipboard

Returns the request body decoded as a UTF-8 string, or null if there is no body.

Link copied to clipboard
fun cancel()

Cancels this request: isCancelled turns true and every action registered with onCancel runs once, in registration order, on the calling thread. Later calls do nothing. If an action throws, the rest still run and the first failure is rethrown afterwards.

Link copied to clipboard

Parses an application/x-www-form-urlencoded body, as curl -d key=value and an HTML form send it, into each name mapped to its ordered list of values. Returns an empty map when the body has another content type, or none.

Link copied to clipboard
fun onCancel(action: Runnable)

Runs action when this request is cancelled, or right away, on the calling thread, if it already is.

Link copied to clipboard
fun queryParam(name: String): String?

Returns the first value of the query parameter named name, or null if the parameter is absent or has no values.