Parses the Host header value and populates the server name and port. @param valueMB The MessageBytes containing the Host header value
(MessageBytes valueMB)
| 305 | * @param valueMB The MessageBytes containing the Host header value |
| 306 | */ |
| 307 | protected void parseHost(MessageBytes valueMB) { |
| 308 | if (valueMB == null || valueMB.isNull()) { |
| 309 | populateHost(); |
| 310 | populatePort(); |
| 311 | return; |
| 312 | } else if (valueMB.getLength() == 0) { |
| 313 | // Empty Host header so set sever name to empty string |
| 314 | request.serverName().setString(""); |
| 315 | populatePort(); |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | ByteChunk valueBC = valueMB.getByteChunk(); |
| 320 | byte[] valueB = valueBC.getBytes(); |
| 321 | int valueL = valueBC.getLength(); |
| 322 | int valueS = valueBC.getStart(); |
| 323 | if (hostNameC.length < valueL) { |
| 324 | hostNameC = new char[valueL]; |
| 325 | } |
| 326 | |
| 327 | try { |
| 328 | // Validates the host name |
| 329 | int colonPos = Host.parse(valueMB); |
| 330 | |
| 331 | // Extract the port information first, if any |
| 332 | if (colonPos != -1) { |
| 333 | int port = 0; |
| 334 | for (int i = colonPos + 1; i < valueL; i++) { |
| 335 | char c = (char) valueB[i + valueS]; |
| 336 | if (c < '0' || c > '9') { |
| 337 | response.setStatus(400); |
| 338 | setErrorState(ErrorState.CLOSE_CLEAN, null); |
| 339 | return; |
| 340 | } |
| 341 | int digit = c - '0'; |
| 342 | if (port > (Integer.MAX_VALUE - digit) / 10) { |
| 343 | response.setStatus(400); |
| 344 | setErrorState(ErrorState.CLOSE_CLEAN, null); |
| 345 | return; |
| 346 | } |
| 347 | port = port * 10 + digit; |
| 348 | } |
| 349 | request.setServerPort(port); |
| 350 | |
| 351 | // Only need to copy the host name up to the : |
| 352 | valueL = colonPos; |
| 353 | } |
| 354 | |
| 355 | // Extract the host name |
| 356 | for (int i = 0; i < valueL; i++) { |
| 357 | hostNameC[i] = (char) valueB[i + valueS]; |
| 358 | } |
| 359 | request.serverName().setChars(hostNameC, 0, valueL); |
| 360 | |
| 361 | } catch (IllegalArgumentException e) { |
| 362 | // IllegalArgumentException indicates that the host name is invalid |
| 363 | UserDataHelper.Mode logMode = userDataHelper.getNextMode(); |
| 364 | if (logMode != null) { |
no test coverage detected