bottle.request.url

Here are the examples of the python api bottle.request.url taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

0 Source : server.py
with MIT License
from rust-lang

def redirect_to_canonical_host():
    request_url = urllib.parse.urlparse(request.url)
    redirect_url = request_url

    # Disable redirects on the health check endpoint.
    if request_url.path == "/health":
        return

    # Handle hostname changes
    if "canonical_url" in g.cfg["web"]:
        canonical_url = urllib.parse.urlparse(g.cfg["web"]["canonical_url"])
        redirect_url = redirect_url._replace(
            scheme=canonical_url.scheme,
            netloc=canonical_url.netloc,
        )

    # Handle path changes
    for prefix in g.cfg["web"].get("remove_path_prefixes", []):
        if redirect_url.path.startswith("/" + prefix + "/"):
            new_path = redirect_url.path[len(prefix)+1:]
            redirect_url = redirect_url._replace(path=new_path)
        elif redirect_url.path == "/" + prefix:
            redirect_url = redirect_url._replace(path="/")

    if request_url != redirect_url:
        redirect(urllib.parse.urlunparse(redirect_url), 301)


def start(cfg, states, queue_handler, repo_cfgs, repos, logger,

0 Source : dispatcher.py
with Apache License 2.0
from shimizukawa

    def route(self, **paths):
        parts = urlparse(bottle.request.url)
        url = urlunparse((self.proto, self.domain) + parts[2:])
        try:
            method = bottle.request.method
            data = bottle.request.body
            req = Request(url, data=data, headers=bottle.request.headers, method=method)
            opener_setup()
            uo = urlopen(req)
            headers = uo.getheaders()
            new_headers = []
            for k,v in headers:
                if self.domain in v:
                    v = v.replace(self.domain, parts[1])
                new_headers.append((k, v))
            return bottle.HTTPResponse(uo.read(), status=uo.status, headers=dict(new_headers))
        except HTTPError as e:
            return bottle.HTTPResponse(e.reason, status=e.code, headers=dict(e.headers))


front = Router('http', 'localhost:8000')