Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
KeepAlive.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
6#include "Stroika/Foundation/Characters/String2Int.h"
9
10#include "KeepAlive.h"
11
12using namespace Stroika::Foundation;
16
17/*
18 ********************************************************************************
19 ********************************* HTTP::KeepAlive ******************************
20 ********************************************************************************
21 */
22KeepAlive KeepAlive::Parse (const String& headerValue)
23{
24 KeepAlive r;
25 for (const String& token : headerValue.Tokenize ({' ', ','})) {
26 Containers::Sequence<String> kvp = token.Tokenize ({'='});
27 if (kvp.length () == 2) {
28 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive
29 if (kvp[0] == "timeout"sv) {
30 r.fTimeout = Time::DurationSeconds{Characters::FloatConversion::ToFloat<> (kvp[1])};
31 return r;
32 }
33 else if (kvp[0] == "max"sv) {
34 unsigned int maxMsg = Characters::String2Int<unsigned int> (kvp[1]);
35 r.fMessages = maxMsg;
36 return r;
37 }
38 else {
39 DbgTrace ("Keep-Alive header bad: {}"_f, token);
40 }
41 }
42 else {
43 DbgTrace ("Keep-Alive header bad: {}"_f, token);
44 }
45 }
46 return r;
47}
48
49optional<KeepAlive> KeepAlive::Merge (const optional<KeepAlive>& lhs, const optional<KeepAlive>& rhs)
50{
51 if (lhs and rhs) {
52 KeepAlive r = *lhs;
53 r.fMessages = Memory::NullCoalesce (lhs->fMessages, rhs->fMessages);
54 r.fTimeout = Memory::NullCoalesce (lhs->fTimeout, rhs->fTimeout);
55 return r;
56 }
57 return Memory::NullCoalesce (lhs, rhs);
58}
59
61{
62 StringBuilder sb; // ? is this a BUG or needs some explanation - LGP 2023-09-24
63 return sb;
64}
65
67{
69 sb << "{"sv;
70 if (fMessages) {
71 sb << "Messages: "sv << *fMessages;
72 }
73 if (fTimeout) {
74 sb << ", Timeout: "sv << *fTimeout;
75 }
76 sb << "}"sv;
77 return sb;
78}
chrono::duration< double > DurationSeconds
chrono::duration<double> - a time span (length of time) measured in seconds, but high precision.
Definition Realtime.h:57
#define DbgTrace
Definition Trace.h:309
Similar to String, but intended to more efficiently construct a String. Mutable type (String is large...
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
A generalization of a vector: a container whose elements are keyed by the natural numbers.
Definition Sequence.h:187
nonvirtual size_t length() const
STL-ish alias for size() - really in STL only used in string, I think, but still makes sense as an al...