Replies: 5 comments 4 replies
-
|
Sorry, what is the question/problem? If it's how to do a redirect, see https://docs.aiohttp.org/en/stable/web_quickstart.html#redirects |
Beta Was this translation helpful? Give feedback.
-
|
This is not the same.
Concern
-------
Suppose that an HTTP client navigates to a URI (GET method).
The HTTP client has no JS (e.g. it may be a software such as Dillo).
That page is relied on JS; otherwise, there is another page without JS.
Plan
----
So, the JS page offers a JS text.
var xmlHttpRequest;
xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open("GET", "/support?feature=ecma", true);
xmlHttpRequest.send();
If aiohttp receives the request of "/support?feature=ecma"; then it
would do nothing.
However, if aiohttp does not receive the request of
"/support?feature=ecma", and no further requests are sent, after five
seconds, after the last request; then aiohttp would redirect to the
page without JS.
|
Beta Was this translation helpful? Give feedback.
-
|
Have you tried it?
Yes.
If so, what went wrong?
This middleware is executed upon every request, so the awaiting
directive of five seconds causes to the page load to occur for five
seconds times the number of requests; that is, five seconds per
request, which be fifty seconds per ten requests.
What part are you actually struggling with?
The unnecessary time span.
I want this middle ware to be executed once; or, the least times as
possible.
Perhaps, I want for this middleware to immediately retract upon each
new request;
Once there are no more requests, the middleware would not retract; and
Then, the process would occur.
|
Beta Was this translation helpful? Give feedback.
-
|
Sam. Good afternoon.
I am trying with the third solution (with directives try/except); and
That solution appears to be working.
I am testing with Dillo, and Falkon.
I send this message to inform you that your solution works.
I will further test, and inform you of results.
I thank you very much for your time and effort.
Please. Check your email.
|
Beta Was this translation helpful? Give feedback.
-
|
Attempting to route to documents causes to the test to fail. This is the middleware which I currently attempt to utilize. class MyMiddleware:
def __init__(self, delay: float = 5):
self._task: asyncio.Task[None] | None = None
self._delay = delay
async def __call__(
self,
request: Request,
handler: Callable[[Request], Awaitable[StreamResponse]]
) -> StreamResponse:
if self._task is not None:
self._task.cancel()
self._task = asyncio.create_task(asyncio.sleep(self._delay))
try:
await self._task
except asyncio.CancelledError:
# A new request is engaged, skip to processing request
#del clients[request.remote]
pass
else:
# Timeout was reached.
if request.remote in clients:
client = clients[request.remote]
print(client)
if client["xslt"] == False and client["ecma"] == False:
# Route to (X)HTML.
#response = HttpRoutes.pages(request, xml=False)
print("Redirect to (X)HTML")
elif client["xslt"] == False and client["ecma"] == True:
# Route to SaxonJS.
#response = HttpRoutes.pages(request, xml=False)
print("Redirect to SaxonJS")
else:
# Route to XML.
#response = HttpRoutes.pages(request, xml=True)
print("Redirect to XML")
#return response
return await handler(request)
@middleware
async def my_middleware(request: Request, handler: Callable[[Request], Awaitable[StreamResponse]]) -> StreamResponse:
middleware_instance = MyMiddleware(delay=5) # Create an instance of your middleware
return await middleware_instance.__call__(request, handler)This is the function def pages(request: Request, xml=True):
if "directory" in request.match_info:
directory = request.match_info["directory"]
else:
directory = ""
if directory not in ("graphics", "images", "scripts"):
if "identifier" in request.match_info:
identifier = request.match_info["identifier"]
else:
identifier = ""
if xml:
filename = "index.atom"
mimetype = "application/xml" # application/atom+xml
else:
filename = "index.html"
mimetype = "text/html"
pathname = os.path.join(publish_properties.directory_output,
directory, identifier, filename)
if os.path.exists(pathname):
result = open(pathname, mode="r").read()
response = Response(
text=result,
content_type=mimetype)
elif not os.path.exists(pathname):
#logger.error(f"{function_name} {e}")
# NOTE This condition is redundant.
if directory not in ("graphics", "images", "scripts"):
raise HTTPFound(f"{request.raw_path}/")
else:
# NOTE Error 403 might be better appropriate.
response = HttpErrors.handle_404(request)
return responseAnother issue, of lesser importance, is that I failed to clear the dictionary of the IP Address from the "clients" dictionary ( |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This is relevant to JS, outdated client software, et cetera.
I attempt to do something of sort with XSLT and ECMA.
https://biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/202601/msg00041.html
This "middleware" is my cirrent attempt.
It could require a minute or so, because it is activated upon every request.
Client requests that are sent to "/support?feature=xslt" and "/support?feature=ecma" would set the values of
client["xslt"]andclient["ecma"]toTrue.I would appreciate your help.
This is the project which involves XSLT and aiohttp.
https://git.xmpp-it.net/sch/Rivista
Beta Was this translation helpful? Give feedback.
All reactions