braid-http 0.3.17 → 0.3.19
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/braid-http-client.js +3 -3
- package/braid-http-server.js +17 -5
- package/package.json +1 -1
package/braid-http-client.js
CHANGED
|
@@ -229,8 +229,8 @@ async function braid_fetch (url, params = {}) {
|
|
|
229
229
|
|
|
230
230
|
// Now we define the subscription function we just used:
|
|
231
231
|
function start_subscription (cb, error) {
|
|
232
|
-
if (!res.ok)
|
|
233
|
-
throw new Error('Request returned not ok', res)
|
|
232
|
+
if (!res.ok) {
|
|
233
|
+
throw new Error('Request returned not ok status:', res.status)
|
|
234
234
|
|
|
235
235
|
if (res.bodyUsed)
|
|
236
236
|
// TODO: check if this needs a return
|
|
@@ -362,7 +362,7 @@ var subscription_parser = (cb) => ({
|
|
|
362
362
|
read (input) {
|
|
363
363
|
|
|
364
364
|
// Store the new input!
|
|
365
|
-
this.state.input.push(
|
|
365
|
+
for (let x of input) this.state.input.push(x)
|
|
366
366
|
|
|
367
367
|
// Now loop through the input and parse until we hit a dead end
|
|
368
368
|
while (this.state.input.length) {
|
package/braid-http-server.js
CHANGED
|
@@ -123,7 +123,7 @@ function parse_update (req, cb) {
|
|
|
123
123
|
req.on('data', function parse (chunk) {
|
|
124
124
|
|
|
125
125
|
// Merge the latest chunk into our buffer
|
|
126
|
-
buffer.push(
|
|
126
|
+
for (let x of chunk) buffer.push(x)
|
|
127
127
|
|
|
128
128
|
while (patches.length < num_patches) {
|
|
129
129
|
let h = extractHeader(buffer)
|
|
@@ -236,10 +236,22 @@ function braidify (req, res, next) {
|
|
|
236
236
|
res.statusCode = 209
|
|
237
237
|
res.setHeader("subscribe", req.headers.subscribe)
|
|
238
238
|
res.setHeader('cache-control', 'no-cache, no-transform')
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
// Note: I used to explicitly disable transfer-encoding chunked
|
|
242
|
+
// here by setting the header to empty string. This is the only
|
|
243
|
+
// way I know to disable it in nodejs. We don't need chunked
|
|
244
|
+
// encoding in subscriptions, because chunked encoding is used to
|
|
245
|
+
// signal the end of a response, and subscriptions don't end. I
|
|
246
|
+
// disabled them to make responses cleaner. However, it turns out
|
|
247
|
+
// the Caddy proxy throws an error if it receives a response with
|
|
248
|
+
// transfer-encoding: set to the empty string. So I'm disabling
|
|
249
|
+
// it now.
|
|
250
|
+
|
|
251
|
+
// if (req.httpVersionMajor == 1) {
|
|
252
|
+
// // Explicitly disable transfer-encoding chunked for http 1
|
|
253
|
+
// res.setHeader('transfer-encoding', '')
|
|
254
|
+
// }
|
|
243
255
|
|
|
244
256
|
// Tell nginx not to buffer the subscription
|
|
245
257
|
res.setHeader('X-Accel-Buffering', 'no')
|