code: private HttpURLConnection configureURLConnection(HttpMethod method, String urlString, Map<String, String> httpHeaders, int contentLength) throws IOException {
  
          preconditionNotNull(method, "method cannot be null");
          preconditionNotNull(urlString, "urlString cannot be null");
          preconditionNotNull(httpHeaders, "httpHeaders cannot be null");
  
          HttpURLConnection connection = getHttpURLConnection(urlString);
          connection.setRequestMethod(method.name());
  
          Map<String, String> headerKeyValues = new HashMap<>(defaultHttpHeaders);
  
          headerKeyValues.putAll(httpHeaders);
  
          for (Map.Entry<String, String> entry : headerKeyValues.entrySet()) {
              connection.setRequestProperty(entry.getKey(), entry.getValue());
              log.trace("Header request property: key='{}', value='{}'", entry.getKey(), entry.getValue());
          }
  
          // Perform additional configuration for POST
          if (contentLength > 0) {
              connection.setDoOutput(true);
              connection.setDoInput(true);
          }
          connection.setRequestProperty("Content-Length", Integer.toString(contentLength));
  
          return connection;
      }
docs: Provides an internal convenience method to allow easy overriding by test classes
  
  @param method        The HTTP method (e.g. GET, POST etc)
  @param urlString     A string representation of a URL
  @param httpHeaders   The HTTP headers (will override the defaults)
  @param contentLength The Content-Length request property
  @return An HttpURLConnection based on the given parameters
  @throws IOException If something goes wrong