Installations
npm install xprezzo-on-finished
Releases
Unable to fetch releases
Developer
xprezzo
Developer Guide
Module System
Unable to determine the module system for this package.
Min. Node Version
>= 0.8
Typescript Support
No
Node Version
16.14.2
NPM Version
8.5.0
Statistics
3 Stars
4 Commits
1 Watching
1 Branches
2 Contributors
Updated on 22 May 2022
Bundle Size
1.99 kB
Minified
989.00 B
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
2,618
Last day
0%
1
Compared to previous day
Last week
-99.7%
3
Compared to previous week
Last month
1,261.5%
885
Compared to previous month
Last year
330.8%
1,370
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
xprezzo-on-finished
Execute a callback when a HTTP request closes, finishes, or errors for xprezzo.
Install
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
1$ npm install xprezzo-on-finished
API
1var onFinished = require('xprezzo-on-finished')
onFinished(res, listener)
Attach a listener to listen for the response to finish. The listener will be invoked only once when the response finished. If the response finished to an error, the first argument will contain the error. If the response has already finished, the listener will be invoked.
Listening to the end of a response would be used to close things associated with the response, like open files.
Listener is invoked as listener(err, res)
.
1onFinished(res, function (err, res) {
2 // clean up open fds, etc.
3 // err contains the error if request error'd
4})
onFinished(req, listener)
Attach a listener to listen for the request to finish. The listener will be invoked only once when the request finished. If the request finished to an error, the first argument will contain the error. If the request has already finished, the listener will be invoked.
Listening to the end of a request would be used to know when to continue after reading the data.
Listener is invoked as listener(err, req)
.
1var data = '' 2 3req.setEncoding('utf8') 4req.on('data', function (str) { 5 data += str 6}) 7 8onFinished(req, function (err, req) { 9 // data is read unless there is err 10})
onFinished.isFinished(res)
Determine if res
is already finished. This would be useful to check and
not even start certain operations if the response has already finished.
onFinished.isFinished(req)
Determine if req
is already finished. This would be useful to check and
not even start certain operations if the request has already finished.
Special Node.js requests
HTTP CONNECT method
The meaning of the CONNECT
method from RFC 7231, section 4.3.6:
The CONNECT method requests that the recipient establish a tunnel to the destination origin server identified by the request-target and, if successful, thereafter restrict its behavior to blind forwarding of packets, in both directions, until the tunnel is closed. Tunnels are commonly used to create an end-to-end virtual connection, through one or more proxies, which can then be secured using TLS (Transport Layer Security, [RFC5246]).
In Node.js, these request objects come from the 'connect'
event on
the HTTP server.
When this module is used on a HTTP CONNECT
request, the request is
considered "finished" immediately, due to limitations in the Node.js
interface. This means if the CONNECT
request contains a request entity,
the request will be considered "finished" even before it has been read.
There is no such thing as a response object to a CONNECT
request in
Node.js, so there is no support for for one.
HTTP Upgrade request
The meaning of the Upgrade
header from RFC 7230, section 6.1:
The "Upgrade" header field is intended to provide a simple mechanism for transitioning from HTTP/1.1 to some other protocol on the same connection.
In Node.js, these request objects come from the 'upgrade'
event on
the HTTP server.
When this module is used on a HTTP request with an Upgrade
header, the
request is considered "finished" immediately, due to limitations in the
Node.js interface. This means if the Upgrade
request contains a request
entity, the request will be considered "finished" even before it has been
read.
There is no such thing as a response object to a Upgrade
request in
Node.js, so there is no support for for one.
Example
The following code ensures that file descriptors are always closed once the response finishes.
1var destroy = require('destroy') 2var fs = require('fs') 3var http = require('http') 4var onFinished = require('xprezzo-on-finished') 5 6http.createServer(function onRequest (req, res) { 7 var stream = fs.createReadStream('package.json') 8 stream.pipe(res) 9 onFinished(res, function () { 10 destroy(stream) 11 }) 12})
People
Xprezzo and related projects are maintained by Cloudgen Wong.
License
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
7 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-w5p7-h5w8-2hfq
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
Found 0/4 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
2.1
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More