demo___customer_pitch-c4152739-a50b-4b5b-9d4d-0561461666d9.zip-extract/_dependencies/npm/on-finished-2.4.1/README.md

Path
demo___customer_pitch-c4152739-a50b-4b5b-9d4d-0561461666d9.zip-extract/_dependencies/npm/on-finished-2.4.1/README.md
Status
scanned
Type
file
Name
README.md
Extension
.md
Programming language

      
    
Mime type
text/plain
File type
exported SGML document, ASCII text
Tag

      
    
Rootfs path

      
    
Size
5160 (5.0 KB)
MD5
562d5d7422331487f93e06407128aa82
SHA1
f5063ba874f2e3b282fe87921df945ef0358d616
SHA256
b52e3f3a4ce4fa24c28fe59ccc08b5f4866eb5dd57943718a4a914f35901aa89
SHA512

      
    
SHA1_git
8973cded6589a6cc5a9e1718e3fb0d709fe6e8d8
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
README.md | 5.0 KB |

# on-finished [![NPM Version][npm-version-image]][npm-url] [![NPM Downloads][npm-downloads-image]][npm-url] [![Node.js Version][node-image]][node-url] [![Build Status][ci-image]][ci-url] [![Coverage Status][coveralls-image]][coveralls-url] Execute a callback when a HTTP request closes, finishes, or errors. ## Install This is a [Node.js](https://nodejs.org/en/) module available through the [npm registry](https://www.npmjs.com/). Installation is done using the [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): ```sh $ npm install on-finished ``` ## API ```js var onFinished = require('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)`. <!-- eslint-disable handle-callback-err --> ```js onFinished(res, function (err, res) { // clean up open fds, etc. // err contains the error if request error'd }) ``` ### 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)`. <!-- eslint-disable handle-callback-err --> ```js var data = '' req.setEncoding('utf8') req.on('data', function (str) { data += str }) onFinished(req, function (err, req) { // data is read unless there is err }) ``` ### 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 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 one. ## Example The following code ensures that file descriptors are always closed once the response finishes. ```js var destroy = require('destroy') var fs = require('fs') var http = require('http') var onFinished = require('on-finished') http.createServer(function onRequest (req, res) { var stream = fs.createReadStream('package.json') stream.pipe(res) onFinished(res, function () { destroy(stream) }) }) ``` ## License [MIT](LICENSE) [ci-image]: https://badgen.net/github/checks/jshttp/on-finished/master?label=ci [ci-url]: https://github.com/jshttp/on-finished/actions/workflows/ci.yml [coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/on-finished/master [coveralls-url]: https://coveralls.io/r/jshttp/on-finished?branch=master [node-image]: https://badgen.net/npm/node/on-finished [node-url]: https://nodejs.org/en/download [npm-downloads-image]: https://badgen.net/npm/dm/on-finished [npm-url]: https://npmjs.org/package/on-finished [npm-version-image]: https://badgen.net/npm/v/on-finished
Detected license expression
mit
Detected license expression (SPDX)
MIT
Percentage of license text
0.38
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
mit-bdcba66f-6e80-f7bd-7994-748183fe5693 mit MIT
URL Start line End line
https://nodejs.org/en 13 13
https://www.npmjs.com/ 14 14
https://docs.npmjs.com/getting-started/installing-npm-packages-locally 15 15
https://badgen.net/github/checks/jshttp/on-finished/master?label=ci 154 154
https://github.com/jshttp/on-finished/actions/workflows/ci.yml 155 155
https://badgen.net/coveralls/c/github/jshttp/on-finished/master 156 156
https://coveralls.io/r/jshttp/on-finished?branch=master 157 157
https://badgen.net/npm/node/on-finished 158 158
https://nodejs.org/en/download 159 159
https://badgen.net/npm/dm/on-finished 160 160
https://npmjs.org/package/on-finished 161 161
https://badgen.net/npm/v/on-finished 162 162
Package URL License Primary language
pkg:npm/acme-demo-app@1.0.0 JavaScript
pkg:npm/on-finished@2.4.1 mit JavaScript