# HG changeset patch # User xitiomet # Date 1322294161 18000 # Node ID 138f56cde331bc5adeea2f6fea2da2fb5ce48c0b # Parent 9e22d72dc6793d145421612b421af8839b633002 session tricks diff -r 9e22d72dc6793d145421612b421af8839b633002 -r 138f56cde331bc5adeea2f6fea2da2fb5ce48c0b Makefile --- a/Makefile Fri Nov 25 17:33:06 2011 -0500 +++ b/Makefile Sat Nov 26 02:56:01 2011 -0500 @@ -22,7 +22,7 @@ cp placebohttp.jar PlaceboHTTP.app/Contents/Resources/placebo/ # Generate Documentation -docs: placebohttp.jar +docs: javadoc -d doc -sourcepath src org.openstatic.placebo org.openstatic.http org.openstatic.util # Alternate build using the java vm diff -r 9e22d72dc6793d145421612b421af8839b633002 -r 138f56cde331bc5adeea2f6fea2da2fb5ce48c0b src/org/openstatic/http/HttpRequest.java --- a/src/org/openstatic/http/HttpRequest.java Fri Nov 25 17:33:06 2011 -0500 +++ b/src/org/openstatic/http/HttpRequest.java Sat Nov 26 02:56:01 2011 -0500 @@ -30,6 +30,7 @@ public class HttpRequest { private Hashtable headers; + private Hashtable outbound_headers; private Hashtable cookies; private Hashtable post_data; private Hashtable get_data; @@ -53,6 +54,7 @@ this.request_prefix = null; this.request_type = request_type; this.headers = headers; + this.outbound_headers = new Hashtable(); this.cookies = cookies; this.post_data = post_data; this.raw_post = raw_post; @@ -100,6 +102,11 @@ this.set_cookie = cookie; } + public void setResponseHeader(String key, String value) + { + this.outbound_headers.put(key, value); + } + /** Return the full path of this request */ public String getFullPath() { @@ -224,7 +231,12 @@ String c_value = prop.get(c_name); socketWrite(c_name + ": " + c_value + "\r\n"); } - + for(Enumeration names2 = outbound_headers.keys(); names2.hasMoreElements(); ) + { + String c_name = names2.nextElement(); + String c_value = outbound_headers.get(c_name); + socketWrite(c_name + ": " + c_value + "\r\n"); + } socketWrite("\r\n"); if (data != null) { diff -r 9e22d72dc6793d145421612b421af8839b633002 -r 138f56cde331bc5adeea2f6fea2da2fb5ce48c0b src/org/openstatic/http/PlaceboHttpServer.java --- a/src/org/openstatic/http/PlaceboHttpServer.java Fri Nov 25 17:33:06 2011 -0500 +++ b/src/org/openstatic/http/PlaceboHttpServer.java Sat Nov 26 02:56:01 2011 -0500 @@ -30,6 +30,7 @@ { private int port; private String myName; + private String session_var; private PrintStream debug_stream; private boolean debug_mode; private boolean show_data; @@ -39,6 +40,10 @@ private LinkedBlockingQueue request_queue; private ServerSocket ss; private int routing_mode; + private int session_mode; + + public final static int GET_SESSION = 1; + public final static int COOKIE_SESSION = 2; public PlaceboHttpServer() { @@ -55,6 +60,18 @@ this.request_queue = new LinkedBlockingQueue(); this.debug_stream = System.err; this.keep_running = true; + this.session_var = "PLACEBO_SESSIONID"; + this.session_mode = COOKIE_SESSION; + } + + public void setSessionVariable(String s_var) + { + this.session_var = s_var; + } + + public void setSessionMode(int mode) + { + this.session_mode = mode; } public void setPort(int value) @@ -96,7 +113,13 @@ if (existing_key != null) new_session.setSessionId(existing_key); logln(this.myName, "Creating new session " + new_session.getSessionId()); - request.setCookie("PLACEBO_SESSIONID=" + new_session.getSessionId() + ";"); + if (this.session_mode == COOKIE_SESSION) + { + request.setCookie("PLACEBO_SESSIONID=" + new_session.getSessionId() + ";"); + } else if (this.session_mode == GET_SESSION) { + request.setResponseHeader("Placebo-Session-Id", new_session.getSessionId()); + request.setResponseHeader("Placebo-Session", this.session_var); + } new_session.handleRequest(request); sessions.put(new_session.getSessionId(), new_session); return new_session; @@ -106,7 +129,7 @@ { logln(this.myName, "Recieved Routing Request"); String session_id = request.getCookie("PLACEBO_SESSIONID"); - String session_id_or = request.getGetValue("PLACEBO_SESSIONID"); + String session_id_or = request.getGetValue(this.session_var); if (session_id_or != null) {