Skip to content

Commit a99eec5

Browse files
Merge pull request #1 from startersclan/fix/python-fix-miniclient.http-get-causing-nginx-to-fail-with-499
Fix (python): Fix miniclient.http_get() causing nginx to fail with `499`
2 parents 2197486 + 308b593 commit a99eec5

1 file changed

Lines changed: 42 additions & 34 deletions

File tree

stats/miniclient.py

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,46 @@ def http_get(host, port = 80, document = "/"):
1818

1919
raise
2020

21-
http.writeline("GET %s HTTP/1.1" % str(document))
22-
http.writeline("Host: %s" % host)
23-
http.writeline("User-Agent: GameSpyHTTP/1.0")
24-
http.writeline("Connection: close") # do not keep-alive
25-
http.writeline("")
26-
http.shutdown() # be nice, tell the http server we're done sending the request
27-
28-
# Determine Status
29-
statusCode = 0
30-
status = string.split(http.readline())
31-
if status[0] != "HTTP/1.1":
32-
print "MiniClient: Unknown status response (%s)" % str(status[0])
33-
3421
try:
35-
statusCode = string.atoi(status[1])
36-
except ValueError:
37-
print "MiniClient: Non-numeric status code (%s)" % str(status[1])
38-
39-
#Extract Headers
40-
headers = []
41-
while 1:
42-
line = http.readline()
43-
if not line:
44-
break
45-
headers.append(line)
46-
47-
http.close() # all done
48-
49-
#Check we got a valid HTTP response
50-
if statusCode == 200:
51-
return http.read()
52-
else:
53-
return "E\nH\terr\nD\tHTTP Error %s \"%s\"\n$\tERR\t$" % (str(statusCode), str(status[2]))
54-
22+
http.writeline("GET %s HTTP/1.1" % str(document))
23+
http.writeline("Host: %s" % host)
24+
http.writeline("User-Agent: GameSpyHTTP/1.0")
25+
http.writeline("Connection: close") # do not keep-alive
26+
http.writeline("")
27+
28+
# Determine Status
29+
statusCode = 0
30+
status = string.split(http.readline())
31+
if status[0] != "HTTP/1.1":
32+
print "MiniClient: Unknown status response (%s)" % str(status[0])
33+
34+
try:
35+
statusCode = string.atoi(status[1])
36+
except ValueError:
37+
print "MiniClient: Non-numeric status code (%s)" % str(status[1])
38+
39+
#Extract Headers
40+
headers = []
41+
while 1:
42+
line = http.readline()
43+
if not line:
44+
break
45+
headers.append(line)
46+
47+
http.shutdown() # be nice, tell the http server we're done sending the request
48+
http.close() # all done
49+
50+
#Check we got a valid HTTP response
51+
if statusCode == 200:
52+
return http.read()
53+
else:
54+
return "E\nH\terr\nD\tHTTP Error %s \"%s\"\n$\tERR\t$" % (str(statusCode), str(status[2]))
55+
56+
except Exception, e:
57+
http.shutdown() # be nice, tell the http server we're done sending the request
58+
http.close() # all done
59+
raise
60+
5561

5662

5763
def http_postSnapshot(host, port = 80, document = "/", snapshot = ""):
@@ -76,7 +82,6 @@ def http_postSnapshot(host, port = 80, document = "/", snapshot = ""):
7682
http.writeline("")
7783
http.writeline(str(snapshot))
7884
http.writeline("")
79-
http.shutdown() # be nice, tell the http server we're done sending the request
8085

8186
# Check that SnapShot Arrives.
8287
# Determine Status
@@ -98,6 +103,7 @@ def http_postSnapshot(host, port = 80, document = "/", snapshot = ""):
98103
break
99104
headers.append(line)
100105

106+
http.shutdown() # be nice, tell the http server we're done sending the request
101107
http.close() # all done
102108

103109
if statusCode == 200:
@@ -106,6 +112,8 @@ def http_postSnapshot(host, port = 80, document = "/", snapshot = ""):
106112
return "E\nH\terr\nD\tHTTP Error %s \"%s\"\n$\tERR\t$" % (str(statusCode), str(status[2]))
107113

108114
except Exception, e:
115+
http.shutdown() # be nice, tell the http server we're done sending the request
116+
http.close() # all done
109117
raise
110118

111119
class miniclient:

0 commit comments

Comments
 (0)