| 325 | } |
| 326 | |
| 327 | static bool parseUrl(SC::StringSpan url, ParsedUrl& parsed) |
| 328 | { |
| 329 | const SC::Span<const char> bytes = url.toCharSpan(); |
| 330 | for (size_t idx = 0; idx < bytes.sizeInBytes(); ++idx) |
| 331 | { |
| 332 | const unsigned char c = static_cast<unsigned char>(bytes[idx]); |
| 333 | if (c <= ' ' or c == 0x7f) |
| 334 | { |
| 335 | return false; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | size_t schemeEnd = 0; |
| 340 | while (schemeEnd + 2 < bytes.sizeInBytes()) |
| 341 | { |
| 342 | if (bytes[schemeEnd] == ':' and bytes[schemeEnd + 1] == '/' and bytes[schemeEnd + 2] == '/') |
| 343 | { |
| 344 | break; |
| 345 | } |
| 346 | schemeEnd += 1; |
| 347 | } |
| 348 | if (schemeEnd + 2 >= bytes.sizeInBytes()) |
| 349 | { |
| 350 | return false; |
| 351 | } |
| 352 | |
| 353 | const SC::StringSpan scheme = sliceString(url, 0, schemeEnd); |
| 354 | if (sessionAsciiEqualsIgnoreCase(scheme, SC::StringSpan("http"))) |
| 355 | { |
| 356 | parsed.isHttps = false; |
| 357 | } |
| 358 | else if (sessionAsciiEqualsIgnoreCase(scheme, SC::StringSpan("https"))) |
| 359 | { |
| 360 | parsed.isHttps = true; |
| 361 | } |
| 362 | else |
| 363 | { |
| 364 | return false; |
| 365 | } |
| 366 | |
| 367 | const size_t hostStart = schemeEnd + 3; |
| 368 | size_t hostEnd = hostStart; |
| 369 | while (hostEnd < bytes.sizeInBytes() and bytes[hostEnd] != '/' and bytes[hostEnd] != '?' and bytes[hostEnd] != '#') |
| 370 | { |
| 371 | hostEnd += 1; |
| 372 | } |
| 373 | if (hostEnd == hostStart) |
| 374 | { |
| 375 | return false; |
| 376 | } |
| 377 | |
| 378 | parsed.origin = sliceString(url, 0, hostEnd); |
| 379 | |
| 380 | size_t hostnameStart = hostStart; |
| 381 | for (size_t idx = hostStart; idx < hostEnd; ++idx) |
| 382 | { |
| 383 | if (bytes[idx] == '@') |
| 384 | { |
no test coverage detected