- async with session.get(url) as resp:
- status = http.HTTPStatus.OK
- response_headers["Content-Type"] = resp.headers["Content-Type"]
- response_headers["Content-Length"] = resp.headers["Content-Length"]
- body = await resp.read()
- if not status:
- status = http.HTTPStatus.NOT_FOUND
- body = f"'{path}' not found!".encode()
- response_headers["Content-Type"] = "text/plain"
- response_headers["Content-Length"] = str(len(body))
- return status, response_headers, body
+ async with session.get(url) as original:
+ body = (await original.read()).decode()
+ response = websocket.respond(http.HTTPStatus.OK, body)
+ del response.headers["Content-Type"]
+ response.headers["Content-Type"] = original.headers["Content-Type"]
+ if not response:
+ response = websocket.respond(
+ http.HTTPStatus.NOT_FOUND, f"'{path}' not found!"
+ )
+ return response