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

Function validateProxyOptions

Libraries/HttpClient/HttpClient.cpp:312–349  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

310}
311
312static SC::Result validateProxyOptions(const SC::HttpClientRequestProxyOptions& proxy)
313{
314 SC_TRY_MSG(isValidProxyMode(proxy.mode), "HttpClientRequestOptions: invalid proxy mode");
315 if (proxy.mode == SC::HttpClientRequestProxyOptions::Http)
316 {
317 static constexpr size_t HttpProxySchemeBytes = sizeof("http://") - 1;
318
319 SC_TRY_MSG(proxy.url.sizeInBytes() > sizeof("http://") - 1,
320 "HttpClientRequestOptions: HTTP proxy URL is empty");
321 SC_TRY_MSG(asciiStartsWithIgnoreCase(proxy.url, SC::StringSpan("http://")),
322 "HttpClientRequestOptions: only http:// proxy URLs are supported");
323 SC_TRY_MSG(not hasUrlUnsafeBytes(proxy.url),
324 "HttpClientRequestOptions: HTTP proxy URL contains whitespace or control bytes");
325 const SC::Span<const char> proxyBytes = proxy.url.toCharSpan();
326 SC_TRY_MSG(proxyBytes[HttpProxySchemeBytes] != '/' and proxyBytes[HttpProxySchemeBytes] != '?' and
327 proxyBytes[HttpProxySchemeBytes] != '#',
328 "HttpClientRequestOptions: HTTP proxy URL host is empty");
329 for (size_t idx = HttpProxySchemeBytes; idx < proxyBytes.sizeInBytes(); ++idx)
330 {
331 SC_TRY_MSG(proxyBytes[idx] != '/' and proxyBytes[idx] != '?' and proxyBytes[idx] != '#',
332 "HttpClientRequestOptions: HTTP proxy URL must not include path, query, or fragment");
333 }
334 SC_TRY_MSG(not hasHttpHeaderUnsafeBytes(proxy.authorization),
335 "HttpClientRequestOptions: proxy authorization contains an invalid line break");
336 SC_TRY_MSG(not hasHttpHeaderUnsafeBytes(proxy.bypassList),
337 "HttpClientRequestOptions: proxy bypass list contains an invalid line break");
338 }
339 else
340 {
341 SC_TRY_MSG(proxy.url.sizeInBytes() == 0,
342 "HttpClientRequestOptions: proxy URL is only valid with HTTP proxy mode");
343 SC_TRY_MSG(proxy.authorization.sizeInBytes() == 0,
344 "HttpClientRequestOptions: proxy authorization is only valid with HTTP proxy mode");
345 SC_TRY_MSG(proxy.bypassList.sizeInBytes() == 0,
346 "HttpClientRequestOptions: proxy bypass list is only valid with HTTP proxy mode");
347 }
348 return SC::Result(true);
349}
350
351static SC::Result validateRequestUrl(SC::StringSpan url)
352{

Callers 1

Calls 7

isValidProxyModeFunction · 0.85
StringSpanFunction · 0.85
hasUrlUnsafeBytesFunction · 0.85
hasHttpHeaderUnsafeBytesFunction · 0.85
ResultClass · 0.50
sizeInBytesMethod · 0.45

Tested by

no test coverage detected