~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/__init__.py

  • Committer: Vincent Ladeuil
  • Date: 2008-01-02 14:13:55 UTC
  • mto: (3159.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 3161.
  • Revision ID: v.ladeuil+lp@free.fr-20080102141355-k20yfjo6i1dasuny
Fix #179368 by keeping the current range hint on ShortReadvErrors.

* response.py:
(RangeFile._checked_read): Avoid huge buffering when huge seeks
are required.

* _urllib2_wrappers.py:
(Response.finish): Check for end-of-file or we'll loop if the
server lied about Content-Length.

* __init__.py:
(HttpTransportBase._readv): When a ShortReadvError occurs, try
again, staying in multiple range mode and degrades only if the
error occurs again for the same offset.

* test_http_response.py:
(TestRangeFileMultipleRanges): Add a test to exercise the buffer
overflow protection code.

* test_http.py:
(TestMultipleRangeWithoutContentLengthServer): Emulate lighttpd
behavior regarding bug #179368.

Show diffs side-by-side

added added

removed removed

Lines of Context:
217
217
        offsets = list(offsets)
218
218
 
219
219
        try_again = True
 
220
        retried_offset = None
220
221
        while try_again:
221
222
            try_again = False
222
223
 
271
272
 
272
273
            except (errors.ShortReadvError, errors.InvalidRange,
273
274
                    errors.InvalidHttpRange), e:
274
 
                self._degrade_range_hint(relpath, coalesced, sys.exc_info())
 
275
                mutter('Exception %r: %s during http._readv',e, e)
 
276
                if (not isinstance(e, errors.ShortReadvError)
 
277
                    or retried_offset == cur_offset_and_size):
 
278
                    # We don't degrade the range hint for ShortReadvError since
 
279
                    # they do not indicate a problem with the server ability to
 
280
                    # handle ranges. Except when we fail to get back a required
 
281
                    # offset twice in a row. In that case, falling back to
 
282
                    # single range or whole file should help or end up in a
 
283
                    # fatal exception.
 
284
                    self._degrade_range_hint(relpath, coalesced, sys.exc_info())
275
285
                # Some offsets may have been already processed, so we retry
276
286
                # only the unsuccessful ones.
277
287
                offsets = [cur_offset_and_size] + [o for o in iter_offsets]
 
288
                retried_offset = cur_offset_and_size
278
289
                try_again = True
279
290
 
280
291
    def _coalesce_readv(self, relpath, coalesced):