~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-01-03 18:09:01 UTC
  • mfrom: (3159.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20080103180901-w987y1ftqoh02qbm
(vila) Fix #179368 by keeping the current range hint on
        ShortReadvErrors

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
    # Some responses have bodies in which we have no interest
76
76
    _body_ignored_responses = [301,302, 303, 307, 401, 403, 404]
77
77
 
 
78
    # in finish() below, we may have to discard several MB in the worst
 
79
    # case. To avoid buffering that much, we read and discard by chunks
 
80
    # instead. The underlying file is either a socket or a StringIO, so reading
 
81
    # 8k chunks should be fine.
 
82
    _discarded_buf_size = 8192
 
83
 
78
84
    def begin(self):
79
85
        """Begin to read the response from the server.
80
86
 
113
119
            # below we keep the socket with the server opened.
114
120
            self.will_close = False
115
121
 
116
 
    # in finish() below, we may have to discard several MB in the worst
117
 
    # case. To avoid buffering that much, we read and discard by chunks
118
 
    # instead. The underlying file is either a socket or a StringIO, so reading
119
 
    # 8k chunks should be fine.
120
 
    _discarded_buf_size = 8192
121
 
 
122
122
    def finish(self):
123
123
        """Finish reading the body.
124
124
 
134
134
        if not self.isclosed():
135
135
            # Make sure nothing was left to be read on the socket
136
136
            pending = 0
137
 
            while self.length and self.length > self._discarded_buf_size:
138
 
                data = self.read(self._discarded_buf_size)
139
 
                pending += len(data)
140
 
            if self.length:
141
 
                data = self.read(self.length)
 
137
            data = True
 
138
            while data and self.length:
 
139
                # read() will update self.length
 
140
                data = self.read(min(self.length, self._discarded_buf_size))
142
141
                pending += len(data)
143
142
            if pending:
144
 
                trace.mutter(
145
 
                    "%s bytes left on the HTTP socket",
146
 
                    pending)
 
143
                trace.mutter("%s bytes left on the HTTP socket", pending)
147
144
            self.close()
148
145
        return pending
149
146