No person arrested upon a warrant shall be delivered over to the agent whom the executive authority demanding the person has appointed to receive the person, unless the person has been informed of the demand made for surrender and of the crime with which the person is charged, and that the person has the right to demand legal counsel. If the prisoner, the prisoner’s friends or counsel shall state that the person or they desire to test the legality of the arrest, the prisoner shall be taken forthwith before a judge of a court of record in this state, who shall fix a reasonable time to be allowed the prisoner within which to apply for a writ of habeas corpus. When the writ is applied for, notice thereof, and of the time and place of hearing thereon, shall be given to the public prosecuting officer of the county in which the arrest is made and in which the accused is in custody, and to the agent of the demanding state.