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

Method appendMatchingCookies

Libraries/HttpClient/HttpClientSession.cpp:825–862  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

823}
824
825SC::Result SC::HttpClientSession::appendMatchingCookies(StringSpan url, size_t& numHeaders)
826{
827 ParsedUrl parsed;
828 SC_TRY_MSG(parseUrl(url, parsed), "HttpClientSession: invalid request URL");
829
830 const size_t cookieHeaderStart = headerScratchUsed;
831 bool wroteCookie = false;
832 for (size_t idx = 0; idx < sessionMemory.cookies.sizeInElements(); ++idx)
833 {
834 const HttpClientSessionCookie& cookie = sessionMemory.cookies[idx];
835 if (not cookie.isInUse())
836 {
837 continue;
838 }
839 if ((cookie.flags & HttpClientSessionCookie::Secure) != 0 and not parsed.isHttps)
840 {
841 continue;
842 }
843 if (not cookieDomainMatches(cookie, parsed.host) or not cookiePathMatches(cookie, parsed.path))
844 {
845 continue;
846 }
847
848 SC_TRY(appendScratch(cookie.name, wroteCookie));
849 SC_TRY(appendScratch(StringSpan("="), false));
850 SC_TRY(appendScratch(cookie.value, false));
851 wroteCookie = true;
852 }
853
854 if (wroteCookie)
855 {
856 const StringSpan value(
857 {sessionMemory.headerScratch.data() + cookieHeaderStart, headerScratchUsed - cookieHeaderStart}, false,
858 StringEncoding::Ascii);
859 SC_TRY(appendPreparedHeader(StringSpan("Cookie"), value, numHeaders));
860 }
861 return Result(true);
862}
863
864SC::Result SC::HttpClientSession::prepareRequest(const HttpClientRequest& source, HttpClientRequest& prepared)
865{

Callers

nothing calls this directly

Calls 6

parseUrlFunction · 0.85
cookieDomainMatchesFunction · 0.85
cookiePathMatchesFunction · 0.85
StringSpanFunction · 0.85
ResultClass · 0.50
dataMethod · 0.45

Tested by

no test coverage detected