Skip to content

Commit

Permalink
[JENKINS-38185] Always follow redirects for DownloadService
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-beck committed Jul 28, 2017
1 parent e952bba commit 8d7f9b5
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions core/src/main/java/hudson/model/DownloadService.java
Expand Up @@ -40,7 +40,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -169,7 +171,12 @@ public Downloadable getById(String id) {
*/
@Restricted(NoExternalUse.class)
public static String loadJSON(URL src) throws IOException {
try (InputStream is = ProxyConfiguration.open(src).getInputStream()) {
URLConnection con = ProxyConfiguration.open(src);
if (con instanceof HttpURLConnection) {
// prevent problems from misbehaving plugins disabling redirects by default
((HttpURLConnection) con).setInstanceFollowRedirects(true);
}
try (InputStream is = con.getInputStream()) {
String jsonp = IOUtils.toString(is, "UTF-8");
int start = jsonp.indexOf('{');
int end = jsonp.lastIndexOf('}');
Expand All @@ -189,7 +196,12 @@ public static String loadJSON(URL src) throws IOException {
*/
@Restricted(NoExternalUse.class)
public static String loadJSONHTML(URL src) throws IOException {
try (InputStream is = ProxyConfiguration.open(src).getInputStream()) {
URLConnection con = ProxyConfiguration.open(src);
if (con instanceof HttpURLConnection) {
// prevent problems from misbehaving plugins disabling redirects by default
((HttpURLConnection) con).setInstanceFollowRedirects(true);
}
try (InputStream is = con.getInputStream()) {
String jsonp = IOUtils.toString(is, "UTF-8");
String preamble = "window.parent.postMessage(JSON.stringify(";
int start = jsonp.indexOf(preamble);
Expand Down

0 comments on commit 8d7f9b5

Please sign in to comment.