X-Git-Url: https://git.cweiske.de/louyapi.git/blobdiff_plain/ff5fd2eaa9d7462ed58c9bb7865808f43c432594..a2c5869257d35627417dae0702b7b9d57a2cb970:/src/main/java/de/cweiske/ouya/louyapi/HttpServer.java diff --git a/src/main/java/de/cweiske/ouya/louyapi/HttpServer.java b/src/main/java/de/cweiske/ouya/louyapi/HttpServer.java index 2e5779a..5682805 100644 --- a/src/main/java/de/cweiske/ouya/louyapi/HttpServer.java +++ b/src/main/java/de/cweiske/ouya/louyapi/HttpServer.java @@ -7,6 +7,8 @@ import android.util.Log; import java.io.IOException; import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; import fi.iki.elonen.NanoHTTPD; @@ -28,6 +30,23 @@ public class HttpServer extends NanoHTTPD { */ public Response serve(IHTTPSession session) { String path = session.getUri(); + Log.d(TAG, "serve: " + path); + //this happens with "//agreements/marketplace.html". remove double slash. + if (path.startsWith("//")) { + path = path.substring(1); + } + + if (session.getMethod() == Method.POST || session.getMethod() == Method.PUT) { + Map parameters = new HashMap(); + try { + session.parseBody(parameters); + } catch (Exception e) { + //we do not care about the content + //we only parse the body to prevent errors, see + // https://github.com/NanoHttpd/nanohttpd/issues/356 + } + } + InputStream content; if (path.equals("/api/v1/status") || path.equals("/generate_204")) { @@ -86,6 +105,10 @@ public class HttpServer extends NanoHTTPD { return newFixedLengthResponse(Response.Status.OK, "application/json", content); } + } else if (path.equals("/api/v1/gamers/key")) { + //usage: store gamer ouya public key via PUT + return newFixedLengthResponse(Response.Status.CREATED, null, ""); + } else if (path.equals("/api/v1/search") && session.getParameters().containsKey("q")) { //usage: search for games String query = session.getParameters().get("q").get(0);