1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| public boolean writeResponse(String response) throws Exception { return this.writeResponse(response, true, 200, true, false, true); }
public boolean writeResponse(String response, boolean json) throws Exception { return this.writeResponse(response, true, 200, true, json, true); }
public boolean writeResponse(String response, boolean log, int code, boolean convertVars, boolean json, boolean log_header) throws Exception { boolean acceptsGZIP = false; return this.writeResponse(response, log, code, convertVars, json, acceptsGZIP, log_header); }
public boolean writeResponse(String response, boolean log, int code, boolean convertVars, boolean json, boolean acceptsGZIP, boolean log_header) throws Exception { if (convertVars) { response = ServerStatus.thisObj.change_vars_to_values(response, this.thisSessionHTTP.thisSession); } this.write_command_http("HTTP/1.1 " + code + " OK", log_header); this.write_command_http("Cache-Control: no-store", log_header); this.write_command_http("Pragma: no-cache", log_header); if (json) { this.write_command_http("Content-Type: application/jsonrequest;charset=utf-8"); } else { this.write_command_http("Content-Type: text/" + (response.indexOf("<?xml") >= 0 ? "xml" : "plain") + ";charset=utf-8"); } if (acceptsGZIP) { this.thisSessionHTTP.write_command_http("Vary: Accept-Encoding"); this.thisSessionHTTP.write_command_http("Content-Encoding: gzip"); this.thisSessionHTTP.write_command_http("Transfer-Encoding: chunked"); this.thisSessionHTTP.write_command_http("Date: " + this.thisSessionHTTP.sdf_rfc1123.format(new Date()), log, true); this.thisSessionHTTP.write_command_http("Server: " + ServerStatus.SG("http_server_header"), log, true); this.thisSessionHTTP.write_command_http("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"", log, true); if (!ServerStatus.SG("Access-Control-Allow-Origin").equals("")) { String origin = this.thisSessionHTTP.headerLookup.getProperty("ORIGIN", ""); int x = 0; while (x < ServerStatus.SG("Access-Control-Allow-Origin").split(",").length) { boolean ok = false; if (origin.equals("")) { ok = true; } else if (ServerStatus.SG("Access-Control-Allow-Origin").split(",")[x].toUpperCase().trim().equalsIgnoreCase(origin.toUpperCase().trim())) { ok = true; } if (ok) { this.write_command_http("Access-Control-Allow-Origin: " + ServerStatus.SG("Access-Control-Allow-Origin").split(",")[x].trim()); } ++x; } this.write_command_http("Access-Control-Allow-Headers: authorization,content-type"); this.write_command_http("Access-Control-Allow-Credentials: true"); this.write_command_http("Access-Control-Allow-Methods: GET,POST,OPTIONS,PUT,PROPFIND,DELETE,MKCOL,MOVE,COPY,HEAD,PROPPATCH,LOCK,UNLOCK,ACL,TR"); } this.write_command_http("", log); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] b = response.getBytes("UTF8"); GZIPOutputStream out = new GZIPOutputStream(baos); ((OutputStream)out).write(b); out.finish(); if (baos.size() > 0) { this.thisSessionHTTP.original_os.write((String.valueOf(Long.toHexString(baos.size())) + "\r\n").getBytes()); baos.writeTo(this.thisSessionHTTP.original_os); this.thisSessionHTTP.original_os.write("\r\n".getBytes()); baos.reset(); } this.thisSessionHTTP.original_os.write("0\r\n\r\n".getBytes()); this.thisSessionHTTP.original_os.flush(); } else { this.thisSessionHTTP.write_standard_headers(log); int len = response.getBytes("UTF8").length + 2; if (len == 2) { len = 0; } this.write_command_http("Content-Length: " + len, log_header); this.write_command_http("", log); if (len > 0) { this.thisSessionHTTP.write_command_http(response, log, convertVars); } } this.thisSessionHTTP.thisSession.drain_log(); return true; }
|