#pragma once
#if ENABLE(FETCH_API)
#include "ExceptionOr.h"
#include "HTTPHeaderMap.h"
#include <wtf/HashTraits.h>
namespace WebCore {
class FetchHeaders : public RefCounted<FetchHeaders> {
public:
enum class Guard {
None,
Immutable,
Request,
RequestNoCors,
Response
};
static Ref<FetchHeaders> create(Guard guard = Guard::None) { return adoptRef(*new FetchHeaders { guard }); }
static Ref<FetchHeaders> create(const FetchHeaders& headers) { return adoptRef(*new FetchHeaders { headers }); }
ExceptionOr<void> append(const String& name, const String& value);
ExceptionOr<void> remove(const String&);
ExceptionOr<String> get(const String&) const;
ExceptionOr<bool> has(const String&) const;
ExceptionOr<void> set(const String& name, const String& value);
void fill(const FetchHeaders*);
void filterAndFill(const HTTPHeaderMap&, Guard);
String fastGet(HTTPHeaderName name) const { return m_headers.get(name); }
void fastSet(HTTPHeaderName name, const String& value) { m_headers.set(name, value); }
class Iterator {
public:
explicit Iterator(FetchHeaders&);
std::optional<WTF::KeyValuePair<String, String>> next();
private:
Ref<FetchHeaders> m_headers;
size_t m_currentIndex { 0 };
Vector<String> m_keys;
};
Iterator createIterator() { return Iterator { *this }; }
const HTTPHeaderMap& internalHeaders() const { return m_headers; }
void setGuard(Guard);
private:
FetchHeaders(Guard guard) : m_guard(guard) { }
FetchHeaders(const FetchHeaders&);
Guard m_guard;
HTTPHeaderMap m_headers;
};
inline FetchHeaders::FetchHeaders(const FetchHeaders& other)
: RefCounted()
, m_guard(other.m_guard)
, m_headers(other.m_headers)
{
}
inline void FetchHeaders::setGuard(Guard guard)
{
ASSERT(!m_headers.size());
m_guard = guard;
}
}
#endif // ENABLE(FETCH_API)