From afee4c4a727d4bbe56c99c79da1a1e0dad5d8d57 Mon Sep 17 00:00:00 2001 From: a Date: Fri, 16 Aug 2024 14:30:14 +0300 Subject: [PATCH] workaround a problem in `Steam_HTTP::SetHTTPRequestHeaderValue()` where some games set a cache-control policy which allows only reponses from previous requests --- dll/dll/steam_http.h | 9 ++++++--- dll/steam_http.cpp | 14 +++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/dll/dll/steam_http.h b/dll/dll/steam_http.h index d9da2fa2..4634a578 100644 --- a/dll/dll/steam_http.h +++ b/dll/dll/steam_http.h @@ -30,12 +30,15 @@ struct Steam_Http_Request { bool requires_valid_ssl = false; constexpr const static char STEAM_DEFAULT_USER_AGENT[] = "Valve/Steam HTTP Client 1.0"; - // GET or POST parameter value on the request + // check Steam_HTTP::SetHTTPRequestHeaderValue() and make sure to bypass the ones that should be reserved std::map headers{ - {"User-Agent", STEAM_DEFAULT_USER_AGENT}, + { "User-Agent", STEAM_DEFAULT_USER_AGENT }, + { "Cache-Control", "max-age=0" }, + { "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7" }, + { "Upgrade-Insecure-Requests", "1" }, }; - // GET or POST parameter value on the request + // GET or POST parameter value of the request std::map get_or_post_params{}; std::string post_raw{}; diff --git a/dll/steam_http.cpp b/dll/steam_http.cpp index 5210d1a6..86035e67 100644 --- a/dll/steam_http.cpp +++ b/dll/steam_http.cpp @@ -38,7 +38,7 @@ Steam_Http_Request *Steam_HTTP::get_request(HTTPRequestHandle hRequest) // or such. HTTPRequestHandle Steam_HTTP::CreateHTTPRequest( EHTTPMethod eHTTPRequestMethod, const char *pchAbsoluteURL ) { - PRINT_DEBUG("%i %s", eHTTPRequestMethod, pchAbsoluteURL); + PRINT_DEBUG("%i '%s'", eHTTPRequestMethod, pchAbsoluteURL); std::lock_guard lock(global_mutex); if (!pchAbsoluteURL) return INVALID_HTTPREQUEST_HANDLE; @@ -83,7 +83,7 @@ HTTPRequestHandle Steam_HTTP::CreateHTTPRequest( EHTTPMethod eHTTPRequestMethod, // sending the request. This is just so the caller can easily keep track of which callbacks go with which request data. bool Steam_HTTP::SetHTTPRequestContextValue( HTTPRequestHandle hRequest, uint64 ulContextValue ) { - PRINT_DEBUG_ENTRY(); + PRINT_DEBUG("%llu", ulContextValue); std::lock_guard lock(global_mutex); Steam_Http_Request *request = get_request(hRequest); @@ -122,15 +122,19 @@ bool Steam_HTTP::SetHTTPRequestHeaderValue( HTTPRequestHandle hRequest, const ch std::lock_guard lock(global_mutex); if (!pchHeaderName || !pchHeaderValue) return false; - std::string headerName(pchHeaderName); - std::transform(headerName.begin(), headerName.end(), headerName.begin(), [](char c){ return (char)std::toupper(c); }); - if (headerName == "USER-AGENT") return false; + if (common_helpers::str_cmp_insensitive(pchHeaderName, "User-Agent")) return false; Steam_Http_Request *request = get_request(hRequest); if (!request) { return false; } + // FIX: appid 1902490 adds the header "Cache-Control: only-if-cached, max-stale=2678400" + // which means a response is returned back only if it was already cached, otherwise the server has to send a 504 "Gateway Timeout" + // just bypass the known ones to be on the safe side + if (common_helpers::str_cmp_insensitive(pchHeaderName, "Cache-Control")) return true; + if (common_helpers::str_cmp_insensitive(pchHeaderName, "Accept")) return true; + request->headers[pchHeaderName] = pchHeaderValue; return true; }