A court, justice or judge entertaining an application for a writ of habeas corpus shall forthwith award the writ or issue an order directing the respondent to show cause why the writ should not be granted, unless it appears from the application that the applicant or person detained is not entitled thereto.
The writ, or order to show cause shall be directed to the person having custody of the person detained. It shall be returned within three days unless for good cause additional time, not exceeding twenty days, is allowed.
The person to whom the writ or order is directed shall make a return certifying the true cause of the detention.
When the writ or order is returned a day shall be set for hearing, not more than five days after the return unless for good cause additional time is allowed.
Unless the application for the writ and the return present only issues of law the person to whom the writ is directed shall be required to produce at the hearing the body of the person detained.
The applicant or the person detained may, under oath, deny any of the facts set forth in the return or allege any other material facts.
The return and all suggestions made against it may be amended, by leave of court, before or after being filed.
The court shall summarily hear and determine the facts, and dispose of the matter as law and justice require.