braid-http 0.1.8 → 0.1.10

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.
@@ -357,7 +357,7 @@ var subscription_parser = (cb) => ({
357
357
  this.state.input += input
358
358
 
359
359
  // Now loop through the input and parse until we hit a dead end
360
- do {
360
+ while (this.state.input.trim() !== '') {
361
361
  this.state = parse_version (this.state)
362
362
 
363
363
  // Maybe we parsed a version! That's cool!
@@ -380,7 +380,8 @@ var subscription_parser = (cb) => ({
380
380
  }
381
381
 
382
382
  // We stop once we've run out of parseable input.
383
- } while (this.state.result !== 'waiting' && this.state.input.trim() !== '')
383
+ if (this.state.result == 'waiting') break
384
+ }
384
385
  }
385
386
  })
386
387
 
@@ -552,14 +553,14 @@ function parse_body (state) {
552
553
 
553
554
  // Parse Patches
554
555
 
555
- else if (state.headers.patches) {
556
+ else if (state.headers.patches != null) {
556
557
  state.patches = state.patches || []
557
558
 
558
559
  var last_patch = state.patches[state.patches.length-1]
559
560
 
560
561
  // Parse patches until the final patch has its content filled
561
562
  while (!(state.patches.length === state.headers.patches
562
- && 'content' in last_patch)) {
563
+ && (state.patches.length === 0 || 'content' in last_patch))) {
563
564
 
564
565
  state.input = state.input.trimStart()
565
566
 
@@ -43,9 +43,8 @@ function generate_patches(res, patches) {
43
43
  // Build up the string as a result
44
44
  var result = ''
45
45
 
46
- // Add `Patches: N` header if we have multiple patches
47
- if (patches.length > 1)
48
- result += `Patches: ${patches.length}\r\n\r\n`
46
+ // Add `Patches: N` header
47
+ result += `Patches: ${patches.length}\r\n\r\n`
49
48
 
50
49
  // Generate each patch
51
50
  patches.forEach((patch, i) => {
@@ -66,8 +65,17 @@ ${patch.content}`
66
65
  function parse_patches (req, cb) {
67
66
  var num_patches = req.headers.patches
68
67
 
69
- // Parse a single patch from the request body
70
- if (num_patches === undefined) {
68
+ // Parse a request body as an "everything" patch
69
+ if (!num_patches && !req.headers['content-range']) {
70
+ var body = ''
71
+ req.on('data', chunk => {body += chunk.toString()})
72
+ req.on('end', () => {
73
+ cb([{unit: 'everything', range: '', content: body}])
74
+ })
75
+ }
76
+
77
+ // Parse a single patch, lacking Patches: N
78
+ else if (num_patches === undefined && req.headers['content-range']) {
71
79
 
72
80
  // We only support range patches right now, so there must be a
73
81
  // Content-Range header.
@@ -231,6 +239,9 @@ function braidify (req, res, next) {
231
239
  res.setHeader('cache-control', 'no-cache, no-transform')
232
240
  res.setHeader('transfer-encoding', '')
233
241
 
242
+ // Tell nginx not to buffer the subscription
243
+ res.setHeader('X-Accel-Buffering', 'no')
244
+
234
245
  var connected = true
235
246
  function disconnected (x) {
236
247
  if (!connected) return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
6
  "test": "node test/server.js"