code: public static URLConnection getConnection(URL url, Map inCookies, boolean input, boolean output, boolean cache, boolean allowAllCerts) throws IOException
      {
          URLConnection c = url.openConnection();
          c.setRequestProperty("Accept-Encoding", "gzip, deflate");
          c.setAllowUserInteraction(false);
          c.setDoOutput(output);
          c.setDoInput(input);
          c.setUseCaches(cache);
          c.setReadTimeout(220000);
          c.setConnectTimeout(45000);
  
          String ref = getReferrer();
          if (StringUtilities.hasContent(ref))
          {
              c.setRequestProperty("Referer", ref);
          }
          String agent = getUserAgent();
          if (StringUtilities.hasContent(agent))
          {
              c.setRequestProperty("User-Agent", agent);
          }
  
          if (c instanceof HttpURLConnection)
          {   // setFollowRedirects is a static (global) method / setting - resetting it in case other code changed it?
              HttpURLConnection.setFollowRedirects(true);
          }
  
          if (c instanceof HttpsURLConnection && allowAllCerts)
          {
              try
              {
                  setNaiveSSLSocketFactory((HttpsURLConnection) c);
              }
              catch(Exception e)
              {
                  LOG.warn("Could not access '" + url.toString() + "'", e);
              }
          }
  
          // Set cookies in the HTTP header
          if (inCookies != null)
          {   // [optional] place cookies (JSESSIONID) into HTTP headers
              setCookies(c, inCookies);
          }
          return c;
      }
docs: Gets a connection from a url.  All getConnection calls should go through this code.
  @param inCookies Supply cookie Map (received from prior setCookies calls from server)
  @param input boolean indicating whether this connection will be used for input
  @param output boolean indicating whether this connection will be used for output
  @param cache boolean allow caching (be careful setting this to true for non-static retrievals).
  @return URLConnection established URL connection.