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 of PigWig

  • method - the request method/verb (GET, POST, etc.)

  • path - WSGI environ PATH_INFO (/foo/bar)

  • query - dict of parsed query string. duplicate keys appear as lists

  • headers - HTTPHeaders of the headers

  • body - dict of parsed body content. see PigWig.content_handlers for a list of supported content types

  • cookies - an instance of http.cookies.SimpleCookie

  • wsgi_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 empty

    • if a str, the response body is UTF-8 encoded

    • if a bytes, the response body is sent as-is

    • if 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 code

  • extra_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

class pigwig.request_response.HTTPHeaders(dict=None, /, **kwargs)[source]

behaves like a regular dict but casefolds the keys