| 371 | } |
| 372 | |
| 373 | SC::Result SC::HttpURLParser::parseHost() |
| 374 | { |
| 375 | HttpStringIterator it = host; |
| 376 | |
| 377 | auto start = it; |
| 378 | // Parse user@password if exists |
| 379 | if (it.advanceUntilMatches('@')) |
| 380 | { |
| 381 | StringSpan userAndPassword = HttpStringIterator::fromIterators(start, it, encoding); |
| 382 | SC_TRY(parseUserPassword(userAndPassword)); |
| 383 | (void)it.stepForward(); |
| 384 | } |
| 385 | else |
| 386 | { |
| 387 | it = start; |
| 388 | } |
| 389 | start = it; |
| 390 | // Save the hostname part (before port) for parsing |
| 391 | StringSpan hostnamePart = HttpStringIterator::fromIteratorUntilEnd(it, encoding); |
| 392 | |
| 393 | // Parse hostname and port from hostnamePart |
| 394 | HttpStringIterator it2 = hostnamePart; |
| 395 | HttpStringIterator start2 = it2; |
| 396 | |
| 397 | char firstChar; |
| 398 | if (it2.advanceRead(firstChar) && firstChar == '[') |
| 399 | { |
| 400 | // IPv6 |
| 401 | if (not it2.advanceUntilMatches(']')) |
| 402 | return Result(false); |
| 403 | (void)it2.stepForward(); // include ] |
| 404 | hostname = HttpStringIterator::fromIterators(start2, it2, encoding); |
| 405 | // check if next char is ':' (port separator) without consuming it twice |
| 406 | if (it2.match(':')) |
| 407 | { |
| 408 | (void)it2.stepForward(); |
| 409 | StringSpan portString = HttpStringIterator::fromIteratorUntilEnd(it2, encoding); |
| 410 | if (portString.isEmpty()) |
| 411 | return Result(false); |
| 412 | int32_t value; |
| 413 | SC_TRY(HttpStringIterator::parseInt32(portString, value)); |
| 414 | if (value < 0 || value > 65535) |
| 415 | return Result(false); |
| 416 | port = static_cast<uint16_t>(value); |
| 417 | // Update host to include hostname and port |
| 418 | host = HttpStringIterator::fromIterators(start, it2, encoding); |
| 419 | } |
| 420 | else if (not it2.isAtEnd()) |
| 421 | { |
| 422 | return Result(false); |
| 423 | } |
| 424 | else |
| 425 | { |
| 426 | // No port for IPv6 |
| 427 | host = HttpStringIterator::fromIterators(start, it2, encoding); |
| 428 | } |
| 429 | } |
| 430 | else |
nothing calls this directly
no test coverage detected