Skip to content

Instantly share code, notes, and snippets.

@LoicMahieu
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save LoicMahieu/9813646 to your computer and use it in GitHub Desktop.

Select an option

Save LoicMahieu/9813646 to your computer and use it in GitHub Desktop.
{
"name": "bug_request",
"version": "0.0.0",
"description": "",
"main": "test.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"async": "^0.2.10",
"request": "^2.34.0",
"express": "^3.5.1"
}
}
# node -v
v0.11.10
PUT file = test.js
File length: 1123
ok
PUT file = images.jpg
File length: 12402
{ [Error: socket hang up] code: 'ECONNRESET' }
PUT file = Mario-icon.png
File length: 33318
{ [Error: socket hang up] code: 'ECONNRESET' }
PUT file = imgres.jpg
File length: 443
{ [Error: socket hang up] code: 'ECONNRESET' }
PUT file = igloo.jpg
File length: 17252
{ [Error: socket hang up] code: 'ECONNRESET' }
PUT file = tipi.jpg
File length: 143504
ok
PUT file = tente.jpg
File length: 18986
{ [Error: socket hang up] code: 'ECONNRESET' }
var files = [
__filename,
'images.jpg',
'Mario-icon.png',
'imgres.jpg',
'igloo.jpg',
'tipi.jpg',
'tente.jpg',
//'v3.14-rc8.tar.gz'
];
var async = require('async');
async.eachSeries(files, function (filePath, done) {
var express = require('express');
var app = express();
var server = require('http').createServer(app);
app.use(function (req, res) {
process.nextTick(function () {
res.send('ok');
})
})
server.listen(1337, function () {
var request = require('request');
var fs = require('fs');
var file = fs.readFileSync(filePath);
request.put({
url: "http://localhost:1337",
body: file.toString(),
headers: {
'content-length' : file.length
}
}, function (err, res) {
console.log('PUT file = ' + filePath);
console.log('File length: ' + file.length)
if (err) {
console.log(err);
} else {
console.log(res.body);
}
console.log('\n');
server.close();
done();
});
});
}, function (err) {
if (err) {
throw err;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment