@jsenv/server 12.3.2 → 12.3.3
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/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
// https://github.com/jamestalmage/stream-to-observable/blob/master/index.js
|
|
2
2
|
import { Readable } from "node:stream"
|
|
3
|
-
|
|
4
3
|
import { createObservable } from "./observable.js"
|
|
5
4
|
|
|
6
5
|
const readableStreamLifetimeInSeconds = 120
|
|
7
6
|
|
|
8
7
|
export const nodeStreamToObservable = (nodeStream) => {
|
|
9
8
|
const observable = createObservable(({ next, error, complete }) => {
|
|
9
|
+
if (nodeStream.isPaused()) {
|
|
10
|
+
nodeStream.resume()
|
|
11
|
+
} else if (nodeStream.complete) {
|
|
12
|
+
complete()
|
|
13
|
+
return null
|
|
14
|
+
}
|
|
10
15
|
const cleanup = () => {
|
|
11
16
|
nodeStream.removeListener("data", next)
|
|
12
17
|
nodeStream.removeListener("error", error)
|
|
@@ -14,13 +19,17 @@ export const nodeStreamToObservable = (nodeStream) => {
|
|
|
14
19
|
nodeStream.removeListener("close", cleanup)
|
|
15
20
|
nodeStream.destroy()
|
|
16
21
|
}
|
|
17
|
-
|
|
18
22
|
// should we do nodeStream.resume() in case the stream was paused ?
|
|
19
23
|
nodeStream.once("error", error)
|
|
20
|
-
nodeStream.on("data",
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
nodeStream.on("data", (data) => {
|
|
25
|
+
next(data)
|
|
26
|
+
})
|
|
27
|
+
nodeStream.once("close", () => {
|
|
28
|
+
cleanup()
|
|
29
|
+
})
|
|
30
|
+
nodeStream.once("end", () => {
|
|
31
|
+
complete()
|
|
32
|
+
})
|
|
24
33
|
return cleanup
|
|
25
34
|
})
|
|
26
35
|
|
package/src/startServer.js
CHANGED
|
@@ -230,6 +230,10 @@ export const startServer = async ({
|
|
|
230
230
|
})
|
|
231
231
|
|
|
232
232
|
const requestCallback = async (nodeRequest, nodeResponse) => {
|
|
233
|
+
// pause the stream to let a chance to "requestToResponse"
|
|
234
|
+
// to call "requestRequestBody". Without this the request body readable stream
|
|
235
|
+
// might be closed when we'll try to attach "data" and "end" listeners to it
|
|
236
|
+
nodeRequest.pause()
|
|
233
237
|
if (!nagle) {
|
|
234
238
|
nodeRequest.connection.setNoDelay(true)
|
|
235
239
|
}
|
|
@@ -309,7 +313,6 @@ export const startServer = async ({
|
|
|
309
313
|
|
|
310
314
|
visitRequestNodeToLog(rootRequestNode, 0)
|
|
311
315
|
}
|
|
312
|
-
|
|
313
316
|
nodeRequest.on("error", (error) => {
|
|
314
317
|
if (error.message === "aborted") {
|
|
315
318
|
addRequestLog(rootRequestNode, {
|
|
@@ -683,6 +686,7 @@ export const startServer = async ({
|
|
|
683
686
|
const responseProperties = await handleRequest(request, {
|
|
684
687
|
requestNode: rootRequestNode,
|
|
685
688
|
})
|
|
689
|
+
nodeRequest.resume()
|
|
686
690
|
if (receiveRequestOperation.signal.aborted) {
|
|
687
691
|
return
|
|
688
692
|
}
|