res can be nil if there is a timeout on send_request_cgi, please check res against nil before accessing the code or headers fields.