Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / connect-timeout / README.md
1 # connect-timeout
2
3 [![NPM Version][npm-image]][npm-url]
4 [![NPM Downloads][downloads-image]][downloads-url]
5 [![Build Status][travis-image]][travis-url]
6 [![Test Coverage][coveralls-image]][coveralls-url]
7 [![Gratipay][gratipay-image]][gratipay-url]
8
9 Times out the request in `ms`, defaulting to `5000`.
10
11 ## Install
12
13 ```sh
14 $ npm install connect-timeout
15 ```
16
17 ## API
18
19 **NOTE** This module is not recommend as a "top-level" middleware (i.e.
20 `app.use(timeout('5s'))`) unless you take precautions to halt your own
21 middleware processing. See [as top-level middleware](#as-top-level-middleware)
22 for how to use as a top-level middleware.
23
24 ### timeout(time, [options])
25
26 Returns middleware that times out in `time` milliseconds. `time` can also
27 be a string accepted by the [ms](https://www.npmjs.org/package/ms#readme)
28 module. On timeout, `req` will emit `"timeout"`.
29
30 #### Options
31
32 The `timeout` function takes an optional `options` object that may contain
33 any of the following keys:
34
35 ##### respond
36
37 Controls if this module will "respond" in the form of forwarding an error.
38 If `true`, the timeout error is passed to `next()` so that you may customize
39 the response behavior. This error has a `.timeout` property as well as
40 `.status == 503`. This defaults to `true`.
41
42 ### req.clearTimeout()
43
44 Clears the timeout on the request. The timeout is completely removed and
45 will not fire for this request in the future.
46
47 ### req.timedout
48
49 `true` if timeout fired; `false` otherwise.
50
51 ## Examples
52
53 ### as top-level middleware
54
55 Because of the way middleware processing works, this once this module
56 passes the request to the next middleware (which it has to do in order
57 for you to do work), it can no longer stop the flow, so you must take
58 care to check if the request has timedout before you continue to act
59 on the request.
60
61 ```javascript
62 var express = require('express');
63 var timeout = require('connect-timeout');
64
65 // example of using this top-level; note the use of haltOnTimedout
66 // after every middleware; it will stop the request flow on a timeout
67 var app = express();
68 app.use(timeout('5s'));
69 app.use(bodyParser());
70 app.use(haltOnTimedout);
71 app.use(cookieParser());
72 app.use(haltOnTimedout);
73
74 // Add your routes here, etc.
75
76 function haltOnTimedout(req, res, next){
77   if (!req.timedout) next();
78 }
79
80 app.listen(3000);
81 ```
82
83 ### express 3.x
84
85 ```javascript
86 var express = require('express');
87 var bodyParser = require('body-parser');
88 var timeout = require('connect-timeout');
89
90 var app = express();
91 app.post('/save', timeout('5s'), bodyParser.json(), haltOnTimedout, function(req, res, next){
92   savePost(req.body, function(err, id){
93     if (err) return next(err);
94     if (req.timedout) return;
95     res.send('saved as id ' + id);
96   });
97 });
98
99 function haltOnTimedout(req, res, next){
100   if (!req.timedout) next();
101 }
102
103 function savePost(post, cb){
104   setTimeout(function(){
105     cb(null, ((Math.random()* 40000) >>> 0));
106   }, (Math.random()* 7000) >>> 0));
107 }
108
109 app.listen(3000);
110 ```
111
112 ### connect
113
114 ```javascript
115 var bodyParser = require('body-parser');
116 var connect = require('connect');
117 var timeout = require('connect-timeout');
118
119 var app = require('connect');
120 app.use('/save', timeout('5s'), bodyParser.json(), haltOnTimedout, function(req, res, next){
121   savePost(req.body, function(err, id){
122     if (err) return next(err);
123     if (req.timedout) return;
124     res.send('saved as id ' + id);
125   });
126 });
127
128 function haltOnTimedout(req, res, next){
129   if (!req.timedout) next();
130 }
131
132 function savePost(post, cb){
133   setTimeout(function(){
134     cb(null, ((Math.random()* 40000) >>> 0));
135   }, (Math.random()* 7000) >>> 0));
136 }
137
138 app.listen(3000);
139 ```
140
141 ## License
142
143 [MIT](LICENSE)
144
145 [npm-image]: https://img.shields.io/npm/v/connect-timeout.svg
146 [npm-url]: https://npmjs.org/package/connect-timeout
147 [travis-image]: https://img.shields.io/travis/expressjs/timeout/master.svg
148 [travis-url]: https://travis-ci.org/expressjs/timeout
149 [coveralls-image]: https://img.shields.io/coveralls/expressjs/timeout/master.svg
150 [coveralls-url]: https://coveralls.io/r/expressjs/timeout?branch=master
151 [downloads-image]: https://img.shields.io/npm/dm/connect-timeout.svg
152 [downloads-url]: https://npmjs.org/package/connect-timeout
153 [gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg
154 [gratipay-url]: https://www.gratipay.com/dougwilson/