Skip to content

Commit

Permalink
Add HEAD request support #1 and release 1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Oct 4, 2018
1 parent d9f4fc6 commit 53e99b4
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<groupId>org.panda-lang</groupId>
<artifactId>nanomaven</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/panda_lang/nanomaven/NanoMaven.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.panda_lang.nanomaven.console.NanoConsole;
import org.panda_lang.nanomaven.console.commands.HelpCommand;
import org.panda_lang.nanomaven.maven.NanoMavenCli;
import org.panda_lang.nanomaven.server.NanoHttpdServer;
import org.panda_lang.nanomaven.server.NanoHttpServer;
import org.panda_lang.nanomaven.server.auth.NanoProjectsManager;
import org.panda_lang.nanomaven.server.auth.NanoUsersManager;
import org.panda_lang.nanomaven.util.DirectoryUtils;
Expand All @@ -37,21 +37,21 @@ public class NanoMaven {
private NanoMavenConfiguration configuration;
private NanoRepositoryManager repositoryManager;
private NanoProjectsManager projectsManager;
private NanoHttpdServer httpdServer;
private NanoHttpServer httpServer;
private NanoMavenCli mavenCli;
private boolean stopped;
private long uptime;

private void initialize() {
this.configuration = new NanoMavenConfiguration();
configuration.load();

this.console = new NanoConsole(this);
console.hook();

this.workspace = new NanoWorkspace();
workspace.prepare();

this.configuration = new NanoMavenConfiguration();
configuration.load();

this.usersManager = new NanoUsersManager();
usersManager.load(configuration);

Expand All @@ -61,7 +61,7 @@ private void initialize() {
this.projectsManager = new NanoProjectsManager(usersManager);
projectsManager.load();

this.httpdServer = new NanoHttpdServer(this);
this.httpServer = new NanoHttpServer(this);
this.mavenCli = new NanoMavenCli(this);
}

Expand All @@ -73,7 +73,7 @@ public void launch() {
this.uptime = System.currentTimeMillis();

try {
httpdServer.start();
httpServer.start();

Thread shutdownHook = new Thread(this::shutdown);
Runtime.getRuntime().addShutdownHook(shutdownHook);
Expand All @@ -95,7 +95,7 @@ public void shutdown() {
this.stopped = true;

getLogger().info("Shutting down...");
httpdServer.stop();
httpServer.stop();

getLogger().info("Saving users...");
usersManager.save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

public class NanoMavenConstants {

public static final String VERSION = "1.0.5";
public static final String VERSION = "1.0.6";

public static final boolean INTERNAL_DEBUG = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@

import java.io.IOException;

public class NanoHttpdServer extends NanoHTTPD {
public class NanoHttpServer extends NanoHTTPD {

private final NanoMaven nanoMaven;
private final NanoFrontRouter frontRouter;
private final NanoPanelRouter panelRouter;
private final NanoRepositoryRouter repositoryRouter;

public NanoHttpdServer(NanoMaven nanoMaven) {
public NanoHttpServer(NanoMaven nanoMaven) {
super(nanoMaven.getConfiguration().getPort());

this.nanoMaven = nanoMaven;
this.frontRouter = new NanoFrontRouter(nanoMaven);
this.panelRouter = new NanoPanelRouter(nanoMaven);
this.repositoryRouter = new NanoRepositoryRouter(nanoMaven);
this.repositoryRouter = new NanoRepositoryRouter();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

public interface NanoRouter {

NanoHTTPD.Response serve(NanoHttpdServer server, NanoHTTPD.IHTTPSession session) throws Exception;
NanoHTTPD.Response serve(NanoHttpServer server, NanoHTTPD.IHTTPSession session) throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import fi.iki.elonen.NanoHTTPD;
import org.panda_lang.nanomaven.NanoMaven;
import org.panda_lang.nanomaven.server.NanoHttpdServer;
import org.panda_lang.nanomaven.server.NanoHttpServer;
import org.panda_lang.nanomaven.server.NanoRouter;

public class NanoFrontRouter implements NanoRouter {
Expand All @@ -28,7 +28,7 @@ public NanoFrontRouter(NanoMaven nanoMaven) {
}

@Override
public NanoHTTPD.Response serve(NanoHttpdServer server, NanoHTTPD.IHTTPSession session) {
public NanoHTTPD.Response serve(NanoHttpServer server, NanoHTTPD.IHTTPSession session) {
return NanoHTTPD.newFixedLengthResponse("#TODO");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import fi.iki.elonen.NanoHTTPD;
import org.panda_lang.nanomaven.NanoMaven;
import org.panda_lang.nanomaven.server.NanoHttpdServer;
import org.panda_lang.nanomaven.server.NanoHttpServer;
import org.panda_lang.nanomaven.server.NanoRouter;

public class NanoPanelRouter implements NanoRouter {
Expand All @@ -28,7 +28,7 @@ public NanoPanelRouter(NanoMaven nanoMaven) {
}

@Override
public NanoHTTPD.Response serve(NanoHttpdServer server, NanoHTTPD.IHTTPSession session) {
public NanoHTTPD.Response serve(NanoHttpServer server, NanoHTTPD.IHTTPSession session) {
return NanoHTTPD.newFixedLengthResponse("#TODO");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
import fi.iki.elonen.NanoHTTPD;
import fi.iki.elonen.NanoHTTPD.Response.Status;
import org.panda_lang.nanomaven.NanoMaven;
import org.panda_lang.nanomaven.server.NanoHttpdServer;
import org.panda_lang.nanomaven.server.NanoHttpServer;
import org.panda_lang.nanomaven.server.NanoRouter;

import java.io.ByteArrayInputStream;

public class NanoRepositoryRouter implements NanoRouter {

private final NanoMaven nanoMaven;
private final NanoRepositoryRouterGet get;
private final NanoRepositoryRouterPut put;

public NanoRepositoryRouter(NanoMaven nanoMaven) {
this.nanoMaven = nanoMaven;
public NanoRepositoryRouter() {
this.get = new NanoRepositoryRouterGet();
this.put = new NanoRepositoryRouterPut();
}

@Override
public NanoHTTPD.Response serve(NanoHttpdServer server, NanoHTTPD.IHTTPSession session) {
public NanoHTTPD.Response serve(NanoHttpServer server, NanoHTTPD.IHTTPSession session) {
System.out.println(session.getUri() + " " + session.getMethod().name());

try {
Expand All @@ -46,10 +46,12 @@ public NanoHTTPD.Response serve(NanoHttpdServer server, NanoHTTPD.IHTTPSession s
}
}

public NanoHTTPD.Response serveOrCatch(NanoHttpdServer server, NanoHTTPD.IHTTPSession session) throws Exception {
public NanoHTTPD.Response serveOrCatch(NanoHttpServer server, NanoHTTPD.IHTTPSession session) throws Exception {
switch (session.getMethod()) {
case GET:
return get.serve(server, session);
case HEAD:
return toHeadResponse(get.serve(server, session));
case PUT:
return put.serve(server, session);
default:
Expand All @@ -58,4 +60,10 @@ public NanoHTTPD.Response serveOrCatch(NanoHttpdServer server, NanoHTTPD.IHTTPSe
}
}

private NanoHTTPD.Response toHeadResponse(NanoHTTPD.Response response) {
response.setData(new ByteArrayInputStream(new byte[0]));
response.setRequestMethod(NanoHTTPD.Method.HEAD);
return response;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import fi.iki.elonen.NanoHTTPD;
import org.panda_lang.nanomaven.NanoMaven;
import org.panda_lang.nanomaven.server.NanoHttpdServer;
import org.panda_lang.nanomaven.server.NanoHttpServer;
import org.panda_lang.nanomaven.server.NanoRouter;
import org.panda_lang.nanomaven.workspace.repository.NanoRepositoryProject;
import org.panda_lang.nanomaven.workspace.repository.NanoRepository;
Expand All @@ -34,7 +34,7 @@
public class NanoRepositoryRouterGet implements NanoRouter {

@Override
public NanoHTTPD.Response serve(NanoHttpdServer server, NanoHTTPD.IHTTPSession session) {
public NanoHTTPD.Response serve(NanoHttpServer server, NanoHTTPD.IHTTPSession session) {
NanoMaven nanoMaven = server.getNanoMaven();
NanoRepositoryManager repositoryManager = nanoMaven.getRepositoryManager();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.commons.io.FileUtils;
import org.panda_lang.nanomaven.NanoMaven;
import org.panda_lang.nanomaven.NanoMavenConstants;
import org.panda_lang.nanomaven.server.NanoHttpdServer;
import org.panda_lang.nanomaven.server.NanoHttpServer;
import org.panda_lang.nanomaven.server.NanoRouter;
import org.panda_lang.nanomaven.server.auth.NanoProject;
import org.panda_lang.nanomaven.server.auth.NanoProjectsManager;
Expand All @@ -47,7 +47,7 @@
public class NanoRepositoryRouterPut implements NanoRouter {

@Override
public NanoHTTPD.Response serve(NanoHttpdServer server, NanoHTTPD.IHTTPSession session) throws Exception {
public NanoHTTPD.Response serve(NanoHttpServer server, NanoHTTPD.IHTTPSession session) throws Exception {
NanoMaven nanoMaven = server.getNanoMaven();
NanoMavenConfiguration configuration = nanoMaven.getConfiguration();

Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/panda_lang/nanomaven/util/AnsiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class AnsiUtils {
public static final Object RESET = new Object();

public static String translate(Object... elements) {

Ansi ansi = Ansi.ansi();

for (Object element : elements) {
Expand Down

0 comments on commit 53e99b4

Please sign in to comment.