make more use of the new ServletRequest interface methodes

getScheme, getServerPort (in QuickCrawlLink_p & YaCyDefaultServlet)
pull/93/head
reger 9 years ago
parent 395f2e8946
commit d631fbc019

@ -39,7 +39,6 @@ import net.yacy.cora.protocol.ClientIdentification;
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.util.NumberTools;
import net.yacy.crawler.data.CrawlProfile;
import net.yacy.crawler.retrieval.Request;
import net.yacy.search.Switchboard;
@ -62,16 +61,15 @@ public class QuickCrawlLink_p {
final serverObjects prop = new serverObjects();
final Switchboard sb = (Switchboard) env;
int port = sb.getConfigInt("port", 8090);
int port;
// get the http host header
if (header.containsKey(HeaderFramework.HOST)) {
final String hostSocket = header.get(HeaderFramework.HOST);
final int pos = hostSocket.indexOf(':', 0);
if (pos != -1) {
port = NumberTools.parseIntDecSubstring(hostSocket, pos + 1);
}
port = header.getServerPort();
} else {
port = sb.getConfigInt("port", 8090);
}
prop.put("mode_host", Domains.LOCALHOST);
prop.put("mode_port", port);

@ -711,23 +711,11 @@ public class YaCyDefaultServlet extends HttpServlet {
public static String getContext(final RequestHeader header, final Switchboard sb) {
String protocol = "http";
String hostAndPort = null;
if(header != null) {
if(hostAndPort == null){
hostAndPort = header.get(HeaderFramework.HOST);
/* We can try here to figure out if we are using http or https, relying on the port used.
* This only works port is not standard (80 or 443) : if so HeaderFramework.X_YACY_REQUEST_SCHEME will be more reliable */
final String sslport;
if(sb != null) {
sslport = ":" + sb.getConfigInt("port.ssl", 8443);
} else {
sslport = ":8443";
}
if (hostAndPort != null && hostAndPort.endsWith(sslport)) { // connection on ssl port, use https protocol
protocol = "https";
}
}
if (header != null) {
hostAndPort = header.get(HeaderFramework.HOST);
protocol = header.getScheme();
}
/* Host and port still null : let's use the default local ones */
if (hostAndPort == null) {
if(sb != null) {

Loading…
Cancel
Save