CrossOriginPreflightResultCache.h [plain text]
#pragma once
#include "StoredCredentialsPolicy.h"
#include "URLHash.h"
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/text/StringHash.h>
namespace WebCore {
class HTTPHeaderMap;
class ResourceResponse;
class CrossOriginPreflightResultCacheItem {
WTF_MAKE_NONCOPYABLE(CrossOriginPreflightResultCacheItem); WTF_MAKE_FAST_ALLOCATED;
public:
explicit CrossOriginPreflightResultCacheItem(StoredCredentialsPolicy storedCredentialsPolicy)
: m_storedCredentialsPolicy(storedCredentialsPolicy)
{
}
WEBCORE_EXPORT bool parse(const ResourceResponse&, String& errorDescription);
WEBCORE_EXPORT bool allowsCrossOriginMethod(const String&, String& errorDescription) const;
WEBCORE_EXPORT bool allowsCrossOriginHeaders(const HTTPHeaderMap&, String& errorDescription) const;
bool allowsRequest(StoredCredentialsPolicy, const String& method, const HTTPHeaderMap& requestHeaders) const;
private:
MonotonicTime m_absoluteExpiryTime;
StoredCredentialsPolicy m_storedCredentialsPolicy;
HashSet<String> m_methods;
HashSet<String, ASCIICaseInsensitiveHash> m_headers;
};
class CrossOriginPreflightResultCache {
WTF_MAKE_NONCOPYABLE(CrossOriginPreflightResultCache); WTF_MAKE_FAST_ALLOCATED;
public:
WEBCORE_EXPORT static CrossOriginPreflightResultCache& singleton();
WEBCORE_EXPORT void appendEntry(const String& origin, const URL&, std::unique_ptr<CrossOriginPreflightResultCacheItem>);
WEBCORE_EXPORT bool canSkipPreflight(const String& origin, const URL&, StoredCredentialsPolicy, const String& method, const HTTPHeaderMap& requestHeaders);
WEBCORE_EXPORT void clear();
private:
friend NeverDestroyed<CrossOriginPreflightResultCache>;
CrossOriginPreflightResultCache();
HashMap<std::pair<String, URL>, std::unique_ptr<CrossOriginPreflightResultCacheItem>> m_preflightHashMap;
};
}