author | Pulkit Goyal <7895pulkit@gmail.com> |
Sat, 17 Jun 2017 15:29:26 +0530 | |
changeset 32897 | 799db2af824c |
parent 32021 | 08e46fcb8637 |
child 33191 | 8065b4ab0ed7 |
permissions | -rw-r--r-- |
32001
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 |
# badserverext.py - Extension making servers behave badly |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 |
# |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2017 Gregory Szorc <gregory.szorc@gmail.com> |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 |
# |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 |
# This software may be used and distributed according to the terms of the |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 |
# GNU General Public License version 2 or any later version. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 |
# no-check-code |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
10 |
"""Extension to make servers behave badly. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
11 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
12 |
This extension is useful for testing Mercurial behavior when various network |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
13 |
events occur. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
14 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
15 |
Various config options in the [badserver] section influence behavior: |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
16 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
17 |
closebeforeaccept |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
18 |
If true, close() the server socket when a new connection arrives before |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
19 |
accept() is called. The server will then exit. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 |
closeafteraccept |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 |
If true, the server will close() the client socket immediately after |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 |
accept(). |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
24 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 |
closeafterrecvbytes |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 |
If defined, close the client socket after receiving this many bytes. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 |
closeaftersendbytes |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 |
If defined, close the client socket after sending this many bytes. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
30 |
""" |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 |
from __future__ import absolute_import |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 |
import socket |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
36 |
from mercurial.hgweb import ( |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 |
server, |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 |
) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 |
# We can't adjust __class__ on a socket instance. So we define a proxy type. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
41 |
class socketproxy(object): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
42 |
__slots__ = ( |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
43 |
'_orig', |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 |
'_logfp', |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 |
'_closeafterrecvbytes', |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 |
'_closeaftersendbytes', |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 |
) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 |
def __init__(self, obj, logfp, closeafterrecvbytes=0, |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 |
closeaftersendbytes=0): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 |
object.__setattr__(self, '_orig', obj) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
52 |
object.__setattr__(self, '_logfp', logfp) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 |
object.__setattr__(self, '_closeafterrecvbytes', closeafterrecvbytes) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 |
object.__setattr__(self, '_closeaftersendbytes', closeaftersendbytes) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
56 |
def __getattribute__(self, name): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
57 |
if name in ('makefile',): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 |
return object.__getattribute__(self, name) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
60 |
return getattr(object.__getattribute__(self, '_orig'), name) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 |
def __delattr__(self, name): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 |
delattr(object.__getattribute__(self, '_orig'), name) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
64 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
65 |
def __setattr__(self, name, value): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
66 |
setattr(object.__getattribute__(self, '_orig'), name, value) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
67 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
68 |
def makefile(self, mode, bufsize): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
69 |
f = object.__getattribute__(self, '_orig').makefile(mode, bufsize) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
70 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
71 |
logfp = object.__getattribute__(self, '_logfp') |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
72 |
closeafterrecvbytes = object.__getattribute__(self, |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 |
'_closeafterrecvbytes') |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
74 |
closeaftersendbytes = object.__getattribute__(self, |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
75 |
'_closeaftersendbytes') |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
76 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
77 |
return fileobjectproxy(f, logfp, |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
78 |
closeafterrecvbytes=closeafterrecvbytes, |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 |
closeaftersendbytes=closeaftersendbytes) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
81 |
# We can't adjust __class__ on socket._fileobject, so define a proxy. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 |
class fileobjectproxy(object): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 |
__slots__ = ( |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
84 |
'_orig', |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
85 |
'_logfp', |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
86 |
'_closeafterrecvbytes', |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
87 |
'_closeaftersendbytes', |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
88 |
) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
89 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
90 |
def __init__(self, obj, logfp, closeafterrecvbytes=0, |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
91 |
closeaftersendbytes=0): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
92 |
object.__setattr__(self, '_orig', obj) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
93 |
object.__setattr__(self, '_logfp', logfp) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
94 |
object.__setattr__(self, '_closeafterrecvbytes', closeafterrecvbytes) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
95 |
object.__setattr__(self, '_closeaftersendbytes', closeaftersendbytes) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
96 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
97 |
def __getattribute__(self, name): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
98 |
if name in ('read', 'readline', 'write', '_writelog'): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
99 |
return object.__getattribute__(self, name) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
100 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
101 |
return getattr(object.__getattribute__(self, '_orig'), name) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
102 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
103 |
def __delattr__(self, name): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
104 |
delattr(object.__getattribute__(self, '_orig'), name) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
105 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
106 |
def __setattr__(self, name, value): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
107 |
setattr(object.__getattribute__(self, '_orig'), name, value) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
108 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
109 |
def _writelog(self, msg): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
110 |
msg = msg.replace('\r', '\\r').replace('\n', '\\n') |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
111 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
112 |
object.__getattribute__(self, '_logfp').write(msg) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
113 |
object.__getattribute__(self, '_logfp').write('\n') |
32021
08e46fcb8637
badserverext: explicitly flush each log write
Matt Harbison <matt_harbison@yahoo.com>
parents:
32001
diff
changeset
|
114 |
object.__getattribute__(self, '_logfp').flush() |
32001
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
115 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
116 |
def read(self, size=-1): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
117 |
remaining = object.__getattribute__(self, '_closeafterrecvbytes') |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
118 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
119 |
# No read limit. Call original function. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
120 |
if not remaining: |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
121 |
result = object.__getattribute__(self, '_orig').read(size) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
122 |
self._writelog('read(%d) -> (%d) (%s) %s' % (size, |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
123 |
len(result), |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
124 |
result)) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
125 |
return result |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
126 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
127 |
origsize = size |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
128 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
129 |
if size < 0: |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
130 |
size = remaining |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
131 |
else: |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
132 |
size = min(remaining, size) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
133 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
134 |
result = object.__getattribute__(self, '_orig').read(size) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
135 |
remaining -= len(result) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
136 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
137 |
self._writelog('read(%d from %d) -> (%d) %s' % ( |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
138 |
size, origsize, len(result), result)) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
139 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
140 |
object.__setattr__(self, '_closeafterrecvbytes', remaining) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
141 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
142 |
if remaining <= 0: |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
143 |
self._writelog('read limit reached, closing socket') |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
144 |
self._sock.close() |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
145 |
# This is the easiest way to abort the current request. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
146 |
raise Exception('connection closed after receiving N bytes') |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
147 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
148 |
return result |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
149 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
150 |
def readline(self, size=-1): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
151 |
remaining = object.__getattribute__(self, '_closeafterrecvbytes') |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
152 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
153 |
# No read limit. Call original function. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
154 |
if not remaining: |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
155 |
result = object.__getattribute__(self, '_orig').readline(size) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
156 |
self._writelog('readline(%d) -> (%d) %s' % ( |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
157 |
size, len(result), result)) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
158 |
return result |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
159 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
160 |
origsize = size |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
161 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
162 |
if size < 0: |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
163 |
size = remaining |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
164 |
else: |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
165 |
size = min(remaining, size) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
166 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
167 |
result = object.__getattribute__(self, '_orig').readline(size) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
168 |
remaining -= len(result) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
169 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
170 |
self._writelog('readline(%d from %d) -> (%d) %s' % ( |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
171 |
size, origsize, len(result), result)) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
172 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
173 |
object.__setattr__(self, '_closeafterrecvbytes', remaining) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
174 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
175 |
if remaining <= 0: |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
176 |
self._writelog('read limit reached; closing socket') |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
177 |
self._sock.close() |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
178 |
# This is the easiest way to abort the current request. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
179 |
raise Exception('connection closed after receiving N bytes') |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
180 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
181 |
return result |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
182 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
183 |
def write(self, data): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
184 |
remaining = object.__getattribute__(self, '_closeaftersendbytes') |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
185 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
186 |
# No byte limit on this operation. Call original function. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
187 |
if not remaining: |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
188 |
self._writelog('write(%d) -> %s' % (len(data), data)) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
189 |
result = object.__getattribute__(self, '_orig').write(data) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
190 |
return result |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
191 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
192 |
if len(data) > remaining: |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
193 |
newdata = data[0:remaining] |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
194 |
else: |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
195 |
newdata = data |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
196 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
197 |
remaining -= len(newdata) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
198 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
199 |
self._writelog('write(%d from %d) -> (%d) %s' % ( |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
200 |
len(newdata), len(data), remaining, newdata)) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
201 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
202 |
result = object.__getattribute__(self, '_orig').write(newdata) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
203 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
204 |
object.__setattr__(self, '_closeaftersendbytes', remaining) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
205 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
206 |
if remaining <= 0: |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
207 |
self._writelog('write limit reached; closing socket') |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
208 |
self._sock.close() |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
209 |
raise Exception('connection closed after sending N bytes') |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
210 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
211 |
return result |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
212 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
213 |
def extsetup(ui): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
214 |
# Change the base HTTP server class so various events can be performed. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
215 |
# See SocketServer.BaseServer for how the specially named methods work. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
216 |
class badserver(server.MercurialHTTPServer): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
217 |
def __init__(self, ui, *args, **kwargs): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
218 |
self._ui = ui |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
219 |
super(badserver, self).__init__(ui, *args, **kwargs) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
220 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
221 |
# Need to inherit object so super() works. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
222 |
class badrequesthandler(self.RequestHandlerClass, object): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
223 |
def send_header(self, name, value): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
224 |
# Make headers deterministic to facilitate testing. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
225 |
if name.lower() == 'date': |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
226 |
value = 'Fri, 14 Apr 2017 00:00:00 GMT' |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
227 |
elif name.lower() == 'server': |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
228 |
value = 'badhttpserver' |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
229 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
230 |
return super(badrequesthandler, self).send_header(name, |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
231 |
value) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
232 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
233 |
self.RequestHandlerClass = badrequesthandler |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
234 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
235 |
# Called to accept() a pending socket. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
236 |
def get_request(self): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
237 |
if self._ui.configbool('badserver', 'closebeforeaccept'): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
238 |
self.socket.close() |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
239 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
240 |
# Tells the server to stop processing more requests. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
241 |
self.__shutdown_request = True |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
242 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
243 |
# Simulate failure to stop processing this request. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
244 |
raise socket.error('close before accept') |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
245 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
246 |
if self._ui.configbool('badserver', 'closeafteraccept'): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
247 |
request, client_address = super(badserver, self).get_request() |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
248 |
request.close() |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
249 |
raise socket.error('close after accept') |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
250 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
251 |
return super(badserver, self).get_request() |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
252 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
253 |
# Does heavy lifting of processing a request. Invokes |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
254 |
# self.finish_request() which calls self.RequestHandlerClass() which |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
255 |
# is a hgweb.server._httprequesthandler. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
256 |
def process_request(self, socket, address): |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
257 |
# Wrap socket in a proxy if we need to count bytes. |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
258 |
closeafterrecvbytes = self._ui.configint('badserver', |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
259 |
'closeafterrecvbytes', 0) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
260 |
closeaftersendbytes = self._ui.configint('badserver', |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
261 |
'closeaftersendbytes', 0) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
262 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
263 |
if closeafterrecvbytes or closeaftersendbytes: |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
264 |
socket = socketproxy(socket, self.errorlog, |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
265 |
closeafterrecvbytes=closeafterrecvbytes, |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
266 |
closeaftersendbytes=closeaftersendbytes) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
267 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
268 |
return super(badserver, self).process_request(socket, address) |
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
269 |
|
c85f19c66e8d
tests: add tests for poorly behaving HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
270 |
server.MercurialHTTPServer = badserver |