handle
Handles a debug API request. Return null for a route that the tab does not have, also for a method that a route does not take: the client gets an enveloped 404, or a 405 with an Allow header when the tab's OpenAPI document declares the path with other methods. For that check, one slash at the end of the path does not count, as for the declared routes, so a tab that routes by hand treats items/ as items. Throwing anything, including an Error such as TODO(), produces an enveloped 500. Throwing a DebugResponseException produces its response.
By default, routes request to the routes that routes declares: null when no declared path matches, or when a path segment does not fit its parameter, 405 with Allow for a declared path with another method, 400 with field for a missing or wrong query parameter or body, and else the route handler's response. A tab that overrides this to route some paths by hand can call super.handle(request) for the declared ones.
Invoked OFF the main thread, and calls may be concurrent (the runtime dispatches multiple requests in flight), so a tab holding mutable state must be thread-safe. Blocking on I/O here is fine — the runtime enforces a per-request timeout.
When a request times out, the client gets a 504 and the runtime cancels the request: DebugRequest.isCancelled turns true, the actions registered with DebugRequest.onCancel run, and this thread is interrupted. A handler that ignores all three keeps its request's concurrency slot until it returns.
The runtime authenticates the request before calling this and does not pass the credentials on: DebugRequest.headers never contains Authorization or Cookie.
The runtime also rejects browser requests from other origins, whatever the method. For a GET or HEAD, though, it can go only by Sec-Fetch-Site, which browsers send only to loopback and HTTPS addresses, and older ones not at all. So GET and HEAD must not change state: use POST, PUT, PATCH, or DELETE for anything that does.