Skip to content

Commit

Permalink
Merge pull request #747 from yizhao1998/fix-python-client-snippet-wit…
Browse files Browse the repository at this point in the history
…h-protocol

fix python.http-client generate code snippet using http
  • Loading branch information
VShingala authored Sep 11, 2024
2 parents 8b5aeb4 + e5d420c commit eb63ffa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion codegens/python-http.client/lib/python-httpclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ self = module.exports = {
snippet += 'from codecs import encode\n';
}
snippet += '\n';
snippet += `conn = http.client.HTTPSConnection("${sanitize(host)}"`;
if (request.url.protocol === 'http') {
snippet += `conn = http.client.HTTPConnection("${sanitize(host)}"`;
}
else {
snippet += `conn = http.client.HTTPSConnection("${sanitize(host)}"`;
}
snippet += url.port ? `, ${request.url.port}` : '';
snippet += options.requestTimeout !== 0 ? `, timeout = ${options.requestTimeout})\n` : ')\n';

Expand Down
23 changes: 23 additions & 0 deletions codegens/python-http.client/test/unit/converter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,29 @@ describe('Python-http.client converter', function () {
});
});

it('should generate valid snippets when url uses http protocol', function () {
var request = new sdk.Request({
'method': 'GET',
'header': [],
'url': {
'raw': 'http://localhost:3000',
'protocol': 'http',
'host': [
'localhost'
],
'port': '3000'
},
'response': []
});
convert(request, {}, function (error, snippet) {
if (error) {
expect.fail(null, null, error);
}
expect(snippet).to.be.a('string');
expect(snippet).to.include('conn = http.client.HTTPConnection("localhost", 3000)');
});
});

});

describe('parseBody function', function () {
Expand Down

0 comments on commit eb63ffa

Please sign in to comment.