Show More
@@ -72,15 +72,21 class wsgirequest(object): | |||||
72 |
|
72 | |||
73 | def respond(self, status, type, filename=None, length=None): |
|
73 | def respond(self, status, type, filename=None, length=None): | |
74 | if self._start_response is not None: |
|
74 | if self._start_response is not None: | |
75 |
|
75 | self.headers.append(('Content-Type', type)) | ||
76 |
|
|
76 | if filename: | |
|
77 | filename = (filename.split('/')[-1] | |||
|
78 | .replace('\\', '\\\\').replace('"', '\\"')) | |||
|
79 | self.headers.append(('Content-Disposition', | |||
|
80 | 'inline; filename="%s"' % filename)) | |||
|
81 | if length is not None: | |||
|
82 | self.headers.append(('Content-Length', str(length))) | |||
77 |
|
83 | |||
78 | for k, v in self.headers: |
|
84 | for k, v in self.headers: | |
79 | if not isinstance(v, str): |
|
85 | if not isinstance(v, str): | |
80 | raise TypeError('header value must be string: %r' % v) |
|
86 | raise TypeError('header value must be string: %r' % (v,)) | |
81 |
|
87 | |||
82 | if isinstance(status, ErrorResponse): |
|
88 | if isinstance(status, ErrorResponse): | |
83 | self.header(status.headers) |
|
89 | self.headers.extend(status.headers) | |
84 | if status.code == HTTP_NOT_MODIFIED: |
|
90 | if status.code == HTTP_NOT_MODIFIED: | |
85 | # RFC 2616 Section 10.3.5: 304 Not Modified has cases where |
|
91 | # RFC 2616 Section 10.3.5: 304 Not Modified has cases where | |
86 | # it MUST NOT include any headers other than these and no |
|
92 | # it MUST NOT include any headers other than these and no | |
@@ -120,21 +126,6 class wsgirequest(object): | |||||
120 | def close(self): |
|
126 | def close(self): | |
121 | return None |
|
127 | return None | |
122 |
|
128 | |||
123 | def header(self, headers=[('Content-Type','text/html')]): |
|
|||
124 | self.headers.extend(headers) |
|
|||
125 |
|
||||
126 | def httphdr(self, type, filename=None, length=None, headers={}): |
|
|||
127 | headers = headers.items() |
|
|||
128 | headers.append(('Content-Type', type)) |
|
|||
129 | if filename: |
|
|||
130 | filename = (filename.split('/')[-1] |
|
|||
131 | .replace('\\', '\\\\').replace('"', '\\"')) |
|
|||
132 | headers.append(('Content-Disposition', |
|
|||
133 | 'inline; filename="%s"' % filename)) |
|
|||
134 | if length is not None: |
|
|||
135 | headers.append(('Content-Length', str(length))) |
|
|||
136 | self.header(headers) |
|
|||
137 |
|
||||
138 | def wsgiapplication(app_maker): |
|
129 | def wsgiapplication(app_maker): | |
139 | '''For compatibility with old CGI scripts. A plain hgweb() or hgwebdir() |
|
130 | '''For compatibility with old CGI scripts. A plain hgweb() or hgwebdir() | |
140 | can and should now be used as a WSGI application.''' |
|
131 | can and should now be used as a WSGI application.''' |
@@ -804,7 +804,7 def archive(web, req, tmpl): | |||||
804 | ] |
|
804 | ] | |
805 | if encoding: |
|
805 | if encoding: | |
806 | headers.append(('Content-Encoding', encoding)) |
|
806 | headers.append(('Content-Encoding', encoding)) | |
807 | req.header(headers) |
|
807 | req.headers.extend(headers) | |
808 | req.respond(HTTP_OK, mimetype) |
|
808 | req.respond(HTTP_OK, mimetype) | |
809 |
|
809 | |||
810 | ctx = webutil.changectx(web.repo, req) |
|
810 | ctx = webutil.changectx(web.repo, req) |
General Comments 0
You need to be logged in to leave comments.
Login now