[14] 
This specification defines [[manakai]]'s extensions to the [[PSGI]] specification.

* Transport integration

[6] To construct the [[environment]], the rules to [[prepare metavariables]]
[MUST[MUST]] be used with [VAR[scheme key name]] [CODE[psgi.url_scheme]].

* Server state API

[1] A [[PSGI server]] [MAY[MAY]] set a [[value][hash value]] for the 
[[key][hash key]] [DFN[[CODE[manakai.server.state]]]] in the [[environment]].
If the [[key][hash key]] [CODE[exists]] and its [[value][hash value]] is [CODE[defined]],
the value [MUST[MUST]] be a [[server state object]].

[2] A [DFN[server state object]] is a [[PSGI server]] dependent [[object]].

[8] Every invocation of a [[PSGI application]] within the same 
[[server session]] [MUST[MUST]] have the same [CODE[manakai.server.state]]
[[value][hash value]] in their [[environments][environment]].
How to determine the [DFN[server session]] is [[PSGI server]] dependent.

[EG[
[9] Typically, all the invocations of a [[PSGI application]] in a single worker process
of a preforking [[PSGI server]] implementation live in the same [[server session]].
]EG]

[10] The [[PSGI server]] [MAY[MAY]] provide a way for the [[application]] to specify
the [[server state object]] for a [[server session]].
It [SHOULD[SHOULD]] also define a way to cleanly discard the [[server state object]].

[EG[
[12] For example, the [[PSGI server]] can invoke the [CODE[destroy]]
[[method]] of the [[server state object]] just before the [[server session]]
is discarded.
]EG]

;;
[13] 
It is intended that the [[application]] can use the [[server state object]]
to keep references to objects which live longer than a single [[PSGI application]]
invocation, such as database connection client objects,
and can discard them safely when the server is shutdown.

* Terminology

[4] 
This specification depends on the [CITE[Infra Standard]].

[7] 
The terms
[DFN[hash key]],
[DFN[hash value]],
[DFN[[CODE[exists]]]],
[DFN[[CODE[defined]]]],
and
[DFN[object]]
are [[Perl]] terms.

[3] The terms
[DFN[PSGI server]],
[DFN[PSGI application]],
[DFN[environment]],
and
[DFN[[CODE[psgi.url_scheme]]]]
are defined by the [[PSGI]] specification.

[5] The term
[DFN[prepare metavariables]]
is defined by the [CITE[Web Transport Processing]] specification.

[11] 
For the purpose of this specification, an [DFN[application]] is an
application server program which has a [[PSGI application]].

* License

[15] 
Per CC0 <https://creativecommons.org/publicdomain/zero/1.0/>, 
to the extent possible under law, the author of this specification 
has waived all copyright and related or neighboring rights to this specification.

* Notes