sprucehttp_sjs 1.0.10 → 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.
- package/README.md +9 -0
- package/index.js +37 -7
- package/package.json +2 -5
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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// This is still CommonJS to support both the old and new versions of the module system.
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/no-
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
|
|
5
5
|
module.exports = {
|
|
@@ -57,11 +57,26 @@ module.exports = {
|
|
|
57
57
|
* @param {string | Buffer} data The data to send.
|
|
58
58
|
*/
|
|
59
59
|
writeDataAsync: function (data) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
61
|
+
return new Promise(async function (resolve) {
|
|
62
|
+
// Send the data in 1 MiB chunks
|
|
63
|
+
const chunkSize = 1024 * 1024;
|
|
64
|
+
// Split the data into chunks
|
|
65
|
+
let chunks = [];
|
|
66
|
+
const data2 = Buffer.from(data);
|
|
67
|
+
for (let i = 0; i < data2.length; i += chunkSize) {
|
|
68
|
+
chunks.push(data2.subarray(i, i + chunkSize));
|
|
69
|
+
}
|
|
70
|
+
// Send all chunks
|
|
71
|
+
for (const chunk of chunks) {
|
|
72
|
+
await new Promise(function (resolve2) {
|
|
73
|
+
process.send({
|
|
74
|
+
type: "data",
|
|
75
|
+
data: chunk
|
|
76
|
+
}, resolve2);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
resolve();
|
|
65
80
|
});
|
|
66
81
|
},
|
|
67
82
|
|
|
@@ -185,7 +200,7 @@ module.exports = {
|
|
|
185
200
|
/**
|
|
186
201
|
* Returns the body of the request as an fs.ReadStream.
|
|
187
202
|
*
|
|
188
|
-
* @param {
|
|
203
|
+
* @param {BufferEncoding | ReadStreamOptions} [options] The options to pass to fs.createReadStream.
|
|
189
204
|
* @returns {fs.ReadStream} A ReadStream of the body of the request.
|
|
190
205
|
*/
|
|
191
206
|
bodyStream: function (options) {
|
|
@@ -194,5 +209,20 @@ module.exports = {
|
|
|
194
209
|
retVal = fs.createReadStream(process.env.reqBody, options);
|
|
195
210
|
}
|
|
196
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;
|
|
197
227
|
}
|
|
198
228
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sprucehttp_sjs",
|
|
3
|
-
"version": "1.0.
|
|
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": {
|
|
@@ -23,8 +23,5 @@
|
|
|
23
23
|
"email": "herronjo@stibarc.dev",
|
|
24
24
|
"url": "https://stibarc.dev"
|
|
25
25
|
},
|
|
26
|
-
"license": "Copyright (c) STiBaRC LLC. All rights reserved."
|
|
27
|
-
"dependencies": {
|
|
28
|
-
"sprucehttp_sjs": "file:"
|
|
29
|
-
}
|
|
26
|
+
"license": "Copyright (c) STiBaRC LLC. All rights reserved."
|
|
30
27
|
}
|