MCPcopy Index your code
hub / github.com/apache/tomcat / parseHost

Method parseHost

java/org/apache/coyote/AbstractProcessor.java:307–381  ·  view source on GitHub ↗

Parses the Host header value and populates the server name and port. @param valueMB The MessageBytes containing the Host header value

(MessageBytes valueMB)

Source from the content-addressed store, hash-verified

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) {

Callers 2

prepareRequestMethod · 0.80
prepareRequestMethod · 0.80

Calls 15

populateHostMethod · 0.95
populatePortMethod · 0.95
getBytesMethod · 0.95
parseMethod · 0.95
setErrorStateMethod · 0.95
serverNameMethod · 0.80
getByteChunkMethod · 0.80
getNextModeMethod · 0.80
isNullMethod · 0.65
getLengthMethod · 0.65
setStatusMethod · 0.65
getStringMethod · 0.65

Tested by

no test coverage detected