1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:57:35 +00:00

LibWeb: Add Fetch::Infrastructure::Header::from_string_pair() helper

This allows us to use this:

```cpp
auto header = TRY_OR_RETURN_OOM(realm,
    Infrastructure::Header::from_string_pair(name, value));
```

Instead of the somewhat unwieldly:

```cpp
auto header = Infrastructure::Header {
    .name = TRY_OR_RETURN_OOM(realm, ByteBuffer::copy(name.bytes())),
    .value = TRY_OR_RETURN_OOM(realm, ByteBuffer::copy(value.bytes())),
};
```
This commit is contained in:
Linus Groh 2022-10-24 09:16:32 +01:00
parent c12c6fd5ea
commit 65f5c7adbc
5 changed files with 15 additions and 17 deletions

View file

@ -218,11 +218,8 @@ MimeSniff::MimeType XMLHttpRequest::get_response_mime_type() const
// FIXME: Use an actual HeaderList for XHR headers.
auto header_list = make_ref_counted<Fetch::Infrastructure::HeaderList>();
for (auto const& entry : m_response_headers) {
auto header = Fetch::Infrastructure::Header {
.name = MUST(ByteBuffer::copy(entry.key.bytes())),
.value = MUST(ByteBuffer::copy(entry.value.bytes())),
};
MUST(header_list->append(move(header)));
auto header = Fetch::Infrastructure::Header::from_string_pair(entry.key, entry.value).release_value_but_fixme_should_propagate_errors();
header_list->append(move(header)).release_value_but_fixme_should_propagate_errors();
}
// 1. Let mimeType be the result of extracting a MIME type from xhrs responses header list.