http: Add keep alive header to the requests.

This commit is contained in:
poljar (Damir Jelić) 2018-03-20 20:00:00 +01:00
parent 808f652d5f
commit 5e7cd9e504

View file

@ -50,6 +50,7 @@ class HttpRequest:
# type: (...) -> None
user_agent = 'User-Agent: {agent}'.format(agent=user_agent)
host_header = 'Host: {host}'.format(host=host)
keepalive = "Connection: keep-alive"
request_list = [] # type: List[str]
accept_header = 'Accept: */*' # type: str
end_separator = '\r\n' # type: str
@ -59,7 +60,8 @@ class HttpRequest:
if request_type == RequestType.GET:
get = 'GET {location} HTTP/1.1'.format(location=location)
request_list = [
get, host_header, user_agent, accept_header, end_separator
get, host_header, user_agent, keepalive, accept_header,
end_separator
]
elif (request_type == RequestType.POST or
@ -80,8 +82,8 @@ class HttpRequest:
length=len(json_data))
request_list = [
request_line, host_header, user_agent, accept_header,
length_header, type_header, end_separator
request_line, host_header, user_agent, keepalive,
accept_header, length_header, type_header, end_separator
]
payload = json_data