MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / parseUrl

Function parseUrl

Libraries/HttpClient/HttpClientSession.cpp:327–434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325}
326
327static 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 {

Callers 4

addAuthorizationMethod · 0.85
appendMatchingCookiesMethod · 0.85
prepareRequestMethod · 0.85
captureSetCookieMethod · 0.85

Calls 4

sliceStringFunction · 0.85
StringSpanFunction · 0.85
sizeInBytesMethod · 0.45

Tested by

no test coverage detected