braid-http 0.1.5 → 0.1.7

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.
@@ -499,7 +499,10 @@ function parse_headers (input) {
499
499
  }
500
500
 
501
501
  // Content-range is of the form '<unit> <range>' e.g. 'json .index'
502
- var content_range_regex = /(\S+)( (.*))?/
502
+ function parse_content_range (range_string) {
503
+ var match = range_string.match(/(\S+)( (.*))?/)
504
+ return match && {unit: match[1], range: match[3] || ''}
505
+ }
503
506
  function parse_body (state) {
504
507
 
505
508
  // Parse Body Snapshot
@@ -520,7 +523,7 @@ function parse_body (state) {
520
523
 
521
524
  // If we have a content-range, then this is a patch
522
525
  if (state.headers['content-range']) {
523
- var match = state.headers['content-range'].match(content_range_regex)
526
+ var match = parse_content_range(state.headers['content-range'])
524
527
  if (!match)
525
528
  return {
526
529
  result: 'error',
@@ -528,8 +531,8 @@ function parse_body (state) {
528
531
  range: state.headers['content-range']
529
532
  }
530
533
  state.patches = [{
531
- unit: match[1],
532
- range: match[3],
534
+ unit: match.unit,
535
+ range: match.range,
533
536
  content: state.input.substring(0, content_length),
534
537
 
535
538
  // Question: Perhaps we should include headers here, like we do for
@@ -609,7 +612,7 @@ function parse_body (state) {
609
612
  return state
610
613
  }
611
614
 
612
- var match = last_patch.headers['content-range'].match(content_range_regex)
615
+ var match = parse_content_range(last_patch.headers['content-range'])
613
616
  if (!match)
614
617
  return {
615
618
  result: 'error',
@@ -617,8 +620,8 @@ function parse_body (state) {
617
620
  patch: last_patch, input: state.input
618
621
  }
619
622
 
620
- last_patch.unit = match[1]
621
- last_patch.range = match[3]
623
+ last_patch.unit = match.unit
624
+ last_patch.range = match.range
622
625
  last_patch.content = state.input.substr(0, content_length)
623
626
 
624
627
  // Consume the parsed input
@@ -170,11 +170,9 @@ function parse_patches (req, cb) {
170
170
  }
171
171
 
172
172
  function parse_content_range (range_string) {
173
- console.log('range string is', range_string)
174
173
  var match = range_string.match(/(\S+)( (.*))?/)
175
- console.log('##### match is', match)
176
174
  if (!match) throw 'Cannot parse Content-Range in ' + string
177
- var [unit, range] = [match[1], match[3]]
175
+ var [unit, range] = [match[1], match[3] || '']
178
176
  return [unit, range]
179
177
  }
180
178
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
6
  "test": "node test/server.js"