File tree Expand file tree Collapse file tree 2 files changed +35
-4
lines changed
Expand file tree Collapse file tree 2 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -16,13 +16,25 @@ module.exports = function (source, options) {
1616 const code = new CodeBuilder ( )
1717 // Start Request
1818 code . push ( 'import http.client' )
19- . blank ( )
19+
20+ if ( options . insecureSkipVerify ) {
21+ code . push ( 'import ssl' )
22+ }
23+
24+ code . blank ( )
2025
2126 // Check which protocol to be used for the client connection
2227 const protocol = source . uriObj . protocol
2328 if ( protocol === 'https:' ) {
24- code . push ( 'conn = http.client.HTTPSConnection("%s")' , source . uriObj . host )
25- . blank ( )
29+ if ( options . insecureSkipVerify ) {
30+ code . push (
31+ 'conn = http.client.HTTPSConnection("%s", context = ssl._create_unverified_context())' ,
32+ source . uriObj . host
33+ ) . blank ( )
34+ } else {
35+ code . push ( 'conn = http.client.HTTPSConnection("%s")' , source . uriObj . host )
36+ . blank ( )
37+ }
2638 } else {
2739 code . push ( 'conn = http.client.HTTPConnection("%s")' , source . uriObj . host )
2840 . blank ( )
Original file line number Diff line number Diff line change 22
33require ( 'should' )
44
5- module . exports = function ( snippet , fixtures ) { }
5+ module . exports = function ( HTTPSnippet , fixtures ) {
6+ it ( 'should support insecureSkipVerify' , function ( ) {
7+ const result = new HTTPSnippet ( fixtures . requests . https ) . convert ( 'python' , 'python3' , {
8+ insecureSkipVerify : true
9+ } )
10+
11+ result . should . be . a . String ( )
12+ result . should . eql ( `import http.client
13+ import ssl
14+
15+ conn = http.client.HTTPSConnection("mockbin.com", context = ssl._create_unverified_context())
16+
17+ conn.request("GET", "/har")
18+
19+ res = conn.getresponse()
20+ data = res.read()
21+
22+ print(data.decode("utf-8"))` )
23+ } )
24+ }
You can’t perform that action at this time.
0 commit comments