Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request.parse / this._parser not used for browser? #1053

Closed
benmosher opened this issue Aug 22, 2016 · 3 comments
Closed

Request.parse / this._parser not used for browser? #1053

benmosher opened this issue Aug 22, 2016 · 3 comments

Comments

@benmosher
Copy link

benmosher commented Aug 22, 2016

this._parser is set in request-base.js via parse method, but is only used in lib/node/index.js.

It seems like _parseBody in client.js should use it, but it doesn't.

Is this a bug? It appears that maybe this is similar to (or a continuation of) #805?

Also noteworthy and related: buffer(true|false) is not available in the browser.

@benmosher benmosher changed the title this._parser not used for browser? Request.parse / this._parser not used for browser? Aug 22, 2016
@kornelski
Copy link
Contributor

Neither buffering, nor response body parsing are available in the browser. These things are handled natively by XHR.

In Node parser is expected to listen to events on response stream, but in the browser we don't have a stream (we could #1033)

@benmosher
Copy link
Author

Ah, so makes sense that buffer(...) would be unavailable within browser.

It still seems like providing a parser via #parse should be used within _parseBody as an override for the global request.parse map?

Current code:

// lib/client.js:375
Response.prototype._parseBody = function(str){
  var parse = request.parse[this.type];
  if (!parse && isJSON(this.type)) {
    parse = request.parse['application/json'];
  }
  return parse && str && (str.length || str instanceof Object)
    ? parse(str)
    : null;
};

What I thought I'd find based on #parse docs:

// lib/client.js:375
Response.prototype._parseBody = function(str){
  var parse = this._parser || request.parse[this.type]; // only changed this line
  if (!parse && isJSON(this.type)) {
    parse = request.parse['application/json'];
  }
  return parse && str && (str.length || str instanceof Object)
    ? parse(str)
    : null;
};

@niftylettuce
Copy link
Collaborator

v5.0.0 was released and should fix this issue, see the updated docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants