Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/hgwebdir_mod.py @ 6945:2cfdabe235fb
hgweb: return content iterator instead of using write() callable
This is a new version of 4879468fa28f (which was backed out in 943f066c0d58),
with an extra line removed to fix problems with hg serve. hg's internal web
server contains checking if the app isn't trying to write more bytes than
specified by the Content-Length header. The first try still contained an old
line that wrote the response, so the response was sent twice.
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Sat, 30 Aug 2008 17:13:23 +0200 |
parents | 580d5e6bfc1f |
children | 125c8fedcbe0 |
comparison
equal
deleted
inserted
replaced
6944:7e5f3480c45b | 6945:2cfdabe235fb |
---|---|
87 static = os.path.join(templater.templatepath(), 'static') | 87 static = os.path.join(templater.templatepath(), 'static') |
88 if virtual.startswith('static/'): | 88 if virtual.startswith('static/'): |
89 fname = virtual[7:] | 89 fname = virtual[7:] |
90 else: | 90 else: |
91 fname = req.form['static'][0] | 91 fname = req.form['static'][0] |
92 req.write(staticfile(static, fname, req)) | 92 return staticfile(static, fname, req) |
93 return [] | |
94 | 93 |
95 # top-level index | 94 # top-level index |
96 elif not virtual: | 95 elif not virtual: |
97 req.respond(HTTP_OK, ctype) | 96 req.respond(HTTP_OK, ctype) |
98 req.write(self.makeindex(req, tmpl)) | 97 return ''.join(self.makeindex(req, tmpl)), |
99 return [] | |
100 | 98 |
101 # nested indexes and hgwebs | 99 # nested indexes and hgwebs |
102 | 100 |
103 repos = dict(self.repos) | 101 repos = dict(self.repos) |
104 while virtual: | 102 while virtual: |
116 | 114 |
117 # browse subdirectories | 115 # browse subdirectories |
118 subdir = virtual + '/' | 116 subdir = virtual + '/' |
119 if [r for r in repos if r.startswith(subdir)]: | 117 if [r for r in repos if r.startswith(subdir)]: |
120 req.respond(HTTP_OK, ctype) | 118 req.respond(HTTP_OK, ctype) |
121 req.write(self.makeindex(req, tmpl, subdir)) | 119 return ''.join(self.makeindex(req, tmpl, subdir)), |
122 return [] | |
123 | 120 |
124 up = virtual.rfind('/') | 121 up = virtual.rfind('/') |
125 if up < 0: | 122 if up < 0: |
126 break | 123 break |
127 virtual = virtual[:up] | 124 virtual = virtual[:up] |
128 | 125 |
129 # prefixes not found | 126 # prefixes not found |
130 req.respond(HTTP_NOT_FOUND, ctype) | 127 req.respond(HTTP_NOT_FOUND, ctype) |
131 req.write(tmpl("notfound", repo=virtual)) | 128 return ''.join(tmpl("notfound", repo=virtual)), |
132 return [] | |
133 | 129 |
134 except ErrorResponse, err: | 130 except ErrorResponse, err: |
135 req.respond(err.code, ctype) | 131 req.respond(err.code, ctype) |
136 req.write(tmpl('error', error=err.message or '')) | 132 return ''.join(tmpl('error', error=err.message or '')), |
137 return [] | |
138 finally: | 133 finally: |
139 tmpl = None | 134 tmpl = None |
140 | 135 |
141 def makeindex(self, req, tmpl, subdir=""): | 136 def makeindex(self, req, tmpl, subdir=""): |
142 | 137 |