~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2006-07-13 14:12:56 UTC
  • mto: This revision was merged to the branch mainline in revision 1869.
  • Revision ID: john@arbash-meinel.com-20060713141256-caf2fbe04f23f3ce
Test that we can extract headers properly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
220
220
                          re.IGNORECASE | re.MULTILINE)
221
221
 
222
222
 
 
223
def _is_multipart(content_type):
 
224
    return content_type.startswith('multipart/byteranges;')
 
225
 
 
226
 
223
227
def handle_response(url, code, headers, response):
224
228
    """Interpret the code & headers and return a HTTP response.
225
229
 
235
239
             ranges indicated by the headers.
236
240
    """
237
241
    content_type = headers['Content-Type']
238
 
    mutter('handling response code %s ctype %s', response.code,
239
 
        content_type)
 
242
    mutter('handling response code %s ctype %s', code, content_type)
240
243
 
241
 
    if response.code == 206 and _is_multipart(content_type):
 
244
    if code == 206 and _is_multipart(content_type):
242
245
        # Full fledged multipart response
243
246
        return HttpMultipartRangeResponse(url, content_type, response)
244
 
    elif response.code == 206:
 
247
    elif code == 206:
245
248
        # A response to a range request, but not multipart
246
 
        content_range = response.headers['Content-Range']
 
249
        content_range = headers['Content-Range']
247
250
        return HttpRangeResponse(url, content_range, response)
248
 
    elif response.code == 200:
 
251
    elif code == 200:
249
252
        # A regular non-range response, unfortunately the result from
250
253
        # urllib doesn't support seek, so we wrap it in a StringIO
251
 
        return StringIO(response.read())
252
 
    elif response.code == 404:
 
254
        tell = getattr(response, 'tell', None)
 
255
        if tell is None:
 
256
            return StringIO(response.read())
 
257
        return response
 
258
    elif code == 404:
253
259
        raise NoSuchFile(url)
254
260
 
255
 
    raise BzrError("HTTP couldn't handle code %s", response.code)
 
261
    raise BzrError("HTTP couldn't handle code %s", code)
256
262