Skip to content

Commit

Permalink
https in request to node mirros
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasmoreau committed May 17, 2022
1 parent 2252b72 commit 23aaa8b
Showing 1 changed file with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.vamdc.portal.session.preview;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -45,6 +46,22 @@ private URL getQuery(URL mirror) {

return result;
}

private HttpURLConnection getHttpURLConnection(URL url) throws IOException {
HttpURLConnection connection = null;


//http request
if (!url.getProtocol().equals("https")) {
connection = (HttpURLConnection) url.openConnection();
}
//https request
else {
connection = (HttpsURLConnection) url.openConnection();
}

return connection;
}

/**
* Send a HEAD request to a node by testing its mirrors
Expand All @@ -54,21 +71,19 @@ public HttpHeadResponse call() throws Exception {
HttpHeadResponse response = null;
for (URL mirror : mirrors) {
HttpURLConnection connection = null;
URL queryURL = getQuery(mirror);

//http request
if (!mirror.getProtocol().equals("https")) {
connection = (HttpURLConnection) queryURL.openConnection();
}
//https request
else {
connection = (HttpsURLConnection) queryURL.openConnection();
}

connection = this.getHttpURLConnection(getQuery(mirror));
connection.setRequestMethod("HEAD");
connection.setReadTimeout(Settings.HTTP_HEAD_TIMEOUT.getInt());

/*if(connection.getResponseCode() == 301 || connection.getResponseCode() == 302) {
connection.disconnect();
String newUrl = connection.getHeaderField("Location");
System.out.println("### try new url : " + newUrl);
connection = this.getHttpURLConnection(new URL(newUrl));
connection.setRequestMethod("HEAD");
connection.setReadTimeout(Settings.HTTP_HEAD_TIMEOUT.getInt());
}*/
response = new HttpHeadResponse(ivoaID, connection);

if (response.isOk())
return response;
}
Expand Down

0 comments on commit 23aaa8b

Please sign in to comment.