CrossOriginPreflightResultCache.h [plain text]
#ifndef CrossOriginPreflightResultCache_h
#define CrossOriginPreflightResultCache_h
#include "URLHash.h"
#include "ResourceHandleTypes.h"
#include <chrono>
#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(StoredCredentials credentials)
: m_credentials(credentials)
{
}
bool parse(const ResourceResponse&, String& errorDescription);
bool allowsCrossOriginMethod(const String&, String& errorDescription) const;
bool allowsCrossOriginHeaders(const HTTPHeaderMap&, String& errorDescription) const;
bool allowsRequest(StoredCredentials, const String& method, const HTTPHeaderMap& requestHeaders) const;
private:
std::chrono::steady_clock::time_point m_absoluteExpiryTime;
StoredCredentials m_credentials;
HashSet<String> m_methods;
HashSet<String, CaseFoldingHash> m_headers;
};
class CrossOriginPreflightResultCache {
WTF_MAKE_NONCOPYABLE(CrossOriginPreflightResultCache); WTF_MAKE_FAST_ALLOCATED;
public:
static CrossOriginPreflightResultCache& shared();
void appendEntry(const String& origin, const URL&, std::unique_ptr<CrossOriginPreflightResultCacheItem>);
bool canSkipPreflight(const String& origin, const URL&, StoredCredentials, const String& method, const HTTPHeaderMap& requestHeaders);
void empty();
private:
friend NeverDestroyed<CrossOriginPreflightResultCache>;
CrossOriginPreflightResultCache();
HashMap<std::pair<String, URL>, std::unique_ptr<CrossOriginPreflightResultCacheItem>> m_preflightHashMap;
};
}
#endif