bare-http1 3.1.0 → 3.2.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/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # bare-http1
2
2
 
3
- Native HTTP/1 library for JavaScript.
3
+ HTTP/1 library for JavaScript.
4
4
 
5
5
  ```
6
6
  npm i bare-http1
7
7
  ```
8
8
 
9
- Only HTTP servers at the moment and current does NOT support server request bodies, but supports most other HTTP features (keep-alive, chunked encoding etc) and streaming server responses.
9
+ Only HTTP servers at the moment and currently does NOT support server request bodies, but supports most other HTTP features (keep-alive, chunked encoding, etc.) and streaming server responses.
10
10
 
11
11
  ## Usage
12
12
 
package/index.js CHANGED
@@ -7,6 +7,8 @@ exports.ServerConnection = require('./lib/server-connection')
7
7
 
8
8
  exports.constants = require('./lib/constants')
9
9
 
10
+ exports.STATUS_CODES = exports.constants.status // For Node.js compatibility
11
+
10
12
  exports.createServer = function createServer (opts, onrequest) {
11
13
  return new Server(opts, onrequest)
12
14
  }
package/lib/constants.js CHANGED
@@ -3,17 +3,20 @@ module.exports = {
3
3
  100: 'Continue',
4
4
  101: 'Switching Protocols',
5
5
  102: 'Processing',
6
+ 103: 'Early Hints',
6
7
  200: 'OK',
7
8
  201: 'Created',
8
9
  202: 'Accepted',
9
- 203: 'Non Authoritative Information',
10
+ 203: 'Non-Authoritative Information',
10
11
  204: 'No Content',
11
12
  205: 'Reset Content',
12
13
  206: 'Partial Content',
13
14
  207: 'Multi-Status',
15
+ 208: 'Already Reported',
16
+ 226: 'IM Used',
14
17
  300: 'Multiple Choices',
15
18
  301: 'Moved Permanently',
16
- 302: 'Moved Temporarily',
19
+ 302: 'Found',
17
20
  303: 'See Other',
18
21
  304: 'Not Modified',
19
22
  305: 'Use Proxy',
@@ -32,18 +35,18 @@ module.exports = {
32
35
  410: 'Gone',
33
36
  411: 'Length Required',
34
37
  412: 'Precondition Failed',
35
- 413: 'Request Entity Too Large',
36
- 414: 'Request-URI Too Long',
38
+ 413: 'Payload Too Large',
39
+ 414: 'URI Too Long',
37
40
  415: 'Unsupported Media Type',
38
- 416: 'Requested Range Not Satisfiable',
41
+ 416: 'Range Not Satisfiable',
39
42
  417: 'Expectation Failed',
40
- 418: 'I\'m a teapot',
41
- 419: 'Insufficient Space on Resource',
42
- 420: 'Method Failure',
43
+ 418: "I'm a Teapot",
43
44
  421: 'Misdirected Request',
44
45
  422: 'Unprocessable Entity',
45
46
  423: 'Locked',
46
47
  424: 'Failed Dependency',
48
+ 425: 'Too Early',
49
+ 426: 'Upgrade Required',
47
50
  428: 'Precondition Required',
48
51
  429: 'Too Many Requests',
49
52
  431: 'Request Header Fields Too Large',
@@ -54,7 +57,11 @@ module.exports = {
54
57
  503: 'Service Unavailable',
55
58
  504: 'Gateway Timeout',
56
59
  505: 'HTTP Version Not Supported',
60
+ 506: 'Variant Also Negotiates',
57
61
  507: 'Insufficient Storage',
62
+ 508: 'Loop Detected',
63
+ 509: 'Bandwidth Limit Exceeded',
64
+ 510: 'Not Extended',
58
65
  511: 'Network Authentication Required'
59
66
  }
60
67
  }
@@ -1,4 +1,4 @@
1
- const { Readable } = require('streamx')
1
+ const { Readable } = require('bare-stream')
2
2
 
3
3
  module.exports = class HTTPIncomingMessage extends Readable {
4
4
  constructor (socket, method, url, headers) {
@@ -12,6 +12,10 @@ module.exports = class HTTPIncomingMessage extends Readable {
12
12
  this.push(null)
13
13
  }
14
14
 
15
+ get httpVersion () {
16
+ return '1.1'
17
+ }
18
+
15
19
  getHeader (name) {
16
20
  return this.headers[name.toLowerCase()]
17
21
  }
@@ -20,6 +24,10 @@ module.exports = class HTTPIncomingMessage extends Readable {
20
24
  return { ...this.headers }
21
25
  }
22
26
 
27
+ hasHeader (name) {
28
+ return name.toLowerCase() in this.headers
29
+ }
30
+
23
31
  _predestroy () {
24
32
  this.socket.destroy()
25
33
  }
@@ -1,4 +1,4 @@
1
- const { Writable } = require('streamx')
1
+ const { Writable } = require('bare-stream')
2
2
  const constants = require('./constants')
3
3
 
4
4
  module.exports = class HTTPOutgoingMessage extends Writable {
@@ -20,6 +20,10 @@ module.exports = class HTTPOutgoingMessage extends Writable {
20
20
  return { ...this.headers }
21
21
  }
22
22
 
23
+ hasHeader (name) {
24
+ return name.toLowerCase() in this.headers
25
+ }
26
+
23
27
  setHeader (name, value) {
24
28
  this.headers[name.toLowerCase()] = value
25
29
  }
@@ -20,9 +20,9 @@ module.exports = class HTTPServerResponse extends HTTPOutgoingMessage {
20
20
  }
21
21
 
22
22
  writeHead (statusCode, statusMessage = null, headers = {}) {
23
- if (typeof statusMessage !== 'string') {
23
+ if (typeof statusMessage === 'object' && statusMessage !== null) {
24
24
  headers = statusMessage
25
- statusMessage = {}
25
+ statusMessage = null
26
26
  }
27
27
 
28
28
  this.statusCode = statusCode
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-http1",
3
- "version": "3.1.0",
3
+ "version": "3.2.1",
4
4
  "description": "Native HTTP/1 library for JavaScript",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -26,8 +26,8 @@
26
26
  "homepage": "https://github.com/holepunchto/bare-http1#readme",
27
27
  "dependencies": {
28
28
  "bare-events": "^2.0.0",
29
- "bare-tcp": "^1.1.2",
30
- "streamx": "^2.13.0"
29
+ "bare-stream": "^1.0.0",
30
+ "bare-tcp": "^1.1.2"
31
31
  },
32
32
  "devDependencies": {
33
33
  "bare-subprocess": "^2.0.0",