braid-http 1.0.7 → 1.1.1

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.
@@ -315,7 +315,6 @@ async function braid_fetch (url, params = {}) {
315
315
  // streamed response.
316
316
  on_error(err)
317
317
  },
318
- !isTextContentType(res.headers.get('content-type')),
319
318
  (...args) => {
320
319
  on_heartbeat()
321
320
  params.onBytes?.(...args)
@@ -402,13 +401,13 @@ async function braid_fetch (url, params = {}) {
402
401
  }
403
402
 
404
403
  // Parse a stream of versions from the incoming bytes
405
- async function handle_fetch_stream (stream, cb, binary, on_bytes) {
404
+ async function handle_fetch_stream (stream, cb, on_bytes) {
406
405
  if (is_nodejs)
407
406
  stream = to_whatwg_stream(stream)
408
407
 
409
408
  // Set up a reader
410
409
  var reader = stream.getReader(),
411
- parser = subscription_parser(cb, binary)
410
+ parser = subscription_parser(cb)
412
411
 
413
412
  while (true) {
414
413
  var versions = []
@@ -442,7 +441,7 @@ async function handle_fetch_stream (stream, cb, binary, on_bytes) {
442
441
  // Braid-HTTP Subscription Parser
443
442
  // ****************************
444
443
 
445
- var subscription_parser = (cb, binary) => ({
444
+ var subscription_parser = (cb) => ({
446
445
  // A parser keeps some parse state
447
446
  state: {input: []},
448
447
 
@@ -462,9 +461,6 @@ var subscription_parser = (cb, binary) => ({
462
461
  // Try to parse an update
463
462
  try {
464
463
  this.state = parse_update (this.state)
465
-
466
- // Parse UTF-8 if it isn't binary
467
- if (!binary && this.state.body) this.state.body = (new TextDecoder('utf-8')).decode(this.state.body)
468
464
  } catch (e) {
469
465
  this.cb(null, e)
470
466
  return
@@ -483,6 +479,13 @@ var subscription_parser = (cb, binary) => ({
483
479
  }
484
480
  for (var k in update)
485
481
  if (update[k] === undefined) delete update[k]
482
+
483
+ Object.defineProperty(update, 'body_text', {
484
+ get: function () {
485
+ if (this.body != null) return new TextDecoder('utf-8').decode(this.body.buffer)
486
+ }
487
+ })
488
+
486
489
  this.cb(update)
487
490
 
488
491
  // Reset the parser for the next version!
@@ -808,29 +811,6 @@ function extractHeader(input) {
808
811
  };
809
812
  }
810
813
 
811
- function isTextContentType(contentType) {
812
- if (!contentType) return false
813
-
814
- contentType = contentType.toLowerCase().trim()
815
-
816
- // Check if it starts with "text/"
817
- if (contentType.startsWith("text/")) return true
818
-
819
- // Initialize the Map if it doesn't exist yet
820
- if (!isTextContentType.textApplicationTypes) {
821
- isTextContentType.textApplicationTypes = new Map([
822
- ["application/json", true],
823
- ["application/xml", true],
824
- ["application/javascript", true],
825
- ["application/ecmascript", true],
826
- ["application/x-www-form-urlencoded", true],
827
- ])
828
- }
829
-
830
- // Use the cached map of text-based application types
831
- return isTextContentType.textApplicationTypes.has(contentType)
832
- }
833
-
834
814
  // ****************************
835
815
  // Exports
836
816
  // ****************************
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "1.0.7",
3
+ "version": "1.1.1",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
6
  "test": "node test/server.js"