nodules / asker

http.request wrapper with gzip, request retries and http.Agent tuning
MIT License
93 stars 11 forks source link

Added bodyEncoding option #66

Closed wayx closed 11 years ago

wayx commented 11 years ago

Added bodyEncoders (text, urlencoded, multipart, stringify default)

9

kaero commented 11 years ago

@webstalk3r thanks for good work!

kaero commented 11 years ago

@webstalk3r more about code style issues:

bad:

var headers = [],
    isObject = typeof body[name] === 'object',
    isFile = isObject && 'data' in body[name] && Buffer.isBuffer(body[name].data),
    isBuffer = isObject && Buffer.isBuffer(body[name]);
headers.push('--' + BOUNDARY);
var disposition = 'content-disposition: form-data; name="' + name + '"';
if (isFile || isBuffer) {
    disposition += '; filename="' + ( ! isBuffer && 'filename' in body[name] ?
        body[name].filename :
        name) + '"';
}
headers.push(disposition);

good:

var headers = [],
    attach = body[name],
    isFile = attach && Buffer.isBuffer(attach.data),
    isBuffer = attach && Buffer.isBuffer(attach),
    disposition = [
        'content-disposition: form-data; name="', name, '"'
    ];

headers.push('--' + BOUNDARY);

if (isFile || isBuffer) {
    disposition.push('; filename="'); 

    if (isFile && attach.filename) {
        disposition.push(body[name].filename);
    } else {
        disposition.push(name);
    }

    disposition.push('"');
}

headers.push(disposition.join(''));
Flackus commented 11 years ago

It's great. Codestyle issues are really could be done by maintainer ;) Good work, guys. One question, any becnhmarks due to the recent changes? :)

kaero commented 11 years ago

I'll add benchmarks for transition from 0.1 to 1.0.

0.2 will be released ASAP due to @webstalk3r needs.