Statuses.cpp 1.0 KB

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