bare-http1 4.0.4 → 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 CHANGED
@@ -24,6 +24,7 @@ export {
24
24
  HTTPError as errors
25
25
  }
26
26
 
27
+ export const METHODS: HTTPMethod[]
27
28
  export const STATUS_CODES: typeof constants.status
28
29
 
29
30
  export interface HTTPIncomingMessageEvents extends ReadableEvents {
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) {
@@ -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('' + data.byteLength.toString(16) + '\r\n'),
68
+ Buffer.from(data.byteLength.toString(16)),
69
+ CHUNK_DELIMITER,
66
70
  data,
67
- Buffer.from('\r\n')
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(Buffer.from('0\r\n\r\n'))
82
+ if (this._chunked) this.socket.write(CHUNK_TERMINATOR)
79
83
 
80
84
  this._pendingFinal = cb
81
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-http1",
3
- "version": "4.0.4",
3
+ "version": "4.1.0",
4
4
  "description": "Native HTTP/1 library for JavaScript",
5
5
  "exports": {
6
6
  "./package": "./package.json",