bare-http1 3.6.2 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client-connection.js +7 -0
- package/lib/client-request.js +1 -1
- package/lib/constants.js +11 -0
- package/lib/incoming-message.js +8 -0
- package/lib/outgoing-message.js +8 -0
- package/lib/server-connection.js +13 -0
- package/lib/server.js +14 -0
- package/package.json +2 -2
package/lib/client-connection.js
CHANGED
|
@@ -27,6 +27,7 @@ module.exports = class HTTPClientConnection {
|
|
|
27
27
|
this._onend = this._onend.bind(this)
|
|
28
28
|
this._ondata = this._ondata.bind(this)
|
|
29
29
|
this._ondrain = this._ondrain.bind(this)
|
|
30
|
+
this._ontimeout = this._ontimeout.bind(this)
|
|
30
31
|
|
|
31
32
|
socket
|
|
32
33
|
.on('error', this._onerror)
|
|
@@ -34,6 +35,7 @@ module.exports = class HTTPClientConnection {
|
|
|
34
35
|
.on('end', this._onend)
|
|
35
36
|
.on('data', this._ondata)
|
|
36
37
|
.on('drain', this._ondrain)
|
|
38
|
+
.on('timeout', this._ontimeout)
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
_onerror (err) {
|
|
@@ -185,6 +187,7 @@ module.exports = class HTTPClientConnection {
|
|
|
185
187
|
.off('end', this._onend)
|
|
186
188
|
.off('data', this._ondata)
|
|
187
189
|
.off('drain', this._ondrain)
|
|
190
|
+
.off('timeout', this._ontimeout)
|
|
188
191
|
|
|
189
192
|
const req = this.req
|
|
190
193
|
|
|
@@ -196,6 +199,10 @@ module.exports = class HTTPClientConnection {
|
|
|
196
199
|
this.socket.destroy()
|
|
197
200
|
}
|
|
198
201
|
|
|
202
|
+
_ontimeout () {
|
|
203
|
+
if (this.req) this.req.emit('timeout')
|
|
204
|
+
}
|
|
205
|
+
|
|
199
206
|
_onfinished () {
|
|
200
207
|
if (this.res) this.res.push(null)
|
|
201
208
|
if (this.req) this.req._continueFinal()
|
package/lib/client-request.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = class HTTPClientRequest extends HTTPOutgoingMessage {
|
|
|
30
30
|
this.headers = { host: host + ':' + port, ...opts.headers }
|
|
31
31
|
|
|
32
32
|
this._connection = connection
|
|
33
|
-
this._chunked =
|
|
33
|
+
this._chunked = method !== 'GET' && method !== 'HEAD'
|
|
34
34
|
|
|
35
35
|
this._pendingFinal = null
|
|
36
36
|
|
package/lib/constants.js
CHANGED
|
@@ -6,6 +6,17 @@ module.exports = {
|
|
|
6
6
|
BEFORE_CHUNK: 4,
|
|
7
7
|
IN_CHUNK: 5
|
|
8
8
|
},
|
|
9
|
+
method: {
|
|
10
|
+
GET: 'GET',
|
|
11
|
+
HEAD: 'HEAD',
|
|
12
|
+
POST: 'POST',
|
|
13
|
+
PUT: 'PUT',
|
|
14
|
+
DELETE: 'DELETE',
|
|
15
|
+
CONNECT: 'CONNECT',
|
|
16
|
+
OPTIONS: 'OPTIONS',
|
|
17
|
+
TRACE: 'TRACE',
|
|
18
|
+
PATCH: 'PATCH'
|
|
19
|
+
},
|
|
9
20
|
status: {
|
|
10
21
|
100: 'Continue',
|
|
11
22
|
101: 'Switching Protocols',
|
package/lib/incoming-message.js
CHANGED
|
@@ -33,6 +33,14 @@ module.exports = class HTTPIncomingMessage extends Readable {
|
|
|
33
33
|
return name.toLowerCase() in this.headers
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
setTimeout (ms, ontimeout) {
|
|
37
|
+
if (ontimeout) this.once('timeout', ontimeout)
|
|
38
|
+
|
|
39
|
+
this.socket.setTimeout(ms)
|
|
40
|
+
|
|
41
|
+
return this
|
|
42
|
+
}
|
|
43
|
+
|
|
36
44
|
_predestroy () {
|
|
37
45
|
if (this.upgrade === false && this.socket !== null) this.socket.destroy()
|
|
38
46
|
}
|
package/lib/outgoing-message.js
CHANGED
|
@@ -34,6 +34,14 @@ module.exports = class HTTPOutgoingMessage extends Writable {
|
|
|
34
34
|
this.headersSent = true
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
setTimeout (ms, ontimeout) {
|
|
38
|
+
if (ontimeout) this.once('timeout', ontimeout)
|
|
39
|
+
|
|
40
|
+
this.socket.setTimeout(ms)
|
|
41
|
+
|
|
42
|
+
return this
|
|
43
|
+
}
|
|
44
|
+
|
|
37
45
|
_header () {
|
|
38
46
|
throw errors.NOT_IMPLEMENTED()
|
|
39
47
|
}
|
package/lib/server-connection.js
CHANGED
|
@@ -28,11 +28,15 @@ module.exports = class HTTPServerConnection {
|
|
|
28
28
|
this._onerror = this._onerror.bind(this)
|
|
29
29
|
this._ondata = this._ondata.bind(this)
|
|
30
30
|
this._ondrain = this._ondrain.bind(this)
|
|
31
|
+
this._ontimeout = this._ontimeout.bind(this)
|
|
31
32
|
|
|
32
33
|
socket
|
|
33
34
|
.on('error', this._onerror)
|
|
34
35
|
.on('data', this._ondata)
|
|
35
36
|
.on('drain', this._ondrain)
|
|
37
|
+
.on('timeout', this._ontimeout)
|
|
38
|
+
|
|
39
|
+
if (this.server.timeout) socket.setTimeout(this.server.timeout)
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
_onerror (err) {
|
|
@@ -176,6 +180,7 @@ module.exports = class HTTPServerConnection {
|
|
|
176
180
|
.off('error', this._onerror)
|
|
177
181
|
.off('data', this._ondata)
|
|
178
182
|
.off('drain', this._ondrain)
|
|
183
|
+
.off('timeout', this._ontimeout)
|
|
179
184
|
|
|
180
185
|
const req = this.req
|
|
181
186
|
|
|
@@ -185,6 +190,14 @@ module.exports = class HTTPServerConnection {
|
|
|
185
190
|
this.server.emit('upgrade', req, this.socket, head || empty)
|
|
186
191
|
}
|
|
187
192
|
|
|
193
|
+
_ontimeout () {
|
|
194
|
+
const reqTimeout = this.req && this.req.emit('timeout')
|
|
195
|
+
const resTimeout = this.res && this.res.emit('timeout')
|
|
196
|
+
const serverTimeout = this.server.emit('timeout', this.socket)
|
|
197
|
+
|
|
198
|
+
if (!reqTimeout && !resTimeout && !serverTimeout) this.socket.destroy()
|
|
199
|
+
}
|
|
200
|
+
|
|
188
201
|
_onfinished () {
|
|
189
202
|
if (this.req) this.req.push(null)
|
|
190
203
|
}
|
package/lib/server.js
CHANGED
|
@@ -10,8 +10,22 @@ module.exports = class HTTPServer extends TCPServer {
|
|
|
10
10
|
|
|
11
11
|
super({ allowHalfOpen: false })
|
|
12
12
|
|
|
13
|
+
this._timeout = 0
|
|
14
|
+
|
|
13
15
|
this.on('connection', (socket) => new HTTPServerConnection(this, socket, opts))
|
|
14
16
|
|
|
15
17
|
if (onrequest) this.on('request', onrequest)
|
|
16
18
|
}
|
|
19
|
+
|
|
20
|
+
get timeout () {
|
|
21
|
+
return this._timeout || undefined // For Node.js compatibility
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
setTimeout (ms = 0, ontimeout) {
|
|
25
|
+
if (ontimeout) this.on('timeout', ontimeout)
|
|
26
|
+
|
|
27
|
+
this._timeout = ms
|
|
28
|
+
|
|
29
|
+
return this
|
|
30
|
+
}
|
|
17
31
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-http1",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "Native HTTP/1 library for JavaScript",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"bare-events": "^2.0.0",
|
|
29
29
|
"bare-stream": "^2.0.0",
|
|
30
|
-
"bare-tcp": "^1.
|
|
30
|
+
"bare-tcp": "^1.8.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"brittle": "^3.3.0",
|