coolaj86 / formaline

formaline is a module for handling form requests ( HTTP POSTs / PUTs ) and for fast parsing of file uploads.
Apache License 2.0
239 stars 16 forks source link

"checkContentLength" setting doesn't work #23

Closed diversario closed 13 years ago

diversario commented 13 years ago

With this code:

var http = require('http'),
    UPLOAD_LIMIT = 10000,
    flconf = {"uploadRootDir": '/tmp/', "requestTimeOut": 600000, "resumeRequestOnError": false, "maxFileSize": UPLOAD_LIMIT, "checkContentLength": true, "holdFilesExtensions": true, "removeIncompleteFiles": true, "logging": 'debug:off,1:on,2:off,3:off,4:off,console:on,file:off,record:off'},
    formaline = require('formaline');

http.createServer(function(req, res){
  if (req.method == 'POST'){
    var form = new formaline(flconf);
    var myListener = function( ){ console.log( arguments )};

    form.on( 'load', myListener );

    form.on( 'loadend', function(json, res, cb){
      console.log('loadend');
      cb(json);
    });

    form.parse(req, res, function(json){
      console.log('parsed', json);
      res.end();
    });
  }
}).listen(80);

app loads entire file (tested with files up to 5 MB in size) and then removes it with "upload threshold exceed" and fileremoved messages. Files less than UPLOAD_LIMIT are saved.

Request headers include "content-length" header.

rootslab commented 13 years ago

Hi @shaisultanov!

Probably the docs are not so clear about this, the behaviour is correct, the checkContentLength switch is related to uploadThreshold and not to maxFileSize; you have not set uploadThreshold in your example, then files are received.

When checkContentLength is true, formaline checks if total length of request overflows uploadThreshold , if so the request is stopped before any files were uploaded.

If it is setted to false, means that formaline ignores the content-length header ( because this header generally could be intentionally faked ) and checks only uploadThreshold .