@@ -37,12 +37,15 @@ def construct_ctx():
37
37
unpatch ()
38
38
39
39
40
- def _do_req (url , method = 'GET' ):
40
+ def _do_req (url , method = 'GET' , use_https = True ):
41
41
parts = urlparse (url )
42
42
host , _ , port = parts .netloc .partition (':' )
43
43
if port == '' :
44
44
port = None
45
- conn = httplib .HTTPSConnection (parts .netloc , port )
45
+ if use_https :
46
+ conn = httplib .HTTPSConnection (parts .netloc , port )
47
+ else :
48
+ conn = httplib .HTTPConnection (parts .netloc , port )
46
49
47
50
path = '{}?{}' .format (parts .path , parts .query ) if parts .query else parts .path
48
51
conn .request (method , path )
@@ -116,3 +119,25 @@ def test_invalid_url():
116
119
117
120
exception = subsegment .cause ['exceptions' ][0 ]
118
121
assert exception .type == 'gaierror'
122
+
123
+
124
+ def test_correct_identify_http ():
125
+ status_code = 200
126
+ url = 'http://{}/status/{}?foo=bar&baz=foo' .format (BASE_URL , status_code )
127
+ _do_req (url , use_https = False )
128
+ subsegment = xray_recorder .current_segment ().subsegments [0 ]
129
+ assert subsegment .name == strip_url (url )
130
+
131
+ http_meta = subsegment .http
132
+ assert http_meta ['request' ]['url' ].split (":" )[0 ] == 'http'
133
+
134
+
135
+ def test_correct_identify_https ():
136
+ status_code = 200
137
+ url = 'https://{}/status/{}?foo=bar&baz=foo' .format (BASE_URL , status_code )
138
+ _do_req (url , use_https = True )
139
+ subsegment = xray_recorder .current_segment ().subsegments [0 ]
140
+ assert subsegment .name == strip_url (url )
141
+
142
+ https_meta = subsegment .http
143
+ assert https_meta ['request' ]['url' ].split (":" )[0 ] == 'https'
0 commit comments