Skip to content

Commit eb63ffa

Browse files
authored
Merge pull request #747 from yizhao1998/fix-python-client-snippet-with-protocol
fix python.http-client generate code snippet using http
2 parents 8b5aeb4 + e5d420c commit eb63ffa

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

codegens/python-http.client/lib/python-httpclient.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ self = module.exports = {
140140
snippet += 'from codecs import encode\n';
141141
}
142142
snippet += '\n';
143-
snippet += `conn = http.client.HTTPSConnection("${sanitize(host)}"`;
143+
if (request.url.protocol === 'http') {
144+
snippet += `conn = http.client.HTTPConnection("${sanitize(host)}"`;
145+
}
146+
else {
147+
snippet += `conn = http.client.HTTPSConnection("${sanitize(host)}"`;
148+
}
144149
snippet += url.port ? `, ${request.url.port}` : '';
145150
snippet += options.requestTimeout !== 0 ? `, timeout = ${options.requestTimeout})\n` : ')\n';
146151

codegens/python-http.client/test/unit/converter.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,29 @@ describe('Python-http.client converter', function () {
336336
});
337337
});
338338

339+
it('should generate valid snippets when url uses http protocol', function () {
340+
var request = new sdk.Request({
341+
'method': 'GET',
342+
'header': [],
343+
'url': {
344+
'raw': 'http://localhost:3000',
345+
'protocol': 'http',
346+
'host': [
347+
'localhost'
348+
],
349+
'port': '3000'
350+
},
351+
'response': []
352+
});
353+
convert(request, {}, function (error, snippet) {
354+
if (error) {
355+
expect.fail(null, null, error);
356+
}
357+
expect(snippet).to.be.a('string');
358+
expect(snippet).to.include('conn = http.client.HTTPConnection("localhost", 3000)');
359+
});
360+
});
361+
339362
});
340363

341364
describe('parseBody function', function () {

0 commit comments

Comments
 (0)