// pass the request for possible modification or analysis
connection.setRequest(request);
connection.setResponse(null);
_proxy.interceptRequest(connection);
request = connection.getRequest();
Response response = connection.getResponse();
if (request == null)
throw new IOException("Request was cancelled");
if (response != null) {
_proxy.failedResponse(id, "Response provided by script");
_proxy = null;
} else {
// pass the request through the plugins, and return the
// response
try {
response = hc.fetchResponse(request);
if (response.getRequest() != null)
request = response.getRequest();
} catch (IOException ioe) {
_logger
.severe("IOException retrieving the response for "
+ request.getURL() + " : " + ioe);
ioe.printStackTrace();
response = errorResponse(request, ioe);
// prevent the conversation from being
// submitted/recorded
_proxy.failedResponse(id, ioe.toString());
_proxy = null;
}
if (response == null) {
_logger.severe("Got a null response from the fetcher");
_proxy.failedResponse(id, "Null response");
return;
}
}
if (_proxy != null) {
// pass the response for analysis or modification by the
// scripts
connection.setResponse(response);
_proxy.interceptResponse(connection);
response = connection.getResponse();
}
if (response == null)
throw new IOException("Response was cancelled");
try {
if (_clientOut != null) {
_logger.fine("Writing the response to the browser");
response.write(_clientOut);
_logger
.fine("Finished writing the response to the browser");
}
} catch (IOException ioe) {
_logger
.severe("Error writing back to the browser : "
+ ioe);
} finally {
response.flushContentStream(); // this simply flushes the
// content from the server
}
// this should not happen, but might if a proxy plugin is
// careless
if (response.getRequest() == null) {
_logger.warning("Response had no associated request!");
response.setRequest(request);
}
if (_proxy != null && !request.getMethod().equals("CONNECT")) {
_proxy.gotResponse(id, response);
}
keepAlive = response.getHeader("Connection");
version = response.getVersion();
request = null;
_logger.fine("Version: " + version + " Connection: "
+ connection);