# HG changeset patch # User xitiomet # Date 1322694386 18000 # Node ID 45513e8a4d4060026a4bbeda798d3c5d31aadba9 # Parent 41d9c6df6f8558ef3684b5cdeb04cb547c3c38f5 interactive response fix diff -r 41d9c6df6f8558ef3684b5cdeb04cb547c3c38f5 -r 45513e8a4d4060026a4bbeda798d3c5d31aadba9 src/org/openstatic/http/HttpRequest.java --- a/src/org/openstatic/http/HttpRequest.java Wed Nov 30 17:50:23 2011 -0500 +++ b/src/org/openstatic/http/HttpRequest.java Wed Nov 30 18:06:26 2011 -0500 @@ -51,9 +51,11 @@ protected String serverHostname; protected PlaceboHttpServer myServer; private PlaceboSession mySession; + private boolean interactive; protected HttpRequest(String path, String request_type, Hashtable headers, Hashtable cookies, Hashtable post_data, String raw_post, Hashtable get_data, String raw_get, Socket socket, PlaceboHttpServer myServer, BufferedReader br) { + this.interactive = false; this.path = path; this.request_prefix = null; this.request_type = request_type; @@ -90,6 +92,12 @@ { this.mySession = session; } + + /** Change the mode to interactive */ + protected void setInteractive(boolean value) + { + this.interactive = value; + } /** Retrieve the session object this request belongs to */ public PlaceboSession getPlaceboSession() @@ -240,66 +248,69 @@ public void sendResponse(HttpResponse response) { - InputStream data = response.getData(); - long data_length = response.getDataLength(); - socketWrite("HTTP/1.1 " + response.getResponseCode() + "\r\n"); - socketWrite("Server: OpenstaticPlacebo/1.0\r\n"); - socketWrite("Date: " + (new Date()).toString() + "\r\n"); - socketWrite("Content-Type: " + response.getContentType() + "\r\n"); - if (data_length != -1) - socketWrite("Content-Length: " + String.valueOf(data_length) + "\r\n"); - if (this.set_cookie != null) + if (!this.interactive) { - socketWrite("Set-Cookie: " + this.set_cookie + "\r\n"); - } - Hashtable prop = response.getHeaders(); - for(Enumeration names = prop.keys(); names.hasMoreElements(); ) - { - String c_name = names.nextElement(); - 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) - { + InputStream data = response.getData(); + long data_length = response.getDataLength(); + socketWrite("HTTP/1.1 " + response.getResponseCode() + "\r\n"); + socketWrite("Server: OpenstaticPlacebo/1.0\r\n"); + socketWrite("Date: " + (new Date()).toString() + "\r\n"); + socketWrite("Content-Type: " + response.getContentType() + "\r\n"); + if (data_length != -1) + socketWrite("Content-Length: " + String.valueOf(data_length) + "\r\n"); + if (this.set_cookie != null) + { + socketWrite("Set-Cookie: " + this.set_cookie + "\r\n"); + } + Hashtable prop = response.getHeaders(); + for(Enumeration names = prop.keys(); names.hasMoreElements(); ) + { + String c_name = names.nextElement(); + 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) + { + try + { + int inputByte; + if (this.myServer.isShowData()) + { + this.myServer.getDebugStream().println("-------------Outbound Data-------------"); + } + while ( (inputByte = data.read()) > -1 ) + { + this.socket_output_stream.write(inputByte); + if (this.myServer.isShowData()) + { + this.myServer.getDebugStream().print((char) inputByte); + } + } + data.close(); + this.socket_output_stream.flush(); + } catch (Exception cs_exc) { + this.myServer.logln(this.clientHostname, "Flush Exception: " + cs_exc.toString() + " / " + cs_exc.getMessage()); + } + if (this.myServer.isShowData()) + { + this.myServer.getDebugStream().println(""); + this.myServer.getDebugStream().println("---------------------------------------"); + } + } try { - int inputByte; - if (this.myServer.isShowData()) - { - this.myServer.getDebugStream().println("-------------Outbound Data-------------"); - } - while ( (inputByte = data.read()) > -1 ) - { - this.socket_output_stream.write(inputByte); - if (this.myServer.isShowData()) - { - this.myServer.getDebugStream().print((char) inputByte); - } - } - data.close(); - this.socket_output_stream.flush(); - } catch (Exception cs_exc) { - this.myServer.logln(this.clientHostname, "Flush Exception: " + cs_exc.toString() + " / " + cs_exc.getMessage()); + this.socket_output_stream.close(); + this.socket.close(); + } catch (Exception close_error) { + this.myServer.logln(this.clientHostname, "Close Exception: " + close_error.toString() + " / " + close_error.getMessage()); } - if (this.myServer.isShowData()) - { - this.myServer.getDebugStream().println(""); - this.myServer.getDebugStream().println("---------------------------------------"); - } - } - try - { - this.socket_output_stream.close(); - this.socket.close(); - } catch (Exception close_error) { - this.myServer.logln(this.clientHostname, "Close Exception: " + close_error.toString() + " / " + close_error.getMessage()); } } diff -r 41d9c6df6f8558ef3684b5cdeb04cb547c3c38f5 -r 45513e8a4d4060026a4bbeda798d3c5d31aadba9 src/org/openstatic/http/InteractiveResponse.java --- a/src/org/openstatic/http/InteractiveResponse.java Wed Nov 30 17:50:23 2011 -0500 +++ b/src/org/openstatic/http/InteractiveResponse.java Wed Nov 30 18:06:26 2011 -0500 @@ -23,6 +23,7 @@ public InteractiveResponse(HttpRequest rq) { + rq.setInteractive(true); this.socket_reader = rq.socket_reader; this.socket_output_stream = rq.socket_output_stream; this.myServer = rq.myServer;