Skip to content

Requests

Request handling and per-request state management.

Request

The main request class that wraps the raw Gemini request and provides convenient accessors.

Request

Request(
    raw_request: GeminiRequest, app: Xitzin | None = None
)

Wraps a Nauyaca GeminiRequest with convenient accessors.

Handlers receive this object as their first argument.

Example

@app.gemini("/user/{username}") def profile(request: Request, username: str): cert_id = request.client_cert_fingerprint viewer = cert_id[:16] if cert_id else 'anonymous' return f"# {username}'s Profile\n\nViewing as: {viewer}"

Attributes:

Name Type Description
app Xitzin

The Xitzin application instance.

state RequestState

Arbitrary state storage for this request.

path str

The URL path component.

query str

The decoded query string (user input).

raw_query str

The raw (URL-encoded) query string.

client_cert Certificate | None

The client's TLS certificate, if provided.

client_cert_fingerprint str | None

SHA-256 fingerprint of client certificate.

Source code in src/xitzin/requests.py
def __init__(self, raw_request: GeminiRequest, app: Xitzin | None = None) -> None:
    self._raw_request = raw_request
    self._app = app
    self._state = RequestState()

app property

app: Xitzin

The Xitzin application handling this request.

client_cert property

client_cert: Certificate | None

The client's TLS certificate, if provided.

client_cert_fingerprint property

client_cert_fingerprint: str | None

SHA-256 fingerprint of the client certificate.

hostname property

hostname: str

The server hostname from the URL.

path property

path: str

The URL path component.

port property

port: int

The server port from the URL.

query property

query: str

The decoded query string.

Gemini uses URL query strings for user input (status 10/11 flow). This property decodes the query string for convenient access.

raw_query property

raw_query: str

The raw (URL-encoded) query string.

raw_url property

raw_url: str

The original URL from the request.

remote_addr property

remote_addr: str | None

The client's IP address, if available.

Note: This property returns the client IP address if it was set by the server or middleware. In CGI context, this is passed to scripts via the REMOTE_ADDR environment variable.

Returns:

Type Description
str | None

The client IP address string, or None if not available.

state property

state: RequestState

Arbitrary state storage for this request.

url property

url: str

The full normalized URL.

RequestState

Per-request state storage for passing data between middleware and handlers.

RequestState

Arbitrary state storage for a request.

Middleware and handlers can store arbitrary data here.

Example

request.state.user = get_current_user() request.state.start_time = time.time()