NAME

Test::HTTPStatus - check an HTTP status

SYNOPSIS

    use Test::HTTPStatus tests => 2;

    http_ok( 'https://www.perl.org', HTTP_OK );

    http_ok( $url, $status );

DESCRIPTION

Check the HTTP status for a resource.

FUNCTIONS

http_ok( URL [, HTTP_STATUS ] )

http_ok( $url, $expected_status );

Tests the HTTP status of the specified URL and reports whether it matches the expected status.

Parameters

Diagnostics

On success, the test will pass with a message in the following format:

Expected [<expected_status>], got [<actual_status>] for [<url>]

On failure, the test will fail with one of the following messages:

Examples

Return Value

The routine does not return any value. Instead, it reports success or failure using the underlying test builder's ok method.

Verify the accessibility of a given URL by checking its HTTP status code using Mojo::UserAgent. It first attempts to send a HEAD request to the provided link, which is useful for quickly checking if the resource exists without downloading its content. If the response indicates no error (i.e., status code is below 400), the function proceeds with a GET request to ensure a proper response is received. The function then validates whether a valid HTTP response was obtained and returns the corresponding status code. If the link is undefined or if no valid response is received, the function returns undef.

It is taken from the old module HTTP::SimpleLinkChecker.

user_agent

Returns the user agent being used

SEE ALSO

HTTP::SimpleLinkChecker, Mojo::URL

AUTHORS

brian d foy, <bdfoy@cpan.org>

Maintained by Nigel Horne, <njh at bandsman.co.uk>

SUPPORT

This module is provided as-is without any warranty.

You can find documentation for this module with the perldoc command.

perldoc Test::HTTPStatus

You can also look for information at:

LICENSE AND COPYRIGHT

This program is released under the following licence: GPL2 Copyright © 2002-2019, brian d foy bdfoy@cpan.org. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.