| 310 | } |
| 311 | |
| 312 | static 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 | |
| 351 | static SC::Result validateRequestUrl(SC::StringSpan url) |
| 352 | { |
no test coverage detected