Request and Response¶
- class pigwig.Request(app: PigWig, method: str, path: str, query: Mapping[str, str | list[str]], headers: HTTPHeaders, body: dict, cookies: http.cookies.BaseCookie, wsgi_environ: dict[str, Any])[source]¶
an instance of this class is passed to every route handler. has the following instance attrs:
app
- an instance ofPigWig
method
- the request method/verb (GET
,POST
, etc.)path
- WSGI environPATH_INFO
(/foo/bar
)query
- dict of parsed query string. duplicate keys appear as listsheaders
-HTTPHeaders
of the headersbody
- dict of parsed body content. seePigWig.content_handlers
for a list of supported content typescookies
- an instance of http.cookies.SimpleCookiewsgi_environ
- the raw WSGI environ handed down from the server
- class pigwig.Response(body: str | bytes | Iterator[bytes] | None = None, code: int = 200, content_type: str = 'text/plain', location: str | None = None, extra_headers: list[tuple[str, str]] | None = None)[source]¶
every route handler should return an instance of this class (or raise an
exceptions.HTTPException
)- Parameters:
body –
if
None
, the response body is emptyif a
str
, the response body is UTF-8 encodedif a
bytes
, the response body is sent as-isif a generator, the response streams the yielded bytes
code (int) – HTTP status code; the “reason phrase” is generated automatically from http.client.responses
content_type – sets the Content-Type header
location – if not
None
, sets the Location header. you must still specify a 3xx codeextra_headers – if not
None
, an iterable of extra header 2-tuples to be sent
has the following instance attrs:
code
body
headers
- a list of 2-tuples