Serenity Operating System
1/*
2 * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <AK/AnyOf.h>
8#include <AK/Array.h>
9#include <LibWeb/Fetch/Infrastructure/HTTP/Statuses.h>
10
11namespace Web::Fetch::Infrastructure {
12
13// https://fetch.spec.whatwg.org/#null-body-status
14bool is_null_body_status(Status status)
15{
16 // A null body status is a status that is 101, 103, 204, 205, or 304.
17 return any_of(Array<Status, 5> { 101, 103, 204, 205, 304 }, [&](auto redirect_status) {
18 return status == redirect_status;
19 });
20}
21
22// https://fetch.spec.whatwg.org/#ok-status
23bool is_ok_status(Status status)
24{
25 // An ok status is a status in the range 200 to 299, inclusive.
26 return status >= 200 && status <= 299;
27}
28
29// https://fetch.spec.whatwg.org/#redirect-status
30bool is_redirect_status(Status status)
31{
32 // A redirect status is a status that is 301, 302, 303, 307, or 308.
33 return any_of(Array<Status, 5> { 301, 302, 303, 307, 308 }, [&](auto redirect_status) {
34 return status == redirect_status;
35 });
36}
37
38}