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

Method writeTo

Libraries/Http/HttpHeaders.cpp:431–479  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

429}
430
431Result HttpSetCookieBuilder::writeTo(Span<char> storage, StringSpan& output) const
432{
433 output = {};
434 size_t offset = 0;
435 SC_TRY_MSG(not name.isEmpty(), "Set-Cookie cookie name is empty");
436 SC_TRY_MSG(HttpHeaderInternal::appendTo(storage, offset, name), "Set-Cookie output buffer is too small");
437 SC_TRY_MSG(HttpHeaderInternal::appendTo(storage, offset, "="), "Set-Cookie output buffer is too small");
438 SC_TRY_MSG(HttpHeaderInternal::appendTo(storage, offset, value), "Set-Cookie output buffer is too small");
439 if (not path.isEmpty())
440 {
441 SC_TRY_MSG(HttpHeaderInternal::appendTo(storage, offset, "; Path="), "Set-Cookie output buffer is too small");
442 SC_TRY_MSG(HttpHeaderInternal::appendTo(storage, offset, path), "Set-Cookie output buffer is too small");
443 }
444 if (not domain.isEmpty())
445 {
446 SC_TRY_MSG(HttpHeaderInternal::appendTo(storage, offset, "; Domain="), "Set-Cookie output buffer is too small");
447 SC_TRY_MSG(HttpHeaderInternal::appendTo(storage, offset, domain), "Set-Cookie output buffer is too small");
448 }
449 if (not expires.isEmpty())
450 {
451 SC_TRY_MSG(HttpHeaderInternal::appendTo(storage, offset, "; Expires="),
452 "Set-Cookie output buffer is too small");
453 SC_TRY_MSG(HttpHeaderInternal::appendTo(storage, offset, expires), "Set-Cookie output buffer is too small");
454 }
455 if (not maxAge.isEmpty())
456 {
457 SC_TRY_MSG(HttpHeaderInternal::appendTo(storage, offset, "; Max-Age="),
458 "Set-Cookie output buffer is too small");
459 SC_TRY_MSG(HttpHeaderInternal::appendTo(storage, offset, maxAge), "Set-Cookie output buffer is too small");
460 }
461 if (secure)
462 {
463 SC_TRY_MSG(HttpHeaderInternal::appendTo(storage, offset, "; Secure"), "Set-Cookie output buffer is too small");
464 }
465 if (httpOnly)
466 {
467 SC_TRY_MSG(HttpHeaderInternal::appendTo(storage, offset, "; HttpOnly"),
468 "Set-Cookie output buffer is too small");
469 }
470 if (not sameSite.isEmpty())
471 {
472 SC_TRY_MSG(HttpHeaderInternal::appendTo(storage, offset, "; SameSite="),
473 "Set-Cookie output buffer is too small");
474 SC_TRY_MSG(HttpHeaderInternal::appendTo(storage, offset, sameSite), "Set-Cookie output buffer is too small");
475 }
476
477 output = {{storage.data(), offset}, false, StringEncoding::Ascii};
478 return Result(true);
479}
480
481StringSpan HttpContentTypeTextPlainUtf8() { return "text/plain; charset=utf-8"; }
482

Callers 2

setCookieHelpersMethod · 0.45
headerBuildersMethod · 0.45

Calls 3

ResultClass · 0.50
isEmptyMethod · 0.45
dataMethod · 0.45

Tested by 2

setCookieHelpersMethod · 0.36
headerBuildersMethod · 0.36