8000 Fix issue #208: parse the correct scheme of URL in Python26 (#209) · sonlinux/client_python@d4a2ecf · GitHub
[go: up one dir, main page]

Skip to content

Commit d4a2ecf

Browse files
caosiyangbrian-brazil
authored andcommitted
Fix issue prometheus#208: parse the correct scheme of URL in Python26 (prometheus#209)
1 parent 7249378 commit d4a2ecf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

prometheus_client/exposition.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import base64
66
import os
77
import socket
8+
import sys
89
import threading
910
from contextlib import closing
1011
from wsgiref.simple_server import make_server, WSGIRequestHandler
@@ -27,6 +28,7 @@
2728
CONTENT_TYPE_LATEST = str('text/plain; version=0.0.4; charset=utf-8')
2829
'''Content type of the latest text format'''
2930

31+
PYTHON26_OR_OLDER = tuple(int(val) for val in sys.version.split()[0].split('.')) < (2, 7, 0)
3032

3133
def make_wsgi_app(registry=core.REGISTRY):
3234
'''Create a WSGI app which serves the metrics from a registry.'''
@@ -251,7 +253,7 @@ def delete_from_gateway(gateway, job, grouping_key=None, timeout=None, handler=d
251253

252254
def _use_gateway(method, gateway, job, registry, grouping_key, timeout, handler):
253255
gateway_url = urlparse(gateway)
254-
if not gateway_url.scheme:
256+
if not gateway_url.scheme or (PYTHON26_OR_OLDER and gateway_url.scheme not in ['http', 'https']):
255257
gateway = 'http://{0}'.format(gateway)
256258
url = '{0}/metrics/job/{1}'.format(gateway, quote_plus(job))
257259

0 commit comments

Comments
 (0)
0