Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix python.http-client generate code snippet using http #747

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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