braid-http 1.3.77 → 1.3.78
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 +44 -3
- package/package.json +1 -1
package/braid-http-client.js
CHANGED
|
@@ -612,7 +612,7 @@ var subscription_parser = (cb) => ({
|
|
|
612
612
|
function parse_update (state) {
|
|
613
613
|
// If we don't have headers yet, let's try to parse some
|
|
614
614
|
if (!state.headers) {
|
|
615
|
-
var parsed = parse_headers(state.input)
|
|
615
|
+
var parsed = parse_headers(state.input, true)
|
|
616
616
|
|
|
617
617
|
// If header-parsing fails, send the error upstream
|
|
618
618
|
if (parsed.result === 'error')
|
|
@@ -636,13 +636,53 @@ function parse_update (state) {
|
|
|
636
636
|
}
|
|
637
637
|
|
|
638
638
|
// Parsing helpers
|
|
639
|
-
function parse_headers (input) {
|
|
639
|
+
function parse_headers (input, check_for_encoding_blocks) {
|
|
640
640
|
|
|
641
641
|
// Find the start of the headers
|
|
642
642
|
var start = 0
|
|
643
643
|
while (input[start] === 13 || input[start] === 10) start++
|
|
644
644
|
if (start === input.length) return {result: 'waiting'}
|
|
645
645
|
|
|
646
|
+
// Check for an "Encoding" block like this:
|
|
647
|
+
//
|
|
648
|
+
// Encoding: dt
|
|
649
|
+
// Length: 411813
|
|
650
|
+
// <binary dt file>
|
|
651
|
+
//
|
|
652
|
+
// Such a block will start with an "e", not an "h"
|
|
653
|
+
if (check_for_encoding_blocks &&
|
|
654
|
+
(input[start] === 101 || input[start] === 69)) {
|
|
655
|
+
|
|
656
|
+
// Look for two newlines
|
|
657
|
+
var end = start
|
|
658
|
+
var count = 0
|
|
659
|
+
while (++end) {
|
|
660
|
+
if (end > input.length) return {result: 'waiting'}
|
|
661
|
+
if (input[end - 1] === 10) count++
|
|
662
|
+
if (count === 2) break
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// Extract the header string
|
|
666
|
+
var headers_source = input.slice(start, end).map(x => String.fromCharCode(x)).join('')
|
|
667
|
+
|
|
668
|
+
// Parse
|
|
669
|
+
var m = headers_source.match(/Encoding:\s*(\w+)\r?\nLength:\s*(\d+)\r?\n/i)
|
|
670
|
+
if (!m) return {
|
|
671
|
+
result: 'error',
|
|
672
|
+
message: `Parse error in encoding block: ${JSON.stringify(headers_source)}`
|
|
673
|
+
}
|
|
674
|
+
var headers = {
|
|
675
|
+
encoding: m[1],
|
|
676
|
+
length: m[2]
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// Update the input
|
|
680
|
+
input = input.slice(end)
|
|
681
|
+
|
|
682
|
+
// And return the parsed result
|
|
683
|
+
return { result: 'success', headers, input }
|
|
684
|
+
}
|
|
685
|
+
|
|
646
686
|
// Look for the double-newline at the end of the headers.
|
|
647
687
|
var end = start
|
|
648
688
|
while (++end) {
|
|
@@ -714,7 +754,8 @@ function parse_body (state) {
|
|
|
714
754
|
|
|
715
755
|
// Parse Body Snapshot
|
|
716
756
|
|
|
717
|
-
var content_length = parseInt(state.headers['content-length']
|
|
757
|
+
var content_length = parseInt(state.headers['content-length'] ??
|
|
758
|
+
(state.headers.patches === undefined && state.headers['length']))
|
|
718
759
|
if (!isNaN(content_length)) {
|
|
719
760
|
|
|
720
761
|
// We've read a Content-Length, so we have a block to parse
|