bare-http1 4.1.0 → 4.1.1
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-request.js +12 -7
- package/lib/server-response.js +14 -8
- package/package.json +1 -1
package/lib/client-request.js
CHANGED
|
@@ -35,6 +35,11 @@ module.exports = class HTTPClientRequest extends HTTPOutgoingMessage {
|
|
|
35
35
|
if (onresponse) this.once('response', onresponse)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
// For Node.js compatibility
|
|
39
|
+
abort() {
|
|
40
|
+
return this.destroy()
|
|
41
|
+
}
|
|
42
|
+
|
|
38
43
|
_header() {
|
|
39
44
|
let h = `${this.method} ${this.path} HTTP/1.1\r\n`
|
|
40
45
|
|
|
@@ -64,15 +69,15 @@ module.exports = class HTTPClientRequest extends HTTPOutgoingMessage {
|
|
|
64
69
|
if (this.headersSent === false) this.flushHeaders()
|
|
65
70
|
|
|
66
71
|
if (this._chunked) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
CHUNK_DELIMITER,
|
|
70
|
-
data,
|
|
71
|
-
CHUNK_DELIMITER
|
|
72
|
-
])
|
|
72
|
+
this.socket.write(Buffer.from(data.byteLength.toString(16)))
|
|
73
|
+
this.socket.write(CHUNK_DELIMITER)
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
|
|
76
|
+
let flushed = this.socket.write(data)
|
|
77
|
+
|
|
78
|
+
if (this._chunked) flushed = this.socket.write(CHUNK_DELIMITER)
|
|
79
|
+
|
|
80
|
+
if (flushed) cb(null)
|
|
76
81
|
else this._pendingWrite = cb
|
|
77
82
|
}
|
|
78
83
|
|
package/lib/server-response.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const HTTPOutgoingMessage = require('./outgoing-message')
|
|
2
2
|
const constants = require('./constants')
|
|
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 HTTPServerResponse extends HTTPOutgoingMessage {
|
|
5
8
|
constructor(socket, req, close) {
|
|
6
9
|
super(socket)
|
|
@@ -77,14 +80,15 @@ module.exports = class HTTPServerResponse extends HTTPOutgoingMessage {
|
|
|
77
80
|
if (this._onlyHeaders === true) return cb(null)
|
|
78
81
|
|
|
79
82
|
if (this._chunked) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
data,
|
|
83
|
-
Buffer.from('\r\n')
|
|
84
|
-
])
|
|
83
|
+
this.socket.write(Buffer.from(data.byteLength.toString(16)))
|
|
84
|
+
this.socket.write(CHUNK_DELIMITER)
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
let flushed = this.socket.write(data)
|
|
88
|
+
|
|
89
|
+
if (this._chunked) flushed = this.socket.write(CHUNK_DELIMITER)
|
|
90
|
+
|
|
91
|
+
if (flushed) cb(null)
|
|
88
92
|
else this._pendingWrite = cb
|
|
89
93
|
}
|
|
90
94
|
|
|
@@ -94,8 +98,10 @@ module.exports = class HTTPServerResponse extends HTTPOutgoingMessage {
|
|
|
94
98
|
this.flushHeaders()
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
if (this._chunked && this._onlyHeaders === false)
|
|
98
|
-
this.socket.write(
|
|
101
|
+
if (this._chunked && this._onlyHeaders === false) {
|
|
102
|
+
this.socket.write(CHUNK_TERMINATOR)
|
|
103
|
+
}
|
|
104
|
+
|
|
99
105
|
if (this._close) this.socket.end()
|
|
100
106
|
|
|
101
107
|
cb(null)
|