Skip to content

Instantly share code, notes, and snippets.

@uolter
Created July 16, 2020 08:38
Show Gist options
  • Save uolter/22a9b98e884f8dc73713496a52b1f31d to your computer and use it in GitHub Desktop.
Save uolter/22a9b98e884f8dc73713496a52b1f31d to your computer and use it in GitHub Desktop.
const https = require('https');
const fs = require('fs');
const hostname = 'Todo';
var outstanding_reqs = 0;
var got_continue = false;
function readTextFile() {
try {
var data = fs.readFileSync('./sample_5000.json', 'utf8');
} catch(e) {
console.log('Error:', e.stack);
}
return data;
}
var postData = readTextFile();
var req = https.request({
hostname: hostname,
method: 'POST',
port: 443,
headers: { 'Expect': '100-continue',
"Content-Type": "application/json",
"Content-Length": postData.length,
},
cert: fs.readFileSync("./certs/client.crt"),
key: fs.readFileSync("./certs/client.key"),
});
console.error('Client sending request...');
var body = '';
req.on('continue', function() {
console.error('Client got 100 Continue...');
got_continue = true;
req.end(postData);
});
var body = '';
req.on('response', function(res) {
res.setEncoding('utf8');
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
console.error('Got full response.');
console.error('Status code ' + res.statusCode)
// assert.equal(body, test_res_body, 'Response body doesn\'t match.');
// assert.ok('abcd' in res.headers, 'Response headers missing.');
outstanding_reqs--;
if (outstanding_reqs === 0) {
server.close();
process.exit();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment