void writeResponse (HttpServletResponse res, ResponseTrans trans, Cookie[] cookies, String protocol) {
void writeResponse (HttpServletRequest req, HttpServletResponse res, ResponseTrans trans, Cookie[] cookies) {
    void writeResponse (HttpServletResponse res, ResponseTrans trans, Cookie[] cookies, String protocol) {	for (int i = 0; i < trans.countCookies(); i++) try {	    Cookie c = new Cookie(trans.getKeyAt(i), trans.getValueAt(i));	    c.setPath ("/");	    if (cookieDomain != null)	        c.setDomain (cookieDomain);	    int expires = trans.getDaysAt(i);	    if (expires > 0)	        c.setMaxAge(expires * 60*60*24);   // Cookie time to live, days -> seconds	    res.addCookie(c);	} catch (Exception ign) {}	if (trans.getRedirect () != null) {	    try {	        res.sendRedirect(trans.getRedirect ());	    } catch(Exception io_e) {}	} else if (trans.getNotModified ()) {	    res.setStatus (HttpServletResponse.SC_NOT_MODIFIED);	} else {	    if (!trans.cache || ! caching) {	        // Disable caching of response.	        if (protocol == null || !protocol.endsWith ("1.1"))	            res.setHeader ("Pragma", "no-cache"); // for HTTP 1.0	        else	            res.setHeader ("Cache-Control", "no-cache"); // for HTTP 1.1	    }	    if ( trans.realm!=null )	        res.setHeader( "WWW-Authenticate", "Basic realm=\"" + trans.realm + "\"" );	    if (trans.status > 0)	        res.setStatus (trans.status);	    // set last-modified header to now	    long modified = trans.getLastModified ();	    if (modified > -1)	        res.setDateHeader ("Last-Modified", System.currentTimeMillis ());	    // if we don't know which charset to use for parsing HTTP params,	    // take the one from the response. This usually works because	    // browsers send parrameters in the same encoding as the page	    // containing the form has. Problem is we can do this only per servlet,	    // not per session or even per page, which would produce too much overhead	    if (defaultEncoding == null)	        defaultEncoding = trans.charset;	    res.setContentLength (trans.getContentLength ());	    res.setContentType (trans.getContentType ());	    try {	        OutputStream out = res.getOutputStream ();	        out.write (trans.getContent ());	        out.close ();	    } catch(Exception io_e) {	        log ("Exception in writeResponse: "+io_e);	    }	}    }