Skip to content

Commit

Permalink
Disable gzip compression for longpoll responses, to focus on starting…
Browse files Browse the repository at this point in the history
… sends instead
  • Loading branch information
luke-jr committed Jan 31, 2013
1 parent 1cc201f commit 0ddfec2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class HTTPHandler(networkserver.SocketHandler):

default_quirks = {}

def sendReply(self, status=200, body=b'', headers=None):
def sendReply(self, status=200, body=b'', headers=None, tryCompression=True):
if self.replySent:
raise RequestAlreadyHandled
buf = "HTTP/1.1 %d %s\r\n" % (status, self.HTTPStatus.get(status, 'Unknown'))
Expand All @@ -85,7 +85,7 @@ def sendReply(self, status=200, body=b'', headers=None):
if body is None:
headers.setdefault('Transfer-Encoding', 'chunked')
else:
if 'gzip' in self.quirks:
if tryCompression and 'gzip' in self.quirks:
headers['Content-Encoding'] = 'gzip'
headers['Vary'] = 'Content-Encoding'
gz = io.BytesIO()
Expand Down
6 changes: 3 additions & 3 deletions jsonrpcserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ class JSONRPCHandler(httpserver.HTTPHandler):
def final_init(server):
pass

def sendReply(self, status=200, body=b'', headers=None):
def sendReply(self, status=200, body=b'', headers=None, *a, **ka):
headers = dict(headers) if headers else {}
if body and body[0] == 123: # b'{'
headers.setdefault('Content-Type', 'application/json')
if status == 200 and self.path in self.JSONRPCURIs:
if not body:
headers.setdefault('Content-Type', 'application/json')
headers.setdefault('X-Long-Polling', '/LP')
return super().sendReply(status, body, headers)
return super().sendReply(status, body, headers, *a, **ka)

def fmtError(self, reason = '', code = 100):
reason = json.dumps(reason)
Expand Down Expand Up @@ -187,7 +187,7 @@ def wakeLongpoll(self, wantClear = False):
return

try:
self.sendReply(200, body=rv, headers=self.LPHeaders)
self.sendReply(200, body=rv, headers=self.LPHeaders, tryCompression=False)
raise httpserver.RequestNotHandled
except httpserver.RequestHandled:
# Expected
Expand Down

0 comments on commit 0ddfec2

Please sign in to comment.