No person arrested upon such warrant shall be delivered over to the agent whom the executive authority demanding him has appointed to receive him unless he is first taken forthwith before a judge of any court having criminal jurisdiction in this state, who shall inform him of the demand made for his surrender and of the crime with which he is charged, and that he has the right to demand and procure legal counsel; and if the prisoner or his counsel states that he or they desire to test the legality of his arrest, the judge of such court shall fix a reasonable time to be allowed him within which to apply for a writ of habeas corpus. When such writ is applied for, notice thereof, and of the time and place of hearing thereon, shall be given to the state’s attorney 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.