##// END OF EJS Templates
hgweb: pass the actual response body to request.response, not just the length...
Mads Kiilerich -
r18352:e33b9b92 default
parent child Browse files
Show More
@@ -140,11 +140,11 b' def staticfile(directory, fname, req):'
140 140 try:
141 141 os.stat(path)
142 142 ct = mimetypes.guess_type(path)[0] or "text/plain"
143 req.respond(HTTP_OK, ct, length = os.path.getsize(path))
144 143 fp = open(path, 'rb')
145 144 data = fp.read()
146 145 fp.close()
147 return data
146 req.respond(HTTP_OK, ct, body=data)
147 return ""
148 148 except TypeError:
149 149 raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename')
150 150 except OSError, err:
@@ -158,8 +158,9 b' class hgweb(object):'
158 158 '').lower() != '100-continue') or
159 159 req.env.get('X-HgHttp2', '')):
160 160 req.drain()
161 req.respond(inst, protocol.HGTYPE)
162 return '0\n%s\n' % inst.message
161 req.respond(inst, protocol.HGTYPE,
162 body='0\n%s\n' % inst.message)
163 return ''
163 164
164 165 # translate user-visible url structure to internal structure
165 166
@@ -75,24 +75,24 b' def call(repo, req, cmd):'
75 75 p = webproto(req, repo.ui)
76 76 rsp = wireproto.dispatch(repo, p, cmd)
77 77 if isinstance(rsp, str):
78 req.respond(HTTP_OK, HGTYPE, length=len(rsp))
79 return [rsp]
78 req.respond(HTTP_OK, HGTYPE, body=rsp)
79 return []
80 80 elif isinstance(rsp, wireproto.streamres):
81 81 req.respond(HTTP_OK, HGTYPE)
82 82 return rsp.gen
83 83 elif isinstance(rsp, wireproto.pushres):
84 84 val = p.restore()
85 85 rsp = '%d\n%s' % (rsp.res, val)
86 req.respond(HTTP_OK, HGTYPE, length=len(rsp))
87 return [rsp]
86 req.respond(HTTP_OK, HGTYPE, body=rsp)
87 return []
88 88 elif isinstance(rsp, wireproto.pusherr):
89 89 # drain the incoming bundle
90 90 req.drain()
91 91 p.restore()
92 92 rsp = '0\n%s\n' % rsp.res
93 req.respond(HTTP_OK, HGTYPE, length=len(rsp))
94 return [rsp]
93 req.respond(HTTP_OK, HGTYPE, body=rsp)
94 return []
95 95 elif isinstance(rsp, wireproto.ooberror):
96 96 rsp = rsp.message
97 req.respond(HTTP_OK, HGERRTYPE, length=len(rsp))
98 return [rsp]
97 req.respond(HTTP_OK, HGERRTYPE, body=rsp)
98 return []
@@ -70,7 +70,7 b' class wsgirequest(object):'
70 70 for s in util.filechunkiter(self.inp, limit=length):
71 71 pass
72 72
73 def respond(self, status, type, filename=None, length=None):
73 def respond(self, status, type, filename=None, body=None):
74 74 if self._start_response is not None:
75 75 self.headers.append(('Content-Type', type))
76 76 if filename:
@@ -78,8 +78,8 b' class wsgirequest(object):'
78 78 .replace('\\', '\\\\').replace('"', '\\"'))
79 79 self.headers.append(('Content-Disposition',
80 80 'inline; filename="%s"' % filename))
81 if length is not None:
82 self.headers.append(('Content-Length', str(length)))
81 if body is not None:
82 self.headers.append(('Content-Length', str(len(body))))
83 83
84 84 for k, v in self.headers:
85 85 if not isinstance(v, str):
@@ -103,6 +103,9 b' class wsgirequest(object):'
103 103 self.server_write = self._start_response(status, self.headers)
104 104 self._start_response = None
105 105 self.headers = []
106 if body is not None:
107 self.write(body)
108 self.server_write = None
106 109
107 110 def write(self, thing):
108 111 if thing:
@@ -61,8 +61,8 b' def rawfile(web, req, tmpl):'
61 61 if mt.startswith('text/'):
62 62 mt += '; charset="%s"' % encoding.encoding
63 63
64 req.respond(HTTP_OK, mt, path, len(text))
65 return [text]
64 req.respond(HTTP_OK, mt, path, body=text)
65 return []
66 66
67 67 def _filerevision(web, tmpl, fctx):
68 68 f = fctx.path()
General Comments 0
You need to be logged in to leave comments. Login now