Skip to content

Commit

Permalink
Add GET handler for _session
Browse files Browse the repository at this point in the history
Send back an "Admin Party"-like response on a GET
request to /_session. This makes CouchApps work
that rely on _session (like Mobile Futon).
  • Loading branch information
vmx committed Mar 25, 2012
1 parent 6cc2407 commit 7509e3e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Expand Up @@ -134,6 +134,16 @@ public void testServer() {
responseBody.put("version", TDRouter.getVersionString());
send(server, "GET", "/", TDStatus.OK, responseBody);

Map<String,Object> session = new HashMap<String,Object>();
Map<String,Object> userCtx = new HashMap<String,Object>();
List<String> roles = new ArrayList<String>();
roles.add("_admin");
session.put("ok", true);
userCtx.put("name", null);
userCtx.put("roles", roles);
session.put("userCtx", userCtx);
send(server, "GET", "/_session", TDStatus.OK, session);

List<String> allDbs = new ArrayList<String>();
send(server, "GET", "/_all_dbs", TDStatus.OK, allDbs);

Expand Down
13 changes: 13 additions & 0 deletions TouchDB-Android/src/com/couchbase/touchdb/router/TDRouter.java
Expand Up @@ -457,6 +457,19 @@ public TDStatus do_GET_all_dbs(TDDatabase _db, String _docID, String _attachment
return new TDStatus(TDStatus.OK);
}

public TDStatus do_GET_session(TDDatabase _db, String _docID, String _attachmentName) {
// Send back an "Admin Party"-like response
Map<String,Object> session= new HashMap<String,Object>();
Map<String,Object> userCtx = new HashMap<String,Object>();
String[] roles = {"_admin"};
session.put("ok", true);
userCtx.put("name", null);
userCtx.put("roles", roles);
session.put("userCtx", userCtx);
connection.setResponseBody(new TDBody(session));
return new TDStatus(TDStatus.OK);
}

public TDStatus do_POST_replicate(TDDatabase _db, String _docID, String _attachmentName) {
// Extract the parameters from the JSON request body:
// http://wiki.apache.org/couchdb/Replication
Expand Down

0 comments on commit 7509e3e

Please sign in to comment.