private HttpResponse buildHttpResponse(HttpURLConnection conn, byte[] bytes) {
        try {
            if (conn.getHeaderFields() != null) {
                Map<String, List<String>> headers = new HashMap<String, List<String>>(conn.getHeaderFields());
                logger.d("Http response headers:", headers);
                if (config.isResponseHeadersInLowerCase()) {
                    Map<String, List<String>> headersLowerCase = new HashMap<String, List<String>>();
                    for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
                        String key = entry.getKey();
                        if (key == null) continue; // ignore the status line whose key is null
                        List<String> values = entry.getValue();
                        headersLowerCase.put(key.toLowerCase(), values);
                        headers = headersLowerCase;
                    }
                }
                return new HttpResponse(conn.getResponseCode(), conn.getURL().toString(), headers, bytes);
            } else {
                return new HttpResponse(conn.getResponseCode(), conn.getURL().toString(), null, bytes);
            }
        } catch (IOException e) {
            return new HttpResponse(e);
        }
    }