<commit_before>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2021.  All rights reserved
 */
#include "../../../StroikaPreComp.h"

#include "../../../Characters/Format.h"
#include "../../../Characters/String2Int.h"
#include "../../../Characters/ToString.h"
#include "../../../Memory/ObjectFieldUtilities.h"

#include "Headers.h"

using namespace Stroika::Foundation;
using namespace Stroika::Foundation::Characters;
using namespace Stroika::Foundation::Containers;
using namespace Stroika::Foundation::IO;
using namespace Stroika::Foundation::IO::Network;
using namespace Stroika::Foundation::IO::Network::HTTP;
using namespace Stroika::Foundation::Streams;

namespace {
    constexpr auto kHeaderNameComparer_ = String::EqualsComparer{CompareOptions::eCaseInsensitive};
}

/*
 ********************************************************************************
 ******************************** HTTP::Headers *********************************
 ********************************************************************************
 */
Headers::Headers ()
    : pCacheControl{
          [] (const auto* property) {
              const Headers*                                     headerObj = Memory::GetObjectOwningField (property, &Headers::pCacheControl);
              lock_guard<const AssertExternallySynchronizedLock> critSec{*headerObj};
              return headerObj->fCacheControl_;
          },
          [] (auto* property, const auto& cacheControl) {
              Headers*                                           headerObj = Memory::GetObjectOwningField (property, &Headers::pCacheControl);
              lock_guard<const AssertExternallySynchronizedLock> critSec{*headerObj};
              headerObj->fCacheControl_ = cacheControl;
          }}
    , pConnection{
          [] (const auto* property) -> optional<ConnectionValue> {
              const Headers* headerObj = Memory::GetObjectOwningField (property, &Headers::pConnection);
              using CompareOptions     = Characters::CompareOptions;
              lock_guard<const AssertExternallySynchronizedLock> critSec{*headerObj};
              if (auto connectionHdr = headerObj->As<Mapping<String, String>> ().Lookup (HeaderName::kConnection)) {
                  if (kHeaderNameComparer_ (*connectionHdr, L"Keep-Alive"sv)) {
                      return eKeepAlive;
                  }
                  else if (kHeaderNameComparer_ (*connectionHdr, L"close"sv)) {
                      return eClose;
                  }
              }
              return nullopt;
          },
          [] (auto* property, const auto& connectionValue) {
              Headers*                                           headerObj = Memory::GetObjectOwningField (property, &Headers::pConnection);
              lock_guard<const AssertExternallySynchronizedLock> critSec{*headerObj};
              optional<String>                                   v;
              if (connectionValue) {
                  switch (*connectionValue) {
                      case ConnectionValue::eKeepAlive:
                          v = L"Keep-Alive"sv;
                          break;
                      case ConnectionValue::eClose:
                          v = L"close"sv;
                          break;
                  }
              }
              headerObj->Set (HeaderName::kConnection, v);
          }}
    , pContentLength{
          [] (const auto* property) {
              const Headers*                                     headerObj = Memory::GetObjectOwningField (property, &Headers::pContentLength);
              lock_guard<const AssertExternallySynchronizedLock> critSec{*headerObj};
              return headerObj->fContentLength_;
          },
          [] (auto* property, auto contentLength) {
              Headers*                                           headerObj = Memory::GetObjectOwningField (property, &Headers::pContentLength);
              lock_guard<const AssertExternallySynchronizedLock> critSec{*headerObj};
              headerObj->fContentLength_ = contentLength;
          }}
    , pContentType{
          [] (const auto* property) {
              const Headers*                                     headerObj = Memory::GetObjectOwningField (property, &Headers::pContentType);
              lock_guard<const AssertExternallySynchronizedLock> critSec{*headerObj};
              return headerObj->fContentType_;<commit_msg>tweak IO/Network/HTTP/Headers.cpp<commit_after>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2021.  All rights reserved
 */
#include "../../../StroikaPreComp.h"

#include "../../../Characters/Format.h"
#include "../../../Characters/String2Int.h"
#include "../../../Characters/ToString.h"
#include "../../../Memory/ObjectFieldUtilities.h"

#include "Headers.h"

using namespace Stroika::Foundation;
using namespace Stroika::Foundation::Characters;
using namespace Stroika::Foundation::Containers;
using namespace Stroika::Foundation::IO;
using namespace Stroika::Foundation::IO::Network;
using namespace Stroika::Foundation::IO::Network::HTTP;
using namespace Stroika::Foundation::Streams;

namespace {
    constexpr auto kHeaderNameComparer_ = String::EqualsComparer{CompareOptions::eCaseInsensitive};
    constexpr wstring_view kKeepAlive_      = L"Keep-Alive"sv;
    constexpr wstring_view kClose_          = L"close"sv;
}

/*
 ********************************************************************************
 ******************************** HTTP::Headers *********************************
 ********************************************************************************
 */
Headers::Headers ()
    : pCacheControl{
          [] (const auto* property) {
              const Headers*                                     headerObj = Memory::GetObjectOwningField (property, &Headers::pCacheControl);
              lock_guard<const AssertExternallySynchronizedLock> critSec{*headerObj};
              return headerObj->fCacheControl_;
          },
          [] (auto* property, const auto& cacheControl) {
              Headers*                                           headerObj = Memory::GetObjectOwningField (property, &Headers::pCacheControl);
              lock_guard<const AssertExternallySynchronizedLock> critSec{*headerObj};
              headerObj->fCacheControl_ = cacheControl;
          }}
    , pConnection{
          [] (const auto* property) -> optional<ConnectionValue> {
              const Headers* headerObj = Memory::GetObjectOwningField (property, &Headers::pConnection);
              lock_guard<const AssertExternallySynchronizedLock> critSec{*headerObj};
              if (auto connectionHdr = headerObj->As<Mapping<String, String>> ().Lookup (HeaderName::kConnection)) {
                  if (kHeaderNameComparer_ (*connectionHdr, kKeepAlive_)) {
                      return eKeepAlive;
                  }
                  else if (kHeaderNameComparer_ (*connectionHdr, kClose_)) {
                      return eClose;
                  }
              }
              return nullopt;
          },
          [] (auto* property, const auto& connectionValue) {
              Headers*                                           headerObj = Memory::GetObjectOwningField (property, &Headers::pConnection);
              lock_guard<const AssertExternallySynchronizedLock> critSec{*headerObj};
              optional<String>                                   v;
              if (connectionValue) {
                  switch (*connectionValue) {
                      case ConnectionValue::eKeepAlive:
                          v = kKeepAlive_;
                          break;
                      case ConnectionValue::eClose:
                          v = kClose_;
                          break;
                  }
              }
              headerObj->Set (HeaderName::kConnection, v);
          }}
    , pContentLength{
          [] (const auto* property) {
              const Headers*                                     headerObj = Memory::GetObjectOwningField (property, &Headers::pContentLength);
              lock_guard<const AssertExternallySynchronizedLock> critSec{*headerObj};
              return headerObj->fContentLength_;
          },
          [] (auto* property, auto contentLength) {
              Headers*                                           headerObj = Memory::GetObjectOwningField (property, &Headers::pContentLength);
              lock_guard<const AssertExternallySynchronizedLock> critSec{*headerObj};
              headerObj->fContentLength_ = contentLength;
          }}
    , pContentType{
          [] (const auto* property) {
              const Headers*                                     headerObj = Memory::GetObjectOwningField (property, &Headers::pContentType);
              lock_guard<const AssertExternallySynchronizedLock> critSec{*headerObj};
              return headerObj->fContentType_;
{'fraction_non_alphanumeric': 0.1489529385273587, 'fraction_numerical': 0.002026570592208962, 'mean_word_length': 2.072639225181598, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '136811', 'n_tokens_mistral': 2100, 'n_tokens_neox': 2032, 'n_words': 393}