ByteChunk valueBC = valueMB.getByteChunk();
byte[] valueB = valueBC.getBytes();
int valueL = valueBC.getLength();
int valueS = valueBC.getStart();
int colonPos = -1;
CharChunk hostNameC = (CharChunk)request.getNote(HOSTBUFFER);
if(hostNameC == null) {
hostNameC = new CharChunk(valueL);
request.setNote(HOSTBUFFER, hostNameC);
}
hostNameC.recycle();
boolean ipv6 = (valueB[valueS] == '[');
boolean bracketClosed = false;
for (int i = 0; i < valueL; i++) {
char b = (char) valueB[i + valueS];
hostNameC.append(b);
if (b == ']') {
bracketClosed = true;
} else if (b == ':') {
if (!ipv6 || bracketClosed) {
colonPos = i;
break;
}
}
}
if (colonPos < 0) {
if (request.scheme().equalsIgnoreCase("https")) {
// 80 - Default HTTTP port
request.setServerPort(443);
} else {
// 443 - Default HTTPS port
request.setServerPort(80);
}
request.serverName().setChars(hostNameC.getChars(),
hostNameC.getStart(),
hostNameC.getLength());
} else {
request.serverName().setChars(hostNameC.getChars(),
hostNameC.getStart(), colonPos);
int port = 0;
int mult = 1;
for (int i = valueL - 1; i > colonPos; i--) {
int charValue = HexUtils.DEC[(int) valueB[i + valueS]];