comparison mercurial/hgweb/hgwebdir_mod.py @ 36917:f0a851542a05

hgweb: remove wsgirequest (API) Good riddance. .. api:: The old ``wsgirequest`` class for handling everything WSGI in hgweb has been replaced by separate request and response types. Various high-level functions in the hgweb WSGI applications now receive these new types as arguments instead of the old ``wsgirequest`` type. Differential Revision: https://phab.mercurial-scm.org/D2832
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 11 Mar 2018 16:29:54 -0700
parents cd6ae9ab7bd8
children 6ff6e1d6b5b8
comparison
equal deleted inserted replaced
36916:98487ad0cf8b 36917:f0a851542a05
346 "called while running as a CGI script.") 346 "called while running as a CGI script.")
347 wsgicgi.launch(self) 347 wsgicgi.launch(self)
348 348
349 def __call__(self, env, respond): 349 def __call__(self, env, respond):
350 baseurl = self.ui.config('web', 'baseurl') 350 baseurl = self.ui.config('web', 'baseurl')
351 wsgireq = requestmod.wsgirequest(env, respond, altbaseurl=baseurl) 351 req = requestmod.parserequestfromenv(env, altbaseurl=baseurl)
352 return self.run_wsgi(wsgireq) 352 res = requestmod.wsgiresponse(req, respond)
353 353
354 def run_wsgi(self, wsgireq): 354 return self.run_wsgi(req, res)
355
356 def run_wsgi(self, req, res):
355 profile = self.ui.configbool('profiling', 'enabled') 357 profile = self.ui.configbool('profiling', 'enabled')
356 with profiling.profile(self.ui, enabled=profile): 358 with profiling.profile(self.ui, enabled=profile):
357 for r in self._runwsgi(wsgireq): 359 for r in self._runwsgi(req, res):
358 yield r 360 yield r
359 361
360 def _runwsgi(self, wsgireq): 362 def _runwsgi(self, req, res):
361 req = wsgireq.req
362 res = wsgireq.res
363
364 try: 363 try:
365 self.refresh() 364 self.refresh()
366 365
367 csp, nonce = cspvalues(self.ui) 366 csp, nonce = cspvalues(self.ui)
368 if csp: 367 if csp:
421 for virtualrepo in _virtualdirs(): 420 for virtualrepo in _virtualdirs():
422 real = repos.get(virtualrepo) 421 real = repos.get(virtualrepo)
423 if real: 422 if real:
424 # Re-parse the WSGI environment to take into account our 423 # Re-parse the WSGI environment to take into account our
425 # repository path component. 424 # repository path component.
426 wsgireq.req = requestmod.parserequestfromenv( 425 req = requestmod.parserequestfromenv(
427 wsgireq.env, wsgireq.req.bodyfh, reponame=virtualrepo, 426 req.rawenv, reponame=virtualrepo,
428 altbaseurl=self.ui.config('web', 'baseurl')) 427 altbaseurl=self.ui.config('web', 'baseurl'))
429 try: 428 try:
430 # ensure caller gets private copy of ui 429 # ensure caller gets private copy of ui
431 repo = hg.repository(self.ui.copy(), real) 430 repo = hg.repository(self.ui.copy(), real)
432 return hgweb_mod.hgweb(repo).run_wsgi(wsgireq) 431 return hgweb_mod.hgweb(repo).run_wsgi(req, res)
433 except IOError as inst: 432 except IOError as inst:
434 msg = encoding.strtolocal(inst.strerror) 433 msg = encoding.strtolocal(inst.strerror)
435 raise ErrorResponse(HTTP_SERVER_ERROR, msg) 434 raise ErrorResponse(HTTP_SERVER_ERROR, msg)
436 except error.RepoError as inst: 435 except error.RepoError as inst:
437 raise ErrorResponse(HTTP_SERVER_ERROR, bytes(inst)) 436 raise ErrorResponse(HTTP_SERVER_ERROR, bytes(inst))