§ 7004. Content of writ. (a) For whom issued. The writ shall be issued on behalf of the state, and where issued upon the petition of a private person, it shall show that it was issued upon his relation. (b) To whom directed. The writ shall be directed to, and the respondent shall be, the person having custody of the person detained. (c) Before whom returnable. A writ to secure the discharge of a person from a state institution shall be made returnable before a justice of the supreme court or a county judge being or residing within the county in which the person is detained; if there is no such judge it shall be made returnable before the nearest accessible supreme court justice or county judge. In all other cases, the writ shall be made returnable in the county where it was issued, except that where the petition was made to the supreme court or to a supreme court justice outside the county in which the person is detained, such court or justice may make the writ returnable before any judge authorized to issue it in the county of detention. (d) When returnable. The writ may be made returnable forthwith or on any day or time certain, as the case requires. (e) Expenses; undertaking. A court issuing a writ directed to any person other than a public officer may require the petitioner to pay the charges of bringing up the person detained and to deliver an undertaking to the person having him in custody, in an amount fixed by the court, to pay the charges for taking back the person detained if he should be remanded. Service of the writ shall not be complete until such charge is paid or tendered and such undertaking is delivered.