Skip to content

Commit

Permalink
Merge pull request #1 from startersclan/fix/python-fix-miniclient.htt…
Browse files Browse the repository at this point in the history
…p-get-causing-nginx-to-fail-with-499

Fix (python): Fix miniclient.http_get() causing nginx to fail with `499`
  • Loading branch information
leojonathanoh authored Oct 7, 2022
2 parents 2197486 + 308b593 commit a99eec5
Showing 1 changed file with 42 additions and 34 deletions.
76 changes: 42 additions & 34 deletions stats/miniclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,46 @@ def http_get(host, port = 80, document = "/"):

raise

http.writeline("GET %s HTTP/1.1" % str(document))
http.writeline("Host: %s" % host)
http.writeline("User-Agent: GameSpyHTTP/1.0")
http.writeline("Connection: close") # do not keep-alive
http.writeline("")
http.shutdown() # be nice, tell the http server we're done sending the request

# Determine Status
statusCode = 0
status = string.split(http.readline())
if status[0] != "HTTP/1.1":
print "MiniClient: Unknown status response (%s)" % str(status[0])

try:
statusCode = string.atoi(status[1])
except ValueError:
print "MiniClient: Non-numeric status code (%s)" % str(status[1])

#Extract Headers
headers = []
while 1:
line = http.readline()
if not line:
break
headers.append(line)

http.close() # all done

#Check we got a valid HTTP response
if statusCode == 200:
return http.read()
else:
return "E\nH\terr\nD\tHTTP Error %s \"%s\"\n$\tERR\t$" % (str(statusCode), str(status[2]))

http.writeline("GET %s HTTP/1.1" % str(document))
http.writeline("Host: %s" % host)
http.writeline("User-Agent: GameSpyHTTP/1.0")
http.writeline("Connection: close") # do not keep-alive
http.writeline("")

# Determine Status
statusCode = 0
status = string.split(http.readline())
if status[0] != "HTTP/1.1":
print "MiniClient: Unknown status response (%s)" % str(status[0])

try:
statusCode = string.atoi(status[1])
except ValueError:
print "MiniClient: Non-numeric status code (%s)" % str(status[1])

#Extract Headers
headers = []
while 1:
line = http.readline()
if not line:
break
headers.append(line)

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

#Check we got a valid HTTP response
if statusCode == 200:
return http.read()
else:
return "E\nH\terr\nD\tHTTP Error %s \"%s\"\n$\tERR\t$" % (str(statusCode), str(status[2]))

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



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

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

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

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

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

class miniclient:
Expand Down

0 comments on commit a99eec5

Please sign in to comment.