Modify according to review feedback.

This commit is contained in:
Aaron Tan
2017-03-20 14:27:02 -04:00
parent f69c2569d6
commit 07e7e4cfd0
2 changed files with 27 additions and 14 deletions

View File

@@ -6,7 +6,7 @@ import logging
import json
import requests
import time
import re
import urlparse
from concurrent.futures import ThreadPoolExecutor
from copy import copy
@@ -119,18 +119,21 @@ class BaseHTTPSHandler(logging.Handler):
def get_http_host(self):
host = self.host or ''
# Force using http(s) protocol
if re.match(r'https?://', host) is None:
if re.match(r'[a-zA-Z]+://', host) is None:
host = 'http://%s' % self.host
else:
host = re.sub(r'[a-zA-Z]+://', r'http://', host, count=1)
# Insert self.port if its special and port number not given in host
if (self.port != 80 and self.port is not None and
re.match(r'https?://[^:/]+:[0-9]+', host) is None):
host = re.sub(r'https?://[^/]+',
lambda m: '%s:%s' % (m.group(0), str(self.port),
host, count=1)
# urlparse requires scheme to be provided, default to use http if
# missing
if not urlparse.urlsplit(host).scheme:
host = 'http://%s' % host
parsed = urlparse.urlsplit(host)
# Insert self.port if its special and port number is either not
# given in host or given as non-numerical
try:
port = parsed.port or self.port
except ValueError:
port = self.port
if port not in (80, None):
new_netloc = '%s:%s' % (parsed.hostname, port)
return urlparse.urlunsplit((parsed.scheme, new_netloc, parsed.path,
parsed.query, parsed.fragment))
return host
def get_post_kwargs(self, payload_input):