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

Function validateRequestUrl

Libraries/HttpClient/HttpClient.cpp:351–376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349}
350
351static SC::Result validateRequestUrl(SC::StringSpan url)
352{
353 SC_TRY_MSG(url.sizeInBytes() > 0, "HttpClientRequest: URL is empty");
354
355 const SC::Span<const char> bytes = url.toCharSpan();
356 SC_TRY_MSG(not hasUrlUnsafeBytes(url), "HttpClientRequest: URL contains whitespace or control bytes");
357
358 size_t schemeBytes = 0;
359 if (asciiStartsWithIgnoreCase(url, SC::StringSpan("http://")))
360 {
361 schemeBytes = sizeof("http://") - 1;
362 }
363 else if (asciiStartsWithIgnoreCase(url, SC::StringSpan("https://")))
364 {
365 schemeBytes = sizeof("https://") - 1;
366 }
367 else
368 {
369 return SC::Result::Error("HttpClientRequest: only http:// and https:// URLs are supported");
370 }
371
372 SC_TRY_MSG(bytes.sizeInBytes() > schemeBytes, "HttpClientRequest: URL host is empty");
373 SC_TRY_MSG(bytes[schemeBytes] != '/' and bytes[schemeBytes] != '?' and bytes[schemeBytes] != '#',
374 "HttpClientRequest: URL host is empty");
375 return SC::Result(true);
376}
377
378static SC::Result validateRequestOptionsShape(const SC::HttpClientRequestOptions& options)
379{

Callers 1

validateRequestShapeFunction · 0.85

Calls 6

hasUrlUnsafeBytesFunction · 0.85
StringSpanFunction · 0.85
ErrorEnum · 0.50
ResultClass · 0.50
sizeInBytesMethod · 0.45

Tested by

no test coverage detected