Apache2-API

 view release on metacpan or  search on metacpan

lib/Apache2/API/Status.pm  view on Meta::CPAN

    405 => "method_not_allowed",
    406 => "not_acceptable",
    407 => "proxy_authentication_required",
    408 => "request_time_out",
    409 => "conflict",
    410 => "gone",
    411 => "length_required",
    412 => "precondition_failed",
    413 => "request_entity_too_large",
    414 => "request_uri_too_large",
    415 => "unsupported_media_type",
    416 => "range_not_satisfiable",
    417 => "expectation_failed",
    422 => "unprocessable_entity",
    423 => "locked",
    424 => "failed_dependency",
    425 => "too_early",
    426 => "upgrade_required",
    429 => "too_many_requests",
    431 => "request_header_fields_too_large",
    451 => "unavailable_for_legal_reasons",
    500 => "internal_server_error",
    501 => "not_implemented",
    502 => "bad_gateway",
    503 => "service_unavailable",
    504 => "gateway_timeout",
    505 => "http_version_not_supported",
    506 => "variant_also_varies",
    507 => "insufficient_storage",
    508 => "loop_detected",
};

# Missing constants in Apache2::Const
my $additions =
{
103 => 'EARLY_HINTS',
418 => 'I_AM_A_TEA_POT',
421 => 'MISDIRECTED_REQUEST',
425 => 'TOO_EARLY',
444 => 'CONNECTION_CLOSED_WITHOUT_RESPONSE',
451 => 'UNAVAILABLE_FOR_LEGAL_REASONS',
499 => 'CLIENT_CLOSED_REQUEST',
505 => 'HTTP_VERSION_NOT_SUPPORTED',
509 => 'BANDWIDTH_LIMIT_EXCEEDED',
599 => 'NETWORK_CONNECT_TIMEOUT_ERROR',
};

foreach my $code ( keys( %$additions ) )
{
    unless( Apache2::Const->can( $additions->{ $code } ) )
    {
        eval( "*Apache2::Const::" . $additions->{ $code } . " = sub{$code};" );
        warn( "Error adding Apache2::Const for HTTP code $code: $@" ) if( $@ );
    }
}

sub init
{
    my $self = shift( @_ );
    my $r = shift( @_ );
    $self->SUPER::init( @_ );
    return( $self );
}

sub convert_short_lang_to_long
{
	my $self = shift( @_ );
	my $lang = shift( @_ );
	# Nothing to do; we already have a good value
	return( $lang ) if( $lang =~ /^[a-z]{2}_[A-Z]{2}$/ );
	return( $MAP_LANG_SHORT->{ lc( $lang ) } ) if( CORE::exists( $MAP_LANG_SHORT->{ lc( $lang ) } ) );
	return( '' );
}

sub is_cacheable_by_default
{
    my $self = shift( @_ );
    my $code = shift( @_ );
    return( $self->error( "A 3 digit code is required." ) ) if( !defined( $code ) || $code !~ /^\d{3}$/ );
    return(
           $code == 200 # OK
        || $code == 203 # Non-Authoritative Information
        || $code == 204 # No Content
        || $code == 206 # Not Acceptable
        || $code == 300 # Multiple Choices
        || $code == 301 # Moved Permanently
        || $code == 308 # Permanent Redirect
        || $code == 404 # Not Found
        || $code == 405 # Method Not Allowed
        || $code == 410 # Gone
        || $code == 414 # Request-URI Too Large
        || $code == 451 # Unavailable For Legal Reasons
        || $code == 501 # Not Implemented
    );
}

sub is_client_error { return( shift->_min_max( 400 => 500, @_ ) ); }

sub is_error { return( shift->_min_max( 400 => 600, @_ ) ); }

sub is_info { return( shift->_min_max( 100 => 200, @_ ) ); }

sub is_redirect { return( shift->_min_max( 300 => 400, @_ ) ); }

sub is_server_error { return( shift->_min_max( 500 => 600, @_ ) ); }

sub is_success { return( shift->_min_max( 200 => 300, @_ ) ); }

sub status_to_type
{
    my $self = shift( @_ );
    my $code = shift( @_ );
    my $sep  = shift( @_ );
    if( !defined( $sep ) ||
        ( defined( $sep ) && $sep eq '_' ) )
    {
        return( $STATUS_TO_TYPE->{ $code } );
    }
    ( my $type = $STATUS_TO_TYPE->{ $code } ) =~ s/_/$sep/g;
    return( $type );
}



( run in 0.978 second using v1.01-cache-2.11-cpan-437f7b0c052 )