hapijs / hapijs/hapi

Add hook for when request.active() return false

Open
#4,222 0 comments 1 reaction 0 assignees View on GitHub
feature
Dominant language
JavaScript
Stars
14.8k
Forks
1.4k
Avg merge
22d 3h
Merged PRs (30d)
1

Description

#### Support plan

* *is this issue currently blocking your project?* (yes/no): no
* *is this issue affecting a production system?* (yes/no): no

#### Context

* *node version*: any
* *module version*: 20.0.3
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): standalone
* *any other relevant information*:

#### What problem are you trying to solve?

Hapi provides a `request.active()` method, which can be queried by handlers to know when to abort the processing.

However, this is only useful for passive checks. It cannot be used (without polling), if you have an abortable operation, most notably a `Http.request()`. Here a callback / deferred promise is needed, in order to trigger the abort of a pending upstream http request.

This is especially relevant with the upcoming more expanded `AbortController` support for cancelling pending promises.

#### Do you have a new or modified API suggestion to solve the problem?

I think the most appropriate integration would be as a new `request.events` event. There is already a `disconnect` event, which covers some of the cases, but it is not triggered in all cases where `request.active()` returns `false`. Eg. when a handler returns `h.close`.

Maybe `close`, to mirror normal streams terminology, where it means that nothing more will happen? Only `onPostRequest` hooks would potentially run after this.

Note that this is not fully covered by listening to `raw.res` `close` event, since it won't catch a handler that returns `h.abandon`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.