Example #1
0
async def middleware(request, handler):
    path = request.url.path
    if len(path) > 100:
        return web.HTTPTemporaryRedirect('/nou')
    if request.url.path[-1] == '/' and request.url.path != '/':
        stripped_url = request.url.path.rstrip('/')
        return web.HTTPPermanentRedirect(stripped_url)
    r = await handler(request)
    if isinstance(r, str):
        r = web.Response(text=r, headers={'content-type': 'text/html'})
    content_types = {
        'css': 'text/css',
        'js': 'text/javascript',
        'html': 'text/html',
        'json': 'application/json',
        'xml': 'application/xml',
        'rss': 'application/rss+xml',
        'png': 'image/png'
    }
    # if r.content_type == 'application/octet-stream':
    parts = request.url.parts
    last_path = parts[-1]
    ext = last_path.rsplit('.', 1)[-1]
    if ext in content_types:
        r.content_type = content_types[ext]
    else:
        if r.content_type == 'application/octet-stream':
            r.content_type = 'text/plain'
    try:
        r = await custom_replace(r, request)
    except AttributeError:
        pass
    return r
Example #2
0
 def _https_redirect(self, request):
     if self._https and not request.secure:
         new_url = request.url.with_host(
             self._https[0]).with_scheme('https')
         if new_url.port != self._https[1]:
             new_url = new_url.with_port(self._https[1])
         raise web.HTTPPermanentRedirect(new_url)
    async def test_donate(self, data: web.Request):
        # update_config()
        print(data, file=sys.stderr)
        print(data.query["size"], file=sys.stderr)
        donation = Donation({
            "additional_data": "{}",
            "amount_main": int(data.query["size"]),
            "username": "******"
        })

        asyncio.get_running_loop().create_task(self.callback(donation))
        return web.HTTPPermanentRedirect("/")
Example #4
0
    async def middleware(self, request, handler):
        whitepath = request.path in self._white_paths
        if not whitepath and not request.secure:
            if self._redirect:
                if self._redirect_url:
                    url = self._redirect_url.join(request.url.relative())
                else:
                    url = request.url.with_scheme('https').with_port(None)
                raise web.HTTPPermanentRedirect(url)
            else:
                msg = "Not secure URL %(url)s"
                logger.error(msg, {'url': request.url})
                await self.raise_error(request)

        return await handler(request)
async def index_handler(request: web.Request) -> web.Response:
    LOG.info('/ has been called, redirecting to /api')
    raise web.HTTPPermanentRedirect('/api')
Example #6
0
 async def get_index(request: web.Request) -> web.Response:
     return web.HTTPPermanentRedirect(URL_BASE)
Example #7
0
async def app_wrong_route(request):
    return web.HTTPPermanentRedirect('/')
Example #8
0
async def handle_fresh(request):
    return web.HTTPPermanentRedirect("/fresh-builds")
Example #9
0
 async def get(self):
     raw_date: str = self.request.match_info.get(REQUEST_VALUE)
     location_url = self.request.app.router['day'].url_for()
     location = location_url.update_query({QUERY_WORD_DATE: raw_date})
     raise web.HTTPPermanentRedirect(location=location)
Example #10
0
 async def get(self):
     return web.HTTPPermanentRedirect('/user')
Example #11
0
async def index(request: Request) -> Response:
    return web.HTTPPermanentRedirect("/commands")