IDEA-133305 (support in HTTP request builder)
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Thu, 4 Dec 2014 12:16:26 +0000 (13:16 +0100)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Thu, 4 Dec 2014 12:16:26 +0000 (13:16 +0100)
platform/platform-impl/src/com/intellij/util/io/HttpRequests.java

index 412f22741e422b984ab2021632401828f82bf76f..4febe81f3da2587d9adc844cb6afb5c643f23824 100644 (file)
@@ -17,6 +17,7 @@ package com.intellij.util.io;
 
 import com.intellij.ide.IdeBundle;
 import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.util.net.HttpConfigurable;
 import org.jetbrains.annotations.NotNull;
 
@@ -54,6 +55,7 @@ public final class HttpRequests {
     private int myTimeout = HttpConfigurable.READ_TIMEOUT;
     private int myRedirectLimit = HttpConfigurable.REDIRECT_LIMIT;
     private boolean myGzip = true;
+    private boolean myForceHttps = false;
 
     private RequestBuilder(@NotNull String url) {
       myUrl = url;
@@ -83,6 +85,12 @@ public final class HttpRequests {
       return this;
     }
 
+    @NotNull
+    public RequestBuilder forceHttps(boolean forceHttps) {
+      myForceHttps = forceHttps;
+      return this;
+    }
+
     public <T> T connect(@NotNull RequestProcessor<T> processor) throws IOException {
       return process(this, processor);
     }
@@ -154,6 +162,10 @@ public final class HttpRequests {
   private static URLConnection openConnection(RequestBuilder builder) throws IOException {
     String url = builder.myUrl;
 
+    if (builder.myForceHttps && StringUtil.startsWith(url, "http:")) {
+      url = "https:" + url.substring(5);
+    }
+
     for (int i = 0; i < builder.myRedirectLimit; i++) {
       URLConnection connection;
       if (ApplicationManager.getApplication() == null) {