public Response invoke(Request request) throws Exception {
int method = request.getMethod();
byte[] rawRequest = request.toBytes();
ResponseReader responseReader;
Socket socket = borrowObject();
boolean keepAlive = false;
try {
try {
socket.writeFully(rawRequest, 0, rawRequest.length);
responseReader = new ResponseReader(socket, BUFFER_SIZE);
} catch (SocketException e) {
// Stale connection? Retry on a fresh socket
destroyObject(socket);
socket = createObject();
socket.writeFully(rawRequest, 0, rawRequest.length);
responseReader = new ResponseReader(socket, BUFFER_SIZE);
}
Response response = responseReader.readResponse(method);
keepAlive = "Keep-Alive".equalsIgnoreCase(response.getHeader("Connection: "));