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