Skip to content

Commit 792b522

Browse files
committed
fix: getting cppcheck version throws an exception
1 parent 7ac7249 commit 792b522

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/command/UpdateCheckCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
public class UpdateCheckCommand {
1717

18-
private static final String UPDATE_URL = "http://cppcheck.sourceforge.net/version.txt";
18+
private static final String UPDATE_URL = "https://cppcheck.sourceforge.net/version.txt";
1919

2020
public UpdateCheckCommand() {
2121

com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/utils/HttpClientService.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,38 @@ private boolean isProxiesEnabled() {
9292
return false;
9393
}
9494

95-
/* (non-Javadoc)
96-
* @see com.googlecode.cppcheclipse.core.utils.IHttpClient#executeGetRequest(java.net.URL)
97-
*/
98-
public InputStream executeGetRequest(URL url) throws URISyntaxException, IOException {
99-
Proxy proxy = getProxy(url.toURI());
100-
95+
private HttpURLConnection newGetRequest(URL url, Proxy proxy) throws IOException {
10196
HttpURLConnection connection;
102-
if (proxy != null)
97+
if (proxy != null)
10398
connection = (HttpURLConnection) url.openConnection(proxy);
104-
else
99+
else
105100
connection = (HttpURLConnection) url.openConnection();
106101
connection.setRequestMethod("GET");
107102
connection.setDoOutput(true);
108103
connection.setReadTimeout(10000);
104+
return connection;
105+
}
106+
107+
/* (non-Javadoc)
108+
* @see com.googlecode.cppcheclipse.core.utils.IHttpClient#executeGetRequest(java.net.URL)
109+
*/
110+
public InputStream executeGetRequest(URL url) throws URISyntaxException, IOException {
111+
Proxy proxy = getProxy(url.toURI());
112+
113+
HttpURLConnection connection = newGetRequest(url, proxy);
114+
115+
if (connection.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP ||
116+
connection.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM) {
117+
String newUrl = connection.getHeaderField("Location");
118+
connection = newGetRequest(new URL(newUrl), proxy);
119+
}
120+
109121
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
110-
throw new IOException("Wrong response code: "
111-
+ connection.getResponseMessage());
122+
throw new IOException("Wrong response code: " + connection.getResponseMessage());
112123
}
113124
return connection.getInputStream();
114125
}
115-
126+
116127
/**
117128
* Binds the {@link IProxyService} service reference.
118129
*

0 commit comments

Comments
 (0)