1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:27:43 +00:00

AK: Allow Vector<ByteBuffer>::contains_slow to accept (Readonly)Bytes

This is done by providing Traits<ByteBuffer>::equals functions for
(Readonly)Bytes, as the base GenericTraits<T>::equals is unable to
convert the ByteBuffer to (Readonly)Bytes to then use Span::operator==

This allows us to check if a Vector<ByteBuffer> contains a
(Readonly)Bytes without having to making a copy of it into a ByteBuffer
first. The initial use of this is in LibWeb with CORS-preflight, where
we check the split contents of the Access-Control headers with
Fetch::Infrastructure::Request::method() and static StringViews
such as "*"sv.bytes().
This commit is contained in:
Luke Wilde 2023-02-10 19:12:10 +00:00 committed by Linus Groh
parent 237df9df5c
commit d9d556fbab
2 changed files with 21 additions and 0 deletions

View file

@ -332,6 +332,14 @@ struct Traits<ByteBuffer> : public GenericTraits<ByteBuffer> {
{
return Traits<ReadonlyBytes>::hash(byte_buffer.span());
}
static bool equals(ByteBuffer const& byte_buffer, Bytes const& other)
{
return byte_buffer.bytes() == other;
}
static bool equals(ByteBuffer const& byte_buffer, ReadonlyBytes const& other)
{
return byte_buffer.bytes() == other;
}
};
}