comparison mercurial/hgweb/request.py @ 18345:590056e0ec2f

hgweb: send Content-Length 0 for zero length response Before, Content-Length wasn't sent for 0 length responses. Now it is. This could in principle prevent some unnecessary http connection close.
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 15 Jan 2013 01:05:12 +0100
parents e2c413bde8a5
children 853221386f48
comparison
equal deleted inserted replaced
18344:87923db0ecff 18345:590056e0ec2f
68 '''need to read all data from request, httplib is half-duplex''' 68 '''need to read all data from request, httplib is half-duplex'''
69 length = int(self.env.get('CONTENT_LENGTH') or 0) 69 length = int(self.env.get('CONTENT_LENGTH') or 0)
70 for s in util.filechunkiter(self.inp, limit=length): 70 for s in util.filechunkiter(self.inp, limit=length):
71 pass 71 pass
72 72
73 def respond(self, status, type=None, filename=None, length=0): 73 def respond(self, status, type=None, filename=None, length=None):
74 if self._start_response is not None: 74 if self._start_response is not None:
75 75
76 self.httphdr(type, filename, length) 76 self.httphdr(type, filename, length)
77 if not self.headers: 77 if not self.headers:
78 raise RuntimeError("request.write called before headers sent") 78 raise RuntimeError("request.write called before headers sent")
123 return None 123 return None
124 124
125 def header(self, headers=[('Content-Type','text/html')]): 125 def header(self, headers=[('Content-Type','text/html')]):
126 self.headers.extend(headers) 126 self.headers.extend(headers)
127 127
128 def httphdr(self, type=None, filename=None, length=0, headers={}): 128 def httphdr(self, type=None, filename=None, length=None, headers={}):
129 headers = headers.items() 129 headers = headers.items()
130 if type is not None: 130 if type is not None:
131 headers.append(('Content-Type', type)) 131 headers.append(('Content-Type', type))
132 if filename: 132 if filename:
133 filename = (filename.split('/')[-1] 133 filename = (filename.split('/')[-1]
134 .replace('\\', '\\\\').replace('"', '\\"')) 134 .replace('\\', '\\\\').replace('"', '\\"'))
135 headers.append(('Content-Disposition', 135 headers.append(('Content-Disposition',
136 'inline; filename="%s"' % filename)) 136 'inline; filename="%s"' % filename))
137 if length: 137 if length is not None:
138 headers.append(('Content-Length', str(length))) 138 headers.append(('Content-Length', str(length)))
139 self.header(headers) 139 self.header(headers)
140 140
141 def wsgiapplication(app_maker): 141 def wsgiapplication(app_maker):
142 '''For compatibility with old CGI scripts. A plain hgweb() or hgwebdir() 142 '''For compatibility with old CGI scripts. A plain hgweb() or hgwebdir()