import java.io.IOException;
import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
import fi.iki.elonen.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<String, String> parameters = new HashMap<String, String>();
+ 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")) {
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);