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

Merge http-leaks into smart-server-leaks

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
                                     errno.ECONNABORTED, errno.EBADF)):
102
102
                raise
103
103
 
 
104
    error_content_type = 'text/plain'
 
105
    error_message_format = '''\
 
106
Error code: %(code)s.
 
107
Message: %(message)s.
 
108
'''
 
109
 
 
110
    def send_error(self, code, message=None):
 
111
        """Send and log an error reply.
 
112
 
 
113
        We redefine the python-provided version to be able to set a 
 
114
        ``Content-Length`` header as some http/1.1 clients complain otherwise
 
115
        (see bug #568421).
 
116
 
 
117
        :param code: The HTTP error code.
 
118
 
 
119
        :param message: The explanation of the error code, Defaults to a short
 
120
             entry.
 
121
        """
 
122
 
 
123
        if message is None:
 
124
            try:
 
125
                message = self.responses[code][0]
 
126
            except KeyError:
 
127
                message = '???'
 
128
        self.log_error("code %d, message %s", code, message)
 
129
        content = (self.error_message_format %
 
130
                   {'code': code, 'message': message})
 
131
        self.send_response(code, message)
 
132
        self.send_header("Content-Type", self.error_content_type)
 
133
        self.send_header("Content-Length", "%d" % len(content))
 
134
        self.send_header('Connection', 'close')
 
135
        self.end_headers()
 
136
        if self.command != 'HEAD' and code >= 200 and code not in (204, 304):
 
137
            self.wfile.write(content)
 
138
 
104
139
    def _handle_one_request(self):
105
140
        SimpleHTTPServer.SimpleHTTPRequestHandler.handle_one_request(self)
106
141