46 |
46 |
47 configitem(b'badserver', b'closeafteraccept', |
47 configitem(b'badserver', b'closeafteraccept', |
48 default=False, |
48 default=False, |
49 ) |
49 ) |
50 configitem(b'badserver', b'closeafterrecvbytes', |
50 configitem(b'badserver', b'closeafterrecvbytes', |
51 default=0, |
51 default='0', |
52 ) |
52 ) |
53 configitem(b'badserver', b'closeaftersendbytes', |
53 configitem(b'badserver', b'closeaftersendbytes', |
54 default=0, |
54 default='0', |
55 ) |
55 ) |
56 configitem(b'badserver', b'closebeforeaccept', |
56 configitem(b'badserver', b'closebeforeaccept', |
57 default=False, |
57 default=False, |
58 ) |
58 ) |
59 |
59 |
236 class badserver(server.MercurialHTTPServer): |
236 class badserver(server.MercurialHTTPServer): |
237 def __init__(self, ui, *args, **kwargs): |
237 def __init__(self, ui, *args, **kwargs): |
238 self._ui = ui |
238 self._ui = ui |
239 super(badserver, self).__init__(ui, *args, **kwargs) |
239 super(badserver, self).__init__(ui, *args, **kwargs) |
240 |
240 |
|
241 recvbytes = self._ui.config('badserver', 'closeafterrecvbytes') |
|
242 recvbytes = recvbytes.split(',') |
|
243 self.closeafterrecvbytes = [int(v) for v in recvbytes if v] |
|
244 sendbytes = self._ui.config('badserver', 'closeaftersendbytes') |
|
245 sendbytes = sendbytes.split(',') |
|
246 self.closeaftersendbytes = [int(v) for v in sendbytes if v] |
|
247 |
241 # Need to inherit object so super() works. |
248 # Need to inherit object so super() works. |
242 class badrequesthandler(self.RequestHandlerClass, object): |
249 class badrequesthandler(self.RequestHandlerClass, object): |
243 def send_header(self, name, value): |
250 def send_header(self, name, value): |
244 # Make headers deterministic to facilitate testing. |
251 # Make headers deterministic to facilitate testing. |
245 if name.lower() == 'date': |
252 if name.lower() == 'date': |
273 # Does heavy lifting of processing a request. Invokes |
280 # Does heavy lifting of processing a request. Invokes |
274 # self.finish_request() which calls self.RequestHandlerClass() which |
281 # self.finish_request() which calls self.RequestHandlerClass() which |
275 # is a hgweb.server._httprequesthandler. |
282 # is a hgweb.server._httprequesthandler. |
276 def process_request(self, socket, address): |
283 def process_request(self, socket, address): |
277 # Wrap socket in a proxy if we need to count bytes. |
284 # Wrap socket in a proxy if we need to count bytes. |
278 closeafterrecvbytes = self._ui.configint('badserver', |
285 if self.closeafterrecvbytes: |
279 'closeafterrecvbytes') |
286 closeafterrecvbytes = self.closeafterrecvbytes.pop(0) |
280 closeaftersendbytes = self._ui.configint('badserver', |
287 else: |
281 'closeaftersendbytes') |
288 closeafterrecvbytes = 0 |
|
289 if self.closeaftersendbytes: |
|
290 closeaftersendbytes = self.closeaftersendbytes.pop(0) |
|
291 else: |
|
292 closeaftersendbytes = 0 |
282 |
293 |
283 if closeafterrecvbytes or closeaftersendbytes: |
294 if closeafterrecvbytes or closeaftersendbytes: |
284 socket = socketproxy(socket, self.errorlog, |
295 socket = socketproxy(socket, self.errorlog, |
285 closeafterrecvbytes=closeafterrecvbytes, |
296 closeafterrecvbytes=closeafterrecvbytes, |
286 closeaftersendbytes=closeaftersendbytes) |
297 closeaftersendbytes=closeaftersendbytes) |