Redirect the request to the protocol defined in the
protocolInfo
. Protocols supported are http and https.
if (redirector == null){
redirector = new Redirector();
}
if (protocolInfo.protocol.equalsIgnoreCase("https")) {
redirector.redirectSSL(protocolInfo);
} else {
redirector.redirect(protocolInfo);
}
protocolInfo.keepAlive = false;
/* ======================================================
* Java HTTP(S) client sends request in 2 chunks: header, payload
* We need to make sure client started to send payload before redirecting/closing
* the connection. Otherwise client can not receive "HTTP 302 redirect" response.
*/
ByteBuffer tmpBuffer = protocolInfo.byteBuffer;
tmpBuffer.clear();
ByteBufferInputStream is = new ByteBufferInputStream(tmpBuffer);
try {
is.setReadTimeout(2);
is.setSelectionKey(protocolInfo.key);
int count = 0;
while (tmpBuffer.hasRemaining() && count < DEFAULT_HTTP_HEADER_BUFFER_SIZE) {
tmpBuffer.position(tmpBuffer.limit());
int readBytes = is.read();
if (readBytes == -1) break;
count += readBytes;
}
} catch(IOException e) {
// ignore
} finally {
is.close();
}
//=========================================================