Skip to content

Commit 3eb6873

Browse files
committed
fix: python prints proper utf8 string from bytes
fix: node prints proper utf8 string from buffer add: actual request testing with natively supported languages (no libraries)
1 parent b436a5d commit 3eb6873

36 files changed

Lines changed: 132 additions & 63 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"url": "https://github.com/Mashape/httpsnippet/issues"
2525
},
2626
"scripts": {
27-
"test": "standard && mocha --reporter spec",
27+
"test": "standard && mocha --bail --no-timeouts --reporter spec",
2828
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha",
2929
"prepush": "npm test"
3030
},

src/targets/node/native.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = function (source, options) {
2727
headers: source.allHeaders
2828
}
2929

30-
code.push('var http = require("http");')
30+
code.push(util.format('var http = require("%s");', source.uriObj.protocol.replace(':', '')))
3131

3232
if (!source.postData.text && source.postData.params) {
3333
code.push('var querystring = require("querystring");')
@@ -53,7 +53,7 @@ module.exports = function (source, options) {
5353

5454
code.push(opts.indent + 'res.on("end", function () {')
5555
code.push(opts.indent + opts.indent + 'var body = Buffer.concat(chunks);')
56-
code.push(opts.indent + opts.indent + 'console.log(body);')
56+
code.push(opts.indent + opts.indent + 'console.log(body.toString());')
5757
code.push(opts.indent + '});')
5858
code.push('});')
5959

src/targets/python/python3.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ module.exports = function (source, options) {
7070
// Get Response
7171
code.push('\nres = conn.getresponse()')
7272
code.push('data = res.read()')
73-
code.push('\nprint(res.status)')
74-
code.push('print(data)')
73+
code.push('print(data.decode("utf-8"))')
7574

7675
// console.log(code)
7776
return code.join('\n')

test/fixtures/cli.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[
2+
{
3+
"run": "node %s",
4+
"target":"node",
5+
"clients": [
6+
"native"
7+
]
8+
},
9+
10+
{
11+
"run": "php %s",
12+
"target": "php",
13+
"clients": [
14+
"curl"
15+
]
16+
},
17+
18+
{
19+
"run": "python3 %s",
20+
"target": "python",
21+
"clients": [
22+
"python3"
23+
]
24+
}
25+
]

test/fixtures/output/node/native/application-form-encoded.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var req = http.request(options, function (res) {
1919

2020
res.on("end", function () {
2121
var body = Buffer.concat(chunks);
22-
console.log(body);
22+
console.log(body.toString());
2323
});
2424
});
2525

test/fixtures/output/node/native/application-json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var req = http.request(options, function (res) {
1919

2020
res.on("end", function () {
2121
var body = Buffer.concat(chunks);
22-
console.log(body);
22+
console.log(body.toString());
2323
});
2424
});
2525

test/fixtures/output/node/native/cookies.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var req = http.request(options, function (res) {
1919

2020
res.on("end", function () {
2121
var body = Buffer.concat(chunks);
22-
console.log(body);
22+
console.log(body.toString());
2323
});
2424
});
2525

test/fixtures/output/node/native/custom-method.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var req = http.request(options, function (res) {
1717

1818
res.on("end", function () {
1919
var body = Buffer.concat(chunks);
20-
console.log(body);
20+
console.log(body.toString());
2121
});
2222
});
2323

test/fixtures/output/node/native/full.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var req = http.request(options, function (res) {
2121

2222
res.on("end", function () {
2323
var body = Buffer.concat(chunks);
24-
console.log(body);
24+
console.log(body.toString());
2525
});
2626
});
2727

test/fixtures/output/node/native/headers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var req = http.request(options, function (res) {
2020

2121
res.on("end", function () {
2222
var body = Buffer.concat(chunks);
23-
console.log(body);
23+
console.log(body.toString());
2424
});
2525
});
2626

0 commit comments

Comments
 (0)