Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
588cc3d50d |
31
poetry.lock
generated
31
poetry.lock
generated
@ -367,6 +367,17 @@ setproctitle = ["setproctitle"]
|
||||
testing = ["coverage", "eventlet", "gevent", "pytest", "pytest-cov"]
|
||||
tornado = ["tornado (>=0.2)"]
|
||||
|
||||
[[package]]
|
||||
name = "h11"
|
||||
version = "0.14.0"
|
||||
description = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761"},
|
||||
{file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hypothesis"
|
||||
version = "6.111.2"
|
||||
@ -784,7 +795,25 @@ files = [
|
||||
{file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uvicorn"
|
||||
version = "0.31.1"
|
||||
description = "The lightning-fast ASGI server."
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "uvicorn-0.31.1-py3-none-any.whl", hash = "sha256:adc42d9cac80cf3e51af97c1851648066841e7cfb6993a4ca8de29ac1548ed41"},
|
||||
{file = "uvicorn-0.31.1.tar.gz", hash = "sha256:f5167919867b161b7bcaf32646c6a94cdbd4c3aa2eb5c17d36bb9aa5cfd8c493"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
click = ">=7.0"
|
||||
h11 = ">=0.8"
|
||||
|
||||
[package.extras]
|
||||
standard = ["colorama (>=0.4)", "httptools (>=0.5.0)", "python-dotenv (>=0.13)", "pyyaml (>=5.1)", "uvloop (>=0.14.0,!=0.15.0,!=0.15.1)", "watchfiles (>=0.13)", "websockets (>=10.4)"]
|
||||
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.11"
|
||||
content-hash = "17f5dc4b157da57ad75a6f6aa3feb7adfa07500b805d5e79d1f09d640964949f"
|
||||
content-hash = "2a986e86d4e694216b4585b8acb128a6f9f9958edb6236ac52fd9624be6c31cf"
|
||||
|
@ -43,6 +43,7 @@ black = "^24.8.0"
|
||||
gunicorn = "^23.0.0"
|
||||
hypothesis = "^6.111.2"
|
||||
coverage = "^7.6.1"
|
||||
uvicorn = "^0.31.1"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
|
@ -351,3 +351,25 @@ class SpiderwebRouter(LocalServerMixin, MiddlewareMixin, RoutesMixin, FernetMixi
|
||||
raise SpiderwebNetworkException(404)
|
||||
except SpiderwebNetworkException as e:
|
||||
return self.send_error_response(start_response, request, e)
|
||||
|
||||
def asgi(self, scope):
|
||||
async def inner(receive, send):
|
||||
if scope['path'] == '/':
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
[b'content-type', b'text/html']
|
||||
]
|
||||
})
|
||||
await send({
|
||||
'type': 'http.response.body',
|
||||
'body': bytes(f'<h1>Index page</h1>\n\n<p>{scope}</p><p>{receive}</p><p>{send}</p>', DEFAULT_ENCODING)
|
||||
|
||||
})
|
||||
elif scope['path'] == '/hello':
|
||||
...
|
||||
else:
|
||||
...
|
||||
|
||||
return inner
|
@ -1,21 +1,28 @@
|
||||
import json
|
||||
from typing import Any, Optional, TYPE_CHECKING, Callable
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from spiderweb.constants import DEFAULT_ENCODING
|
||||
from spiderweb.utils import get_client_address, Headers
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from spiderweb import SpiderwebRouter
|
||||
|
||||
|
||||
class Request:
|
||||
def __init__(
|
||||
self,
|
||||
environ=None,
|
||||
content=None,
|
||||
headers=None,
|
||||
path=None,
|
||||
server=None,
|
||||
handler=None,
|
||||
environ: Optional[dict[str, Any]]=None,
|
||||
content: Optional[str]=None,
|
||||
headers: dict[str, str]=None,
|
||||
path: str=None,
|
||||
server: "SpiderwebRouter"=None,
|
||||
handler: Callable=None,
|
||||
scope: Optional[dict[str, Any]]=None,
|
||||
):
|
||||
self.environ = environ
|
||||
self._data = environ or scope
|
||||
|
||||
self.environ = environ or {}
|
||||
self.content: str = content
|
||||
self.method: str = environ["REQUEST_METHOD"]
|
||||
self.headers: dict[str, str] = headers if headers else {}
|
||||
|
Loading…
Reference in New Issue
Block a user