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

POST results in "TypeError: Cannot read property 'lengthComputable' of undefined" #40

Closed
taku0 opened this issue Apr 27, 2016 · 2 comments
Labels
bug Something isn't working

Comments

@taku0
Copy link

taku0 commented Apr 27, 2016

Summary

POST with body results in "TypeError: Cannot read property 'lengthComputable' of undefined" because XMLHttpRequestUpload doesn't have _properties.

Sample Code

const http = require('http');
const XMLHttpRequest = require('w3c-xmlhttprequest').XMLHttpRequest;

const server = http.createServer((req, res) => {
  res.end();
});
server.on('clientError', (err, socket) => {
  socket.end('HTTP/1.1 400 Bad Request\r\n\r\n');
});
server.listen(8000);

const client = new XMLHttpRequest();

client.open("POST", "http://localhost:8000");
client.send("abcdefg");

Result

~/src/node-xmlhttprequest/lib/xmlhttprequest.js:129
      lengthComputable: _properties.lengthComputable,
                                   ^

TypeError: Cannot read property 'lengthComputable' of undefined
    at Socket.<anonymous> (/home/takuo/src/node-xmlhttprequest/lib/xmlhttprequest.js:129:36)
    at emitOne (events.js:82:20)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:146:16)
    at Socket.Readable.push (_stream_readable.js:110:10)
    at TCP.onread (net.js:523:20)

Version

2.1.0 and master (383319c)

Cause

_setDispatchProgressEvents read this._properties while this is bound to XMLHttpRequest#upload which doesn't have _properties.

function _setDispatchProgressEvents(stream) {
  const _properties = this._properties;
      client.on('socket', _setDispatchProgressEvents.bind(this.upload));

Possible Fix

Defining _properties on XMLHttpRequestUpload.

@ykzts ykzts added the bug Something isn't working label Nov 2, 2016
@sibelius
Copy link

@ykzts @taku0 I can confirm this

any progress on this?

@ykzts ykzts closed this as completed in 7d2fa85 Nov 13, 2016
ykzts added a commit that referenced this issue Nov 13, 2016
@ykzts
Copy link
Owner

ykzts commented Nov 13, 2016

@taku0 @sibelius

I think that it might have been fixed.

v2.1.2 released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants