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

fails if you close the socket after writes? #240

Closed
tj opened this issue Jul 3, 2013 · 7 comments
Closed

fails if you close the socket after writes? #240

tj opened this issue Jul 3, 2013 · 7 comments

Comments

@tj
Copy link
Contributor

tj commented Jul 3, 2013

This almost seems like it might be a node buffering bug or something, but here's the test failing in 0.8.x and 0.11.x. If you remove res.end() it works fine, otherwise you get "Request aborted", but this used to pass just fine

app.get('/', function(req, res){
  res.set('Content-Type', 'multipart/form-data; boundary=awesome');
  // res.write('\r\n'); TODO: formidable bug
  res.write('--awesome\r\n');
  res.write('Content-Disposition: attachment; name="image"; filename="something.png"\r\n');
  res.write('Content-Type: image/png\r\n');
  res.write('\r\n');
  res.write('some data');
  res.write('\r\n--awesome\r\n');
  res.write('Content-Disposition: form-data; name="name"\r\n');
  res.write('Content-Type: text/plain\r\n');
  res.write('\r\n');
  res.write('tobi');
  res.write('\r\n--awesome--');
  res.end();
});

app.listen(3007);

describe('request multipart/form-data', function(){
  describe('req.body', function(){
    it('should be populated with fields', function(done){
      request.get('http://localhost:3007/', function(err, res){
        if (err) return done(err);
        res.status.should.equal(200);
        res.body.should.eql({ name: 'tobi' });
        res.files.image.name.should.equal('something.png');
        res.files.image.type.should.equal('image/png');
        assert(null == res.text, 'res.text should be empty for multipart');
        done();
      });
    })
  })
})
@tj
Copy link
Contributor Author

tj commented Jul 3, 2013

i'll see if i can reproduce with less library in the way

@tj tj closed this as completed Jul 3, 2013
@tj
Copy link
Contributor Author

tj commented Jul 3, 2013

ah looks like us disabling agent is what did the trick:

http.createServer(function(req, res){
  res.setHeader('Content-Type', 'multipart/form-data; boundary=awesome');
  res.write('\r\n');
  res.write('--awesome\r\n');
  res.write('Content-Disposition: attachment; name="image"; filename="something.png"\r\n');
  res.write('Content-Type: image/png\r\n');
  res.write('\r\n');
  res.write('some data');
  res.write('\r\n--awesome\r\n');
  res.write('Content-Disposition: form-data; name="name"\r\n');
  res.write('Content-Type: text/plain\r\n');
  res.write('\r\n');
  res.write('tobi');
  res.write('\r\n--awesome--');
  res.end();
}).listen(4000);

var url = require('url');
var opts = url.parse('http://localhost:4000');
opts.agent = false;

http
.get(opts)
.on('response', function(res){
  var form = new formidable.IncomingForm;

  form.parse(res, function(err, fields, files){
    if (err) throw err;
    console.log(fields);
    console.log(files);
  });
})

@tj tj reopened this Jul 3, 2013
@egirshov
Copy link
Contributor

egirshov commented Jul 3, 2013

Reducing this even more: got 'abort' (and later, 'end') from ClientResponse.

var http = require('http');
var server = http.createServer(function test1(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.write('aaa');
  res.end('bbb');
});
server.listen(4000);
http.get({port: 4000, agent: false}).on('response', function (res) {
  res.on('data', function () {
    res.pause();
    setTimeout(function () { res.resume(); }, 100);
  });
  res.on('aborted', function () {
    console.log('abort');
  });
  res.on('end', function () {
    console.log('end');
    server.close();
  });
});

@felixge
Copy link
Collaborator

felixge commented Jul 12, 2013

Sorry for being late to the party. Is the consensus that this is probably a formidable bug, rather than something in node's beautiful http client? : )

@egirshov
Copy link
Contributor

I don't think there is a formidable bug here, but weird http client response behavior. We could probably implement a workaround in formidable though.

@tj
Copy link
Contributor Author

tj commented Jul 12, 2013

seems like a node thing, I haven't had more time to look into it yet but I'll close for now to reduce noise until I can confirm!

@tj tj closed this as completed Jul 12, 2013
@felixge
Copy link
Collaborator

felixge commented Jul 15, 2013

@visionmedia ok - keep me posted. I'm happy to help if it's in formidable!

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