Skip to content

Commit

Permalink
Updated Safari hack to target 15.0-15.3 (#1347) (#1414)
Browse files Browse the repository at this point in the history
  • Loading branch information
not-implemented authored Feb 14, 2022
1 parent 89ea606 commit eea4b7e
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,24 @@ namespace uWS {
bool compress;
};

/* Safari 15.0 - 15.3 has a completely broken compression implementation (client_no_context_takeover not
* properly implemented) - so we fully disable compression for this browser :-(
* see https://github.com/uNetworking/uWebSockets/issues/1347 */
inline bool hasBrokenCompression(std::string_view userAgent) {
size_t pos;
int uaVersion = 0;
size_t posStart = userAgent.find(" Version/15.");
if (posStart == std::string_view::npos) return false;
posStart += 12;

if ((pos = userAgent.find(" Version/")) == std::string_view::npos) return false;
pos += 9;
size_t posEnd = userAgent.find(' ', posStart);
if (posEnd == std::string_view::npos) return false;

std::string_view uaVersionStr = userAgent.substr(pos);
uaVersionStr = uaVersionStr.substr(0, uaVersionStr.find_first_of(". "));
auto result = std::from_chars(uaVersionStr.data(), uaVersionStr.data() + uaVersionStr.size(), uaVersion);
if (result.ec == std::errc::invalid_argument) return false;
if (uaVersion != 15) return false; // we target just Safari 15 - give Apple a chance ;-)
unsigned int minorVersion = 0;
auto result = std::from_chars(userAgent.data() + posStart, userAgent.data() + posEnd, minorVersion);
if (result.ec != std::errc()) return false;
if (result.ptr != userAgent.data() + posEnd) return false; // do not accept trailing chars
if (minorVersion > 3) return false; // we target just Safari 15.0 - 15.3

if ((pos = userAgent.find(" Safari/", pos)) == std::string_view::npos) return false;
if (userAgent.find(" Safari/", posEnd) == std::string_view::npos) return false;

return true;
}
Expand Down

0 comments on commit eea4b7e

Please sign in to comment.