~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/http_utils.py

  • Committer: Jelmer Vernooij
  • Date: 2010-12-20 11:57:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5577.
  • Revision ID: jelmer@samba.org-20101220115714-2ru3hfappjweeg7q
Don't use no-plugins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
from cStringIO import StringIO
 
18
import errno
18
19
import re
 
20
import socket
 
21
import threading
 
22
import time
19
23
import urllib2
 
24
import urlparse
20
25
 
21
26
 
22
27
from bzrlib import (
27
32
    )
28
33
from bzrlib.smart import (
29
34
    medium,
 
35
    protocol,
30
36
    )
31
37
from bzrlib.tests import http_server
32
38
from bzrlib.transport import chroot
284
290
    # - auth_header_recv: the header received containing auth
285
291
    # - auth_error_code: the error code to indicate auth required
286
292
 
287
 
    def _require_authentication(self):
288
 
        # Note that we must update test_case_server *before*
289
 
        # sending the error or the client may try to read it
290
 
        # before we have sent the whole error back.
291
 
        tcs = self.server.test_case_server
292
 
        tcs.auth_required_errors += 1
293
 
        self.send_response(tcs.auth_error_code)
294
 
        self.send_header_auth_reqed()
295
 
        # We do not send a body
296
 
        self.send_header('Content-Length', '0')
297
 
        self.end_headers()
298
 
        return
299
 
 
300
293
    def do_GET(self):
301
294
        if self.authorized():
302
295
            return http_server.TestingHTTPRequestHandler.do_GET(self)
303
296
        else:
304
 
            return self._require_authentication()
305
 
 
306
 
    def do_HEAD(self):
307
 
        if self.authorized():
308
 
            return http_server.TestingHTTPRequestHandler.do_HEAD(self)
309
 
        else:
310
 
            return self._require_authentication()
 
297
            # Note that we must update test_case_server *before*
 
298
            # sending the error or the client may try to read it
 
299
            # before we have sent the whole error back.
 
300
            tcs = self.server.test_case_server
 
301
            tcs.auth_required_errors += 1
 
302
            self.send_response(tcs.auth_error_code)
 
303
            self.send_header_auth_reqed()
 
304
            # We do not send a body
 
305
            self.send_header('Content-Length', '0')
 
306
            self.end_headers()
 
307
            return
311
308
 
312
309
 
313
310
class BasicAuthRequestHandler(AuthRequestHandler):