Skip to content

Commit

Permalink
tweak(net/http-server): flag to remove EASTL usage
Browse files Browse the repository at this point in the history
The known 'broken' build range from https://forum.cfx.re/t/4975484 looks
like it includes an EASTL bump commit (168f92e) as likely culprit.

Since the crash diagnosis also includes the `"200"` string (as in H2's
:status field) being written in spurious places, the use of EASTL might
be suspect here.

This is done using an `#if` so it can easily be changed when trying to
work on issues caused by this.

The flag is also toggled off for now to make this a valid build to test
for the issue there.
  • Loading branch information
blattersturm committed Mar 11, 2023
1 parent 2e00de8 commit 6fa9f9f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
Expand Up @@ -32,7 +32,7 @@ namespace fx
{
if (boost::algorithm::ends_with(prefix, "/"))
{
eastl::string_view prefixView{ prefix.c_str(), prefix.size() };
net::HeaderStringView prefixView{ prefix.c_str(), prefix.size() };
matches = request->GetPath() == prefixView.substr(0, prefixView.length() - 1);
}
}
Expand Down
38 changes: 35 additions & 3 deletions code/components/net-http-server/include/HttpServer.h
Expand Up @@ -12,8 +12,15 @@
#include <forward_list>
#include <shared_mutex>

#define HTTPSERVER_USE_EASTL 0

#if HTTPSERVER_USE_EASTL
#include <EASTL/fixed_map.h>
#include <EASTL/fixed_string.h>
#else
#include <map>
#include <string>
#endif

#include <optional>

Expand All @@ -28,15 +35,30 @@ struct HeaderComparator
template<typename TString, typename TOtherString>
bool operator()(const TString& left, const TOtherString& right) const
{
return std::lexicographical_compare(left.begin(), left.end(), right.begin(), right.end(), [](char a, char b)
auto leftView = std::string_view{
left
};

auto rightView = std::string_view{
right
};

return std::lexicographical_compare(leftView.begin(), leftView.end(), rightView.begin(), rightView.end(), [](char a, char b)
{
return ToLower(a) < ToLower(b);
});
}
};

#if HTTPSERVER_USE_EASTL
using HeaderStringView = eastl::string_view;
using HeaderString = eastl::fixed_string<char, 64, true>;
using HeaderMap = eastl::fixed_multimap<HeaderString, HeaderString, 16, true, HeaderComparator>;
#else
using HeaderStringView = std::string_view;
using HeaderString = std::string;
using HeaderMap = std::multimap<HeaderString, HeaderString, HeaderComparator>;
#endif

class HttpRequest : public fwRefCountable
{
Expand Down Expand Up @@ -140,9 +162,13 @@ class HttpRequest : public fwRefCountable
return m_headerList;
}

inline std::string GetHeader(eastl::string_view key, const std::string& default_ = {}) const
inline std::string GetHeader(HeaderStringView key, const std::string& default_ = {}) const
{
#if HTTPSERVER_USE_EASTL
auto it = m_headerList.find_as(key, HeaderComparator{});
#else
auto it = m_headerList.find(key);
#endif

return (it != m_headerList.end()) ? std::string{ it->second.c_str(), it->second.size() } : default_;
}
Expand Down Expand Up @@ -191,9 +217,13 @@ class COMPONENT_EXPORT(NET_HTTP_SERVER) HttpResponse : public fwRefCountable
public:
HttpResponse(fwRefContainer<HttpRequest> request);

inline auto GetHeader(eastl::string_view key, eastl::string_view default_ = {}) const
inline auto GetHeader(HeaderStringView key, HeaderStringView default_ = {}) const
{
#if HTTPSERVER_USE_EASTL
auto it = m_headerList.find_as(key, HeaderComparator{});
#else
auto it = m_headerList.find(key);
#endif

return (it != m_headerList.end()) ? it->second : default_;
}
Expand All @@ -209,6 +239,7 @@ class COMPONENT_EXPORT(NET_HTTP_SERVER) HttpResponse : public fwRefCountable
SetHeader(name, HeaderString{ value });
}

#if HTTPSERVER_USE_EASTL
inline void SetHeader(const HeaderString& name, const std::string& value)
{
SetHeader(name, HeaderString{
Expand All @@ -228,6 +259,7 @@ class COMPONENT_EXPORT(NET_HTTP_SERVER) HttpResponse : public fwRefCountable

SetHeader(name, headers);
}
#endif

void WriteHead(int statusCode);

Expand Down
7 changes: 7 additions & 0 deletions code/components/net-http-server/src/Http2Server.cpp
Expand Up @@ -9,7 +9,10 @@
#include "HttpServer.h"
#include "HttpServerImpl.h"

#if HTTPSERVER_USE_EASTL
#include <EASTL/fixed_vector.h>
#endif

#include <nghttp2/nghttp2.h>

#include <deque>
Expand Down Expand Up @@ -549,7 +552,11 @@ class Http2Response : public HttpResponse

int m_stream;

#if HTTPSERVER_USE_EASTL
eastl::fixed_vector<eastl::pair<HeaderString, HeaderString>, 16> m_headers;
#else
std::vector<std::pair<HeaderString, HeaderString>> m_headers;
#endif

ZeroCopyByteBuffer m_buffer;

Expand Down

0 comments on commit 6fa9f9f

Please sign in to comment.