sprucehttp_sjs 1.0.11 → 1.0.12

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.
Files changed (3) hide show
  1. package/README.md +9 -0
  2. package/index.js +16 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -22,6 +22,7 @@ A module for responding to requests within SpruceHTTP in an SJS file.
22
22
  - [headerValue(name)](#headervaluename)
23
23
  - [body()](#body)
24
24
  - [bodyStream()](#bodystream)
25
+ - [getMTlsPeerCertificate()](#getmtlspeercertificate)
25
26
 
26
27
  ## Documentation:
27
28
  Importing the module:
@@ -245,4 +246,12 @@ Returns the request body as a ReadStream.
245
246
  ```js
246
247
  console.log(sjs.bodyStream().read(13).toString("utf8"));
247
248
  // Hello, world!
249
+ ```
250
+
251
+ ### ``getMTlsPeerCertificate()``:
252
+ Returns details about the mTLS peer's certificate, if present.
253
+
254
+ ```js
255
+ console.log(sjs.getMTlsPeerCertificate().subject.CN);
256
+ // sprucehttp.com
248
257
  ```
package/index.js CHANGED
@@ -57,6 +57,7 @@ module.exports = {
57
57
  * @param {string | Buffer} data The data to send.
58
58
  */
59
59
  writeDataAsync: function (data) {
60
+ // eslint-disable-next-line no-async-promise-executor
60
61
  return new Promise(async function (resolve) {
61
62
  // Send the data in 1 MiB chunks
62
63
  const chunkSize = 1024 * 1024;
@@ -208,5 +209,20 @@ module.exports = {
208
209
  retVal = fs.createReadStream(process.env.reqBody, options);
209
210
  }
210
211
  return retVal;
212
+ },
213
+
214
+ /**
215
+ * Returns details about the mTLS peer's certificate, if present.
216
+ *
217
+ * @returns {PeerCertificate}
218
+ */
219
+ getMTlsPeerCertificate: function() {
220
+ let retVal = undefined;
221
+ if (process.env.mTlsPeerCertificate) {
222
+ retVal = JSON.parse(process.env.mTlsPeerCertificate);
223
+ if (retVal.raw) retVal.raw = Buffer.from(retVal.raw, "base64");
224
+ if (retVal.pubkey) retVal.pubkey = Buffer.from(retVal.pubkey, "base64");
225
+ }
226
+ return retVal;
211
227
  }
212
228
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sprucehttp_sjs",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "A module for responding to requests within SpruceHTTP in an SJS file",
5
5
  "main": "index.js",
6
6
  "scripts": {