91 |
91 |
92 def respond(self, status, type, filename=None, body=None): |
92 def respond(self, status, type, filename=None, body=None): |
93 if not isinstance(type, str): |
93 if not isinstance(type, str): |
94 type = pycompat.sysstr(type) |
94 type = pycompat.sysstr(type) |
95 if self._start_response is not None: |
95 if self._start_response is not None: |
96 self.headers.append(('Content-Type', type)) |
96 self.headers.append((r'Content-Type', type)) |
97 if filename: |
97 if filename: |
98 filename = (filename.rpartition('/')[-1] |
98 filename = (filename.rpartition('/')[-1] |
99 .replace('\\', '\\\\').replace('"', '\\"')) |
99 .replace('\\', '\\\\').replace('"', '\\"')) |
100 self.headers.append(('Content-Disposition', |
100 self.headers.append(('Content-Disposition', |
101 'inline; filename="%s"' % filename)) |
101 'inline; filename="%s"' % filename)) |
102 if body is not None: |
102 if body is not None: |
103 self.headers.append(('Content-Length', str(len(body)))) |
103 self.headers.append((r'Content-Length', str(len(body)))) |
104 |
104 |
105 for k, v in self.headers: |
105 for k, v in self.headers: |
106 if not isinstance(v, str): |
106 if not isinstance(v, str): |
107 raise TypeError('header value must be string: %r' % (v,)) |
107 raise TypeError('header value must be string: %r' % (v,)) |
108 |
108 |