Main address now redirects to /server on HTTP servers #668

This commit is contained in:
Rsl1122 2018-08-05 11:01:09 +03:00
parent addd463406
commit 0b6d6cb687
3 changed files with 21 additions and 5 deletions

View File

@ -44,9 +44,14 @@ public class ResponseHandler extends TreePageHandler {
ServerPageHandler serverPageHandler = new ServerPageHandler();
registerPage("network", serverPageHandler);
registerPage("server", serverPageHandler);
if (webServer.isAuthRequired()) {
registerPage("", new RootPageHandler(this));
}
registerPage("", webServer.isAuthRequired()
? new RootPageHandler(this)
: new PageHandler() {
@Override
public Response getResponse(Request request, List<String> target) {
return new RedirectResponse("/server");
}
});
}
public void registerWebAPIPages() {

View File

@ -1,5 +1,10 @@
package com.djrapitops.plan.system.webserver.response;
import com.djrapitops.plan.system.locale.Locale;
import com.sun.net.httpserver.HttpExchange;
import java.io.IOException;
/**
* @author Rsl1122
* @since 3.5.2
@ -8,6 +13,12 @@ public class RedirectResponse extends Response {
public RedirectResponse(String direct) {
super.setHeader("HTTP/1.1 302 Found");
super.setContent("Location: " + direct);
super.setContent(direct);
}
@Override
public void send(HttpExchange exchange, Locale locale) throws IOException {
responseHeaders.set("Location", getContent());
super.send(exchange, locale);
}
}

View File

@ -20,7 +20,7 @@ public abstract class Response {
private String header;
private String content;
private Headers responseHeaders;
protected Headers responseHeaders;
public Response(ResponseType type) {
this.type = type.get();