Probably should use TFTP actually

This commit is contained in:
Norbi Peti 2017-06-27 23:06:01 +02:00
parent 4c4301d2d9
commit 897372f098
3 changed files with 39 additions and 1 deletions

View file

@ -111,6 +111,9 @@ public class ButtonWebsiteModule extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
addPage(new IndexPage()); addPage(new IndexPage());
addPage(new AutoUpdatePage());
addPage(new LoginPage());
addPage(new ProfilePage());
TBMCCoreAPI.RegisterUserClass(WebUser.class); TBMCCoreAPI.RegisterUserClass(WebUser.class);
Bukkit.getScheduler().runTaskAsynchronously(this, () -> { Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
this.getLogger().info("Starting webserver..."); this.getLogger().info("Starting webserver...");

View file

@ -0,0 +1,35 @@
package buttondevteam.website.page;
import java.io.IOException;
import java.util.stream.Collectors;
import com.sun.net.httpserver.HttpExchange;
import buttondevteam.website.io.IOHelper;
import buttondevteam.website.io.Response;
public class AutoUpdatePage extends Page {
@Override
public String GetName() {
return "autoupdate";
}
@Override
public Response handlePage(HttpExchange exchange) {
if (exchange.getRequestHeaders().containsKey("Expect")
&& exchange.getRequestHeaders().get("Expect").contains("100-continue"))
try {
exchange.sendResponseHeaders(100, -1);
exchange.getResponseBody().close();
} catch (IOException e1) {
e1.printStackTrace();
}
return new Response(200,
"Headers:\n" + exchange.getRequestHeaders().entrySet().stream()
.map(e -> e.getKey() + ": " + e.getValue().stream().collect(Collectors.joining(" ")))
.collect(Collectors.joining("\n")) + "\nPOST: " + IOHelper.GetPOST(exchange),
exchange);
}
}

View file

@ -22,7 +22,7 @@ public abstract class Page implements HttpHandler {
if (exchange.getRequestURI().getPath().equals("/" + GetName())) if (exchange.getRequestURI().getPath().equals("/" + GetName()))
IOHelper.SendResponse(handlePage(exchange)); IOHelper.SendResponse(handlePage(exchange));
else { else {
IOHelper.SendResponse(404, "404 Not found", exchange); IOHelper.SendResponse(404, "404 Not found: " + exchange.getRequestURI().getPath(), exchange);
} }
} catch (Exception e) { } catch (Exception e) {
TBMCCoreAPI.SendException("Internal Server Error in ButtonWebsiteModule!", e); TBMCCoreAPI.SendException("Internal Server Error in ButtonWebsiteModule!", e);