/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/HTTPTestUtil.py

  • Committer: Vincent Ladeuil
  • Date: 2007-06-20 13:56:21 UTC
  • mto: (2574.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 2575.
  • Revision ID: v.ladeuil+lp@free.fr-20070620135621-x43c0hnmzu0iuo6m
Fix #115209 by issuing a single range request on 400: Bad Request

* bzrlib/transport/http/response.py:
(handle_response): Consider 400 as an indication that too much
ranges were specified.

* bzrlib/transport/http/_urllib2_wrappers.py:
(Request): Add an 'accpeted_errors' parameters describing what
error codes the caller will handle.
(HTTPErrorProcessor): Mention that Request specific accepted error
codes takes precedence.
(HTTPDefaultErrorHandler.http_error_default): Remove dead code.

* bzrlib/transport/http/_urllib.py:
(HttpTransport_urllib._get): Add 400 as an accepted error iff
ranges are specified.
(HttpTransport_urllib._head): Restrict accepted errors.

* bzrlib/transport/http/__init__.py:
(HttpTransportBase._degrade_range_hint,
HttpTransportBase._get_ranges_hinted): Replace _retry_get.
(HttpTransportBase.readv): Simplified and avoid the spurious _get()
issued when _get was successful.

* bzrlib/tests/test_http.py:
(TestLimitedRangeRequestServer,
TestLimitedRangeRequestServer_urllib,
TestLimitedRangeRequestServer_pycurl): Bug #115209 specific tests.

* bzrlib/tests/HTTPTestUtil.py:
(LimitedRangeRequestHandler, LimitedRangeHTTPServer): New test
classes to emulate apache throwing 400: Bad Request when too much
ranges are specified.
(AuthRequestHandler.do_GET): Remove dead code. Yeah, I know,
not related to the bug :-/

Show diffs side-by-side

added added

removed removed

Lines of Context:
150
150
        self.wfile.write(out_buffer.getvalue())
151
151
 
152
152
 
 
153
class LimitedRangeRequestHandler(TestingHTTPRequestHandler):
 
154
    """Errors out when range specifiers exceed the limit"""
 
155
 
 
156
    def get_multiple_ranges(self, file, file_size, ranges):
 
157
        """Refuses the multiple ranges request"""
 
158
        tcs = self.server.test_case_server
 
159
        #import pdb; pdb.set_trace()
 
160
        if tcs.range_limit is not None and len(ranges) > tcs.range_limit:
 
161
            file.close()
 
162
            # Emulate apache behavior
 
163
            self.send_error(400, "Bad Request")
 
164
            return
 
165
        return TestingHTTPRequestHandler.get_multiple_ranges(self, file,
 
166
                                                             file_size, ranges)
 
167
 
 
168
    def do_GET(self):
 
169
        tcs = self.server.test_case_server
 
170
        tcs.GET_request_nb += 1
 
171
        return TestingHTTPRequestHandler.do_GET(self)
 
172
 
 
173
 
 
174
class LimitedRangeHTTPServer(HttpServer):
 
175
    """An HttpServer erroring out on requests with too much range specifiers"""
 
176
 
 
177
    def __init__(self, request_handler=LimitedRangeRequestHandler,
 
178
                 range_limit=None):
 
179
        HttpServer.__init__(self, request_handler)
 
180
        self.range_limit = range_limit
 
181
        self.GET_request_nb = 0
 
182
 
 
183
 
153
184
class SingleRangeRequestHandler(TestingHTTPRequestHandler):
154
185
    """Always reply to range request as if they were single.
155
186
 
337
368
            self.end_headers()
338
369
            return
339
370
 
340
 
        TestingHTTPRequestHandler.do_GET(self)
341
 
 
342
371
 
343
372
class BasicAuthRequestHandler(AuthRequestHandler):
344
373
    """Implements the basic authentication of a request"""