comparison libervia/server/server.py @ 1454:fc91b78b71db

server: handle "proxy" scheme in configuration
author Goffi <goffi@goffi.org>
date Tue, 28 Sep 2021 18:18:37 +0200
parents 396d5606477f
children 595e7fef41f3
comparison
equal deleted inserted replaced
1453:d62df81440c6 1454:fc91b78b71db
494 log.info("[{host_name}] Added redirection from /{old} to application " 494 log.info("[{host_name}] Added redirection from /{old} to application "
495 "{app_name}".format( 495 "{app_name}".format(
496 host_name=self.host_name, 496 host_name=self.host_name,
497 old=old, 497 old=old,
498 app_name=app_name)) 498 app_name=app_name))
499
500 # normal redirection system is not used here
501 continue
502 elif new_url.scheme == "proxy":
503 # a reverse proxy
504 host, port = new_url.hostname, new_url.port
505 if host is None or port is None:
506 raise ValueError(
507 "invalid host or port in proxy redirection, please check your "
508 "configuration: {new_url.geturl()}"
509 )
510 url_prefix = (new_url.path or old).rstrip('/')
511 res = proxy.SatReverseProxyResource(
512 host,
513 port,
514 url_prefix.encode(),
515 )
516 self.addResourceToPath(old, res)
517 log.info(
518 f"[{self.host_name}] Added redirection from /{old} to reverse proxy "
519 f"{new_url.netloc} with URL prefix {url_prefix}/"
520 )
499 521
500 # normal redirection system is not used here 522 # normal redirection system is not used here
501 continue 523 continue
502 else: 524 else:
503 raise NotImplementedError( 525 raise NotImplementedError(