bare-http1 4.0.3 → 4.1.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/index.d.ts +1 -0
- package/index.js +1 -0
- package/lib/client-connection.js +9 -2
- package/lib/client-request.js +7 -3
- package/lib/server-connection.js +8 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -14,6 +14,7 @@ exports.ClientConnection = require('./lib/client-connection')
|
|
|
14
14
|
exports.constants = require('./lib/constants')
|
|
15
15
|
exports.errors = require('./lib/errors')
|
|
16
16
|
|
|
17
|
+
exports.METHODS = Object.values(exports.constants.method) // For Node.js compatibility
|
|
17
18
|
exports.STATUS_CODES = exports.constants.status // For Node.js compatibility
|
|
18
19
|
|
|
19
20
|
exports.createServer = function createServer(opts, onrequest) {
|
package/lib/client-connection.js
CHANGED
|
@@ -143,12 +143,13 @@ module.exports = class HTTPClientConnection {
|
|
|
143
143
|
if (r.length === 0) return this.socket.destroy()
|
|
144
144
|
|
|
145
145
|
const [, statusCode, ...statusMessage] = r[0].split(' ')
|
|
146
|
-
if (!statusCode || !statusMessage) return this.socket.destroy()
|
|
146
|
+
if (!statusCode || !statusMessage.length) return this.socket.destroy()
|
|
147
147
|
|
|
148
148
|
const headers = {}
|
|
149
149
|
|
|
150
150
|
for (let i = 1; i < r.length; i++) {
|
|
151
|
-
const [name, value] = r[i]
|
|
151
|
+
const [name, value] = splitHeader(r[i])
|
|
152
|
+
if (name === null) return this.socket.destroy()
|
|
152
153
|
headers[name.toLowerCase()] = value
|
|
153
154
|
}
|
|
154
155
|
|
|
@@ -262,3 +263,9 @@ module.exports = class HTTPClientConnection {
|
|
|
262
263
|
HTTPClientConnection._connections.delete(this.socket)
|
|
263
264
|
}
|
|
264
265
|
}
|
|
266
|
+
|
|
267
|
+
function splitHeader(s) {
|
|
268
|
+
const i = s.indexOf(': ')
|
|
269
|
+
if (i === -1) return [null, null]
|
|
270
|
+
return [s.slice(0, i), s.slice(i + 2)]
|
|
271
|
+
}
|
package/lib/client-request.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const HTTPAgent = require('./agent')
|
|
2
2
|
const HTTPOutgoingMessage = require('./outgoing-message')
|
|
3
3
|
|
|
4
|
+
const CHUNK_DELIMITER = Buffer.from('\r\n')
|
|
5
|
+
const CHUNK_TERMINATOR = Buffer.from('0\r\n\r\n')
|
|
6
|
+
|
|
4
7
|
module.exports = class HTTPClientRequest extends HTTPOutgoingMessage {
|
|
5
8
|
constructor(opts = {}, onresponse = null) {
|
|
6
9
|
if (typeof opts === 'function') {
|
|
@@ -62,9 +65,10 @@ module.exports = class HTTPClientRequest extends HTTPOutgoingMessage {
|
|
|
62
65
|
|
|
63
66
|
if (this._chunked) {
|
|
64
67
|
data = Buffer.concat([
|
|
65
|
-
Buffer.from(
|
|
68
|
+
Buffer.from(data.byteLength.toString(16)),
|
|
69
|
+
CHUNK_DELIMITER,
|
|
66
70
|
data,
|
|
67
|
-
|
|
71
|
+
CHUNK_DELIMITER
|
|
68
72
|
])
|
|
69
73
|
}
|
|
70
74
|
|
|
@@ -75,7 +79,7 @@ module.exports = class HTTPClientRequest extends HTTPOutgoingMessage {
|
|
|
75
79
|
_final(cb) {
|
|
76
80
|
if (this.headersSent === false) this.flushHeaders()
|
|
77
81
|
|
|
78
|
-
if (this._chunked) this.socket.write(
|
|
82
|
+
if (this._chunked) this.socket.write(CHUNK_TERMINATOR)
|
|
79
83
|
|
|
80
84
|
this._pendingFinal = cb
|
|
81
85
|
}
|
package/lib/server-connection.js
CHANGED
|
@@ -145,7 +145,8 @@ module.exports = class HTTPServerConnection {
|
|
|
145
145
|
const headers = {}
|
|
146
146
|
|
|
147
147
|
for (let i = 1; i < r.length; i++) {
|
|
148
|
-
const [name, value] = r[i]
|
|
148
|
+
const [name, value] = splitHeader(r[i])
|
|
149
|
+
if (name === null) return this.socket.destroy()
|
|
149
150
|
headers[name.toLowerCase()] = value
|
|
150
151
|
}
|
|
151
152
|
|
|
@@ -270,3 +271,9 @@ module.exports = class HTTPServerConnection {
|
|
|
270
271
|
}
|
|
271
272
|
|
|
272
273
|
function noop() {}
|
|
274
|
+
|
|
275
|
+
function splitHeader(s) {
|
|
276
|
+
const i = s.indexOf(': ')
|
|
277
|
+
if (i === -1) return [null, null]
|
|
278
|
+
return [s.slice(0, i), s.slice(i + 2)]
|
|
279
|
+
}
|