code: private HttpURLConnection openConnection(URL url) throws IOException {
          URLConnection urlConnection = url.openConnection();
          if (!(urlConnection instanceof HttpURLConnection)) {
              throw new IllegalStateException("Connection should be an HttpURLConnection");
          }
          return (HttpURLConnection) urlConnection;
      }
docs: Opens and returns a connection to the given URL.
  
  @param url   the URL to open a connection to
  @return the opened connection
  @throws IOException in case of I/O errors