Skip to content

Commit 93d5062

Browse files
authored
Merge pull request #1227 from filipe-norte-red/wpe-2.38-xml-http-request-cache-disable-for-protocols
XMLHttpReques: allow disabling the cache for selected protocols
2 parents 85f3f00 + 9676ed4 commit 93d5062

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

Source/WebCore/xml/XMLHttpRequest.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,29 @@ static void logConsoleError(ScriptExecutionContext* context, const String& messa
9797
context->addConsoleMessage(MessageSource::JS, MessageLevel::Error, message);
9898
}
9999

100+
static bool shouldDisableCacheForRequest(URL& url)
101+
{
102+
static Vector<String> s_protocolsNotCached;
103+
static std::once_flag s_onceFlag;
104+
std::call_once(s_onceFlag,
105+
[] {
106+
// The env var contains a comma separated list of protocols that need to disable the cache,
107+
// for example WPE_DISABLE_XHR_RESPONSE_CACHING_FOR_PROTOCOLS="dvb,echo,file"
108+
String s(String::fromLatin1(std::getenv("WPE_DISABLE_XHR_RESPONSE_CACHING_FOR_PROTOCOLS")));
109+
if (!s.isEmpty()) {
110+
s_protocolsNotCached.appendVector(s.split(','));
111+
}
112+
});
113+
114+
if (getenv("WPE_DISABLE_XHR_RESPONSE_CACHING"))
115+
return true;
116+
117+
if (s_protocolsNotCached.contains(url.protocol().toString()))
118+
return true;
119+
120+
return false;
121+
}
122+
100123
Ref<XMLHttpRequest> XMLHttpRequest::create(ScriptExecutionContext& context)
101124
{
102125
auto xmlHttpRequest = adoptRef(*new XMLHttpRequest(context));
@@ -627,7 +650,7 @@ ExceptionOr<void> XMLHttpRequest::createRequest()
627650
options.filteringPolicy = ResponseFilteringPolicy::Enable;
628651
options.contentEncodingSniffingPolicy = ContentEncodingSniffingPolicy::Disable;
629652

630-
if (responseType() == ResponseType::Arraybuffer || getenv("WPE_DISABLE_XHR_RESPONSE_CACHING")) {
653+
if (responseType() == ResponseType::Arraybuffer || shouldDisableCacheForRequest(m_url)) {
631654
options.dataBufferingPolicy = DataBufferingPolicy::DoNotBufferData;
632655
options.cachingPolicy = CachingPolicy::DisallowCaching;
633656
request.setCachePolicy(ResourceRequestCachePolicy::DoNotUseAnyCache);

0 commit comments

Comments
 (0)