/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/HttpServer.py

  • Committer: Daniel Watkins
  • Date: 2007-11-06 09:33:05 UTC
  • mfrom: (2967 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2993.
  • Revision ID: d.m.watkins@warwick.ac.uk-20071106093305-zfef3c0jbcvunnuz
Merged bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
    def handle_one_request(self):
61
61
        """Handle a single HTTP request.
62
62
 
63
 
        You normally don't need to override this method; see the class
64
 
        __doc__ string for information on how to handle specific HTTP
65
 
        commands such as GET and POST.
66
 
 
 
63
        We catch all socket errors occurring when the client close the
 
64
        connection early to avoid polluting the test results.
67
65
        """
68
 
        for i in xrange(1,11): # Don't try more than 10 times
69
 
            try:
70
 
                self.raw_requestline = self.rfile.readline()
71
 
            except socket.error, e:
72
 
                if e.args[0] in (errno.EAGAIN, errno.EWOULDBLOCK):
73
 
                    # omitted for now because some tests look at the log of
74
 
                    # the server and expect to see no errors.  see recent
75
 
                    # email thread. -- mbp 20051021. 
76
 
                    ## self.log_message('EAGAIN (%d) while reading from raw_requestline' % i)
77
 
                    time.sleep(0.01)
78
 
                    continue
 
66
        try:
 
67
            SimpleHTTPRequestHandler.handle_one_request(self)
 
68
        except socket.error, e:
 
69
            if (len(e.args) > 0
 
70
                and e.args[0] in (errno.EPIPE, errno.ECONNRESET,
 
71
                                  errno.ECONNABORTED,)):
 
72
                self.close_connection = 1
 
73
                pass
 
74
            else:
79
75
                raise
80
 
            else:
81
 
                break
82
 
        if not self.raw_requestline:
83
 
            self.close_connection = 1
84
 
            return
85
 
        if not self.parse_request(): # An error code has been sent, just exit
86
 
            return
87
 
        mname = 'do_' + self.command
88
 
        if getattr(self, mname, None) is None:
89
 
            self.send_error(501, "Unsupported method (%r)" % self.command)
90
 
            return
91
 
        method = getattr(self, mname)
92
 
        method()
93
76
 
94
77
    _range_regexp = re.compile(r'^(?P<start>\d+)-(?P<end>\d+)$')
95
78
    _tail_regexp = re.compile(r'^-(?P<tail>\d+)$')
291
274
        # the tests cases.
292
275
        self.test_case_server = test_case_server
293
276
 
 
277
    def server_close(self):
 
278
        """Called to clean-up the server.
 
279
 
 
280
        Since the server may be in a blocking read, we shutdown the socket
 
281
        before closing it.
 
282
        """
 
283
        self.socket.shutdown(socket.SHUT_RDWR)
 
284
        BaseHTTPServer.HTTPServer.server_close(self)
 
285
 
294
286
 
295
287
class HttpServer(Server):
296
288
    """A test server for http transports.
327
319
                                               self.host,
328
320
                                               self.port)
329
321
        self._http_starting.release()
330
 
        httpd.socket.settimeout(0.1)
331
322
 
332
323
        while self._http_running:
333
324
            try:
380
371
 
381
372
    def tearDown(self):
382
373
        """See bzrlib.transport.Server.tearDown."""
 
374
        self._httpd.server_close()
383
375
        self._http_running = False
384
376
        self._http_thread.join()
385
377