| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
|
| 4 |
use Test::More; |
| 5 |
|
| 6 |
use HTTP::Status qw(:constants :is status_message status_constant_name status_codes); |
| 7 |
|
| 8 |
is(HTTP_OK, 200); |
| 9 |
|
| 10 |
ok(is_info(HTTP_CONTINUE)); |
| 11 |
ok(is_success(HTTP_ACCEPTED)); |
| 12 |
ok(is_error(HTTP_BAD_REQUEST)); |
| 13 |
ok(is_redirect(HTTP_MOVED_PERMANENTLY)); |
| 14 |
ok(is_redirect(HTTP_PERMANENT_REDIRECT)); |
| 15 |
|
| 16 |
# renamed status constants |
| 17 |
ok(is_error(HTTP_REQUEST_ENTITY_TOO_LARGE)); |
| 18 |
ok(is_error(HTTP_PAYLOAD_TOO_LARGE)); |
| 19 |
ok(is_error(HTTP_REQUEST_URI_TOO_LARGE)); |
| 20 |
ok(is_error(HTTP_URI_TOO_LONG)); |
| 21 |
ok(is_error(HTTP_REQUEST_RANGE_NOT_SATISFIABLE)); |
| 22 |
ok(is_error(HTTP_RANGE_NOT_SATISFIABLE)); |
| 23 |
ok(is_error(HTTP_NO_CODE)); |
| 24 |
ok(is_error(HTTP_UNORDERED_COLLECTION)); |
| 25 |
ok(is_error(HTTP_TOO_EARLY)); |
| 26 |
ok(is_error(HTTP_UNPROCESSABLE_ENTITY)); |
| 27 |
ok(is_error(HTTP_PAYLOAD_TOO_LARGE)); |
| 28 |
|
| 29 |
# Have a sip and a great day |
| 30 |
ok(is_client_error(HTTP_I_AM_A_TEAPOT)); |
| 31 |
ok(is_error(HTTP_I_AM_A_TEAPOT)); |
| 32 |
is(status_message(418), "I'm a teapot"); |
| 33 |
|
| 34 |
ok(!is_success(HTTP_NOT_FOUND)); |
| 35 |
|
| 36 |
is(status_message( 0), undef); |
| 37 |
is(status_message(200), "OK"); |
| 38 |
is(status_message(404), "Not Found"); |
| 39 |
is(status_message(999), undef); |
| 40 |
|
| 41 |
|
| 42 |
ok(!is_info(HTTP_NOT_FOUND)); |
| 43 |
ok(!is_success(HTTP_NOT_FOUND)); |
| 44 |
ok(!is_redirect(HTTP_NOT_FOUND)); |
| 45 |
ok(!is_error(HTTP_CONTINUE)); |
| 46 |
ok(!is_client_error(HTTP_CONTINUE)); |
| 47 |
ok(!is_server_error(HTTP_NOT_FOUND)); |
| 48 |
ok(!is_server_error(999)); |
| 49 |
ok(!is_info(99)); |
| 50 |
ok(!is_success(99)); |
| 51 |
ok(!is_redirect(99)); |
| 52 |
|
| 53 |
ok(is_cacheable_by_default($_), |
| 54 |
"Cacheable by default [$_] " . status_message($_) |
| 55 |
) for (200,203,204,206,300,301,308,404,405,410,414,451,501); |
| 56 |
|
| 57 |
ok(!is_cacheable_by_default($_), |
| 58 |
"... is not cacheable [$_] " . status_message($_) |
| 59 |
) for (100,201,302,400,500); |
| 60 |
|
| 61 |
is(status_constant_name(HTTP_OK), "HTTP_OK"); |
| 62 |
is(status_constant_name(404), "HTTP_NOT_FOUND"); |
| 63 |
is(status_constant_name(999), undef); |
| 64 |
|
| 65 |
my %status_codes = status_codes(); |
| 66 |
is($status_codes{200}, status_message(200)); |
| 67 |
|
| 68 |
done_testing; |