Apache2-API

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

        # en_GB
        my $lang = $api->lang_unix;
        # en-GB
        my $lang = $api->lang_web;
        $api->log_error( "Oops" );
        $api->print( @some_data );
        $api->push_handlers( $name => $code_reference );
        return( $api->reply( Apache2::Const::HTTP_OK => {
            message => "All good!",
            # arbitrary property
            client_id => "efe4bcf3-730c-4cb2-99df-25d4027ec404",
            # special property
            cleanup => sub
            {
                # Some code here to be executed after the reply is sent out to the client.
            }
        }) );
        # Apache2::API::Request
        my $req = $api->request;
        # Apache2::API::Response
        my $req = $api->response;

README.md  view on Meta::CPAN

    # en_GB
    my $lang = $api->lang_unix;
    # en-GB
    my $lang = $api->lang_web;
    $api->log_error( "Oops" );
    $api->print( @some_data );
    $api->push_handlers( $name => $code_reference );
    return( $api->reply( Apache2::Const::HTTP_OK => {
        message => "All good!",
        # arbitrary property
        client_id => "efe4bcf3-730c-4cb2-99df-25d4027ec404",
        # special property
        cleanup => sub
        {
            # Some code here to be executed after the reply is sent out to the client.
        }
    }) );
    # Apache2::API::Request
    my $req = $api->request;
    # Apache2::API::Response
    my $req = $api->response;

SIGNATURE  view on Meta::CPAN

SHA256 3198471e2b96dcb3c40acfdb6f850236fcb8eb6cb448de9cff3785a82edb4a5a t/07.accept.t
SHA256 f1723cb11eca5b344a1705f90a49fb1ab648c7b4d2cff7c8c5a12065d18e5cff t/08.accept_language.t
SHA256 f493598fe4163465ad7539d49c32b84f335f320055e9715d554493b2cecac4c5 t/90.coverage.t
SHA256 4078280a2bd703e111776029e90998fec7e4401924a2272fe69f0122bee659be t/91.pod.t
SHA256 30bfc1987ae524f686d277a49167fac052caa782be018e4e581a8dd17d251474 t/92.signature.t
SHA256 3f93bfcebfe0951d578634d012f65734b40a0d68af4d32de03689b69b54c034d t/93.manifest.t
SHA256 610bb2233eaefa594359fd529387118cd79768ff3bdb1ce9a462dd382120df41 t/99.kwalitee.t
SHA256 926482972612b4093e5029c5701664d47e45ddda3989406366638ab563f4ea5c t/TEST.PL
SHA256 f5b29a1ddcebaf72d1221472b716f5afc7f14c8d016cf1617e3a3fa5a48ecb74 t/conf/extra.conf.in
SHA256 f457a704fb3849dcf8850402630672af57f6708b8689bd30b90addc4318ba8cc t/conf/options.conf.in
SHA256 bc96ffe5c07b48dce0acc8b4bc40732b4043bd9f7ac49ddfdb8f008b8833360a t/lib/Test/Apache2/API.pm
SHA256 de05f108a0799829c22c942f3d4d62811a737ecfd69ada3400ee4276b43cdc4b t/lib/Test/Apache2/API/Request.pm
SHA256 f6a8e6d44ab5d81c58be30709936f4cd0576e3dc5931da9fe2ec4338ff2c4862 t/lib/Test/Apache2/API/Response.pm
SHA256 26ec4e6759f280de9c870de9543341f0a40b4e5acac69af4bf808998d3122aeb t/lib/Test/Apache2/Common.pm
SHA256 ca4beff78eb1f5944fb9409db0c3fd48cccd4610d839a8b855d62a6980c1b086 t/server.crt
SHA256 15f7f65457b3abc0ee1b454bf06f658b88f685d233dcf96d1e11a5978f6be291 t/server.key
-----BEGIN PGP SIGNATURE-----

iQIzBAEBAwAdFiEENa28Ovg1XoRROdiWXzwCYc2y51IFAmnexWEACgkQXzwCYc2y
51LDFA/+ONv1bCCKGG1+5rQJ2V2qKsRVI2daH7pPNPLAKQf7+3SBBVRiWa2zLjql
2XkUSUv2HtdRcghZHcQN5zmOjAebBH363jUeMEJ1SYMn3C9/cY2dX0OKad8pr/jg

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

{
    my $self = shift( @_ );
    my( $code, $ref );
    my $use_rfc_error = $self->{use_rfc_error} // $USE_RFC_ERROR;
    # rfc9457 standard for REST API error response: <https://www.rfc-editor.org/rfc/rfc9457.html>
    # Legacy JSON payload like Google, Twitter, Facebook
    # Modern REST APIs now uses rfc9457 with a flattened payload.
    # When the use_rfc_error object property is true, we use rfc9457 flattened error, this will produce something like:
    # {
    #     error  => 'not_found',
    #     status => 404,
    #     title  => 'Not found!',
    #     detail => q{The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.},
    #     locale => 'en-US',
    #     type   => 'https://api.example.com/problems/not-found',
    # }
    # otherwise, the legacy approach would be:
    # {
    #     error =>
    #     {
    #         code => 404,
    #         message => q{The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.},
    #     },
    #     locale => 'en-US',
    # }
    # $self->reply( Apache2::Const::HTTP_OK, { message => "All is well" } );
    if( scalar( @_ ) == 2 )
    {
        ( $code, $ref ) = @_;
    }
    elsif( scalar( @_ ) == 1 &&

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

    # en_GB
    my $lang = $api->lang_unix;
    # en-GB
    my $lang = $api->lang_web;
    $api->log_error( "Oops" );
    $api->print( @some_data );
    $api->push_handlers( $name => $code_reference );
    return( $api->reply( Apache2::Const::HTTP_OK => {
        message => "All good!",
        # arbitrary property
        client_id => "efe4bcf3-730c-4cb2-99df-25d4027ec404",
        # special property
        cleanup => sub
        {
            # Some code here to be executed after the reply is sent out to the client.
        }
    }) );
    # Apache2::API::Request
    my $req = $api->request;
    # Apache2::API::Response
    my $req = $api->response;

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

# APR::Finfo
sub finfo { return( shift->_try( 'request', 'finfo' ) ) }

# example: CGI/1.1
sub gateway_interface { return( shift->env( 'GATEWAY_INTERFACE', @_ ) ); }

# $handlers_list = $r->get_handlers($hook_name);
# https://perl.apache.org/docs/2.0/api/Apache2/RequestUtil.html#C_get_handlers_
sub get_handlers { return( shift->_try( 'request', 'get_handlers', @_ ) ); }

# e.g. get_status_line( 404 ) would return 404 Not Found
sub get_status_line { return( shift->_try( 'request', 'get_status_line', @_ ) ); }

sub global_request { return( Apache2::RequestUtil->request ); }

sub has_auth { return( shift->_try( 'request', 'some_auth_required' ) ); }

sub header
{
    my $self = shift( @_ );
    return( $self->error( "No header field name was provided to set or retrieve its value." ) ) if( !scalar( @_ ) );

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

    my $hash_ref = $req->env;
    my $headers = $req->err_headers_out;
    # request filename
    my $filename = $req->filename;
    # APR::Finfo object
    my $finfo = $req->finfo;
    # e.g.: CGI/1.1
    my $gateway = $req->gateway_interface;
    my $code_ref = $req->get_handlers( $name );

    # 404 Not Found
    my $str = $req->get_status_line(404);
    my $r = $req->global_request;
    my $is_head = $req->header_only;
    # same
    my $is_head = $req->is_header_only;

    my $content_type = $req->headers( 'Content-Type' );
    # or (since it is case insensitive)
    my $content_type = $req->headers( 'content-type' );
    # or
    my $content_type = $req->headers->{'Content-Type'};

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

If nothing is provided, it returns a L<APR::Table> object.

=head2 err_headers_out

Get or sets HTTP response headers, which are printed out even on errors and persist across internal redirects.

According to the L<Apache2::RequestRec> documentation:

The difference between L</headers_out> (L<Apache2::RequestRec/headers_out>) and L</err_headers_out> (L<Apache2::RequestRec/err_headers_out>), is that the latter are printed even on error, and persist across internal redirects (so the headers printed ...

For example, if a handler wants to return a C<404> response, but nevertheless to set a cookie, it has to be:

    $req->err_headers_out->add( 'Set-Cookie' => $cookie );
    return( Apache2::Const::NOT_FOUND );

If the handler does:

    $req->headers_out->add( 'Set-Cookie' => $cookie );
    return( Apache2::Const::NOT_FOUND );

the C<Set-Cookie> header will not be sent.

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

Given one or more name => value pair, this will set them in the HTTP header using the L</err_headers_out> method.

=head2 err_headers_out

Get or sets HTTP response headers, which are printed out even on errors and persist across internal redirects.

According to the L<Apache2::RequestRec> documentation:

The difference between L</headers_out> (L<Apache2::RequestRec/headers_out>) and L</err_headers_out> (L<Apache2::RequestRec/err_headers_out>), is that the latter are printed even on error, and persist across internal redirects (so the headers printed ...

For example, if a handler wants to return a C<404> response, but nevertheless to set a cookie, it has to be:

    $resp->err_headers_out->add( 'Set-Cookie' => $cookie );
    return( Apache2::Const::NOT_FOUND );

If the handler does:

    $resp->headers_out->add( 'Set-Cookie' => $cookie );
    return( Apache2::Const::NOT_FOUND );

the C<Set-Cookie> header will not be sent.

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

        HTTP_MOVED_TEMPORARILY                  => 302,
        HTTP_SEE_OTHER                          => 303,
        HTTP_NOT_MODIFIED                       => 304,
        HTTP_USE_PROXY                          => 305,
        HTTP_TEMPORARY_REDIRECT                 => 307,
        HTTP_PERMANENT_REDIRECT                 => 308,
        HTTP_BAD_REQUEST                        => 400,
        HTTP_UNAUTHORIZED                       => 401,
        HTTP_PAYMENT_REQUIRED                   => 402,
        HTTP_FORBIDDEN                          => 403,
        HTTP_NOT_FOUND                          => 404,
        HTTP_METHOD_NOT_ALLOWED                 => 405,
        HTTP_NOT_ACCEPTABLE                     => 406,
        HTTP_PROXY_AUTHENTICATION_REQUIRED      => 407,
        HTTP_REQUEST_TIME_OUT                   => 408,
        HTTP_CONFLICT                           => 409,
        HTTP_GONE                               => 410,
        HTTP_LENGTH_REQUIRED                    => 411,
        HTTP_PRECONDITION_FAILED                => 412,
        HTTP_REQUEST_ENTITY_TOO_LARGE           => 413,
        # Compatibility with HTTP::Status

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

303 => Apache2::Const::HTTP_SEE_OTHER,
304 => Apache2::Const::HTTP_NOT_MODIFIED,
305 => Apache2::Const::HTTP_USE_PROXY,
307 => Apache2::Const::HTTP_TEMPORARY_REDIRECT,
308 => Apache2::Const::HTTP_PERMANENT_REDIRECT,
# Client error 4xx
400 => Apache2::Const::HTTP_BAD_REQUEST,
401 => Apache2::Const::HTTP_UNAUTHORIZED,
402 => Apache2::Const::HTTP_PAYMENT_REQUIRED,
403 => Apache2::Const::HTTP_FORBIDDEN,
404 => Apache2::Const::HTTP_NOT_FOUND,
405 => Apache2::Const::HTTP_METHOD_NOT_ALLOWED,
406 => Apache2::Const::HTTP_NOT_ACCEPTABLE,
407 => Apache2::Const::HTTP_PROXY_AUTHENTICATION_REQUIRED,
408 => Apache2::Const::HTTP_REQUEST_TIME_OUT,
409 => Apache2::Const::HTTP_CONFLICT,
410 => Apache2::Const::HTTP_GONE,
411 => Apache2::Const::HTTP_LENGTH_REQUIRED,
412 => Apache2::Const::HTTP_PRECONDITION_FAILED,
413 => Apache2::Const::HTTP_REQUEST_ENTITY_TOO_LARGE,
414 => Apache2::Const::HTTP_REQUEST_URI_TOO_LARGE,

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

        302 => "Dočasně přesunuto!",
        303 => "Viz jiné",
        304 => "Nezměněno",
        305 => "Použít proxy",
        307 => "Dočasné přesměrování!",
        308 => "Trvalé přesměrování!",
        400 => "Chybný požadavek!",
        401 => "Požadováno ověření!",
        402 => "Platba vyžadována!",
        403 => "Přístup odmítnut!",
        404 => "Objekt nenalezen!",
        405 => "Metoda nepovolena!",
        406 => "Nepřijatelné!",
        407 => "Požadováno ověření proxy!",
        408 => "Vypršel časový limit požadavku!",
        409 => "Konflikt!",
        410 => "Zdroj již není dále dostupný!",
        411 => "Chybná hlavička Content-Length!",
        412 => "Předběžná podmínka nesplněna!",
        413 => "Požadovaná entita je příliš velká!",
        414 => "Požadované URI je příliš dlouhé!",

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

        302 => "Vorübergehend verschoben!",
        303 => "Andere sehen",
        304 => "Nicht geändert",
        305 => "Proxy verwenden",
        307 => "Vorübergehende Umleitung!",
        308 => "Dauerhafte Umleitung!",
        400 => "Fehlerhafte Anfrage!",
        401 => "Authentifizierung erforderlich!",
        402 => "Zahlung erforderlich!",
        403 => "Zugriff verweigert!",
        404 => "Objekt nicht gefunden!",
        405 => "Methode nicht erlaubt!",
        406 => "Nicht akzeptabel!",
        407 => "Proxy-Authentifizierung erforderlich!",
        408 => "Zeitlimit überschritten!",
        409 => "Konflikt!",
        410 => "Objekt nicht mehr verfügbar!",
        411 => "Content-Length-Angabe fehlerhaft!",
        412 => "Vorbedingung nicht erfüllt!",
        413 => "Übergebene Daten zu groß!",
        414 => "Übergebener URI zu lang!",

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

        302 => "Found (temporary redirect)!",
        303 => "See Other",
        304 => "Not Modified",
        305 => "Use Proxy",
        307 => "Temporary redirect!",
        308 => "Permanent redirect!",
        400 => "Bad request!",
        401 => "Authentication required!",
        402 => "Payment required!",
        403 => "Access forbidden!",
        404 => "Object not found!",
        405 => "Method not allowed!",
        406 => "Not acceptable!",
        407 => "Proxy authentication required!",
        408 => "Request time-out!",
        409 => "Conflict!",
        410 => "Resource is no longer available!",
        411 => "Bad Content-Length!",
        412 => "Precondition failed!",
        413 => "Request entity too large!",
        414 => "Submitted URI too long!",

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

        302 => "¡Encontrado (redirección temporal)!",
        303 => "Ver otros",
        304 => "No modificado",
        305 => "Usar proxy",
        307 => "¡Redirección temporal!",
        308 => "¡Redirección permanente!",
        400 => "¡Petición errónea!",
        401 => "¡Autenticación requerida!",
        402 => "¡Pago requerido!",
        403 => "¡Acceso prohibido!",
        404 => "¡Objeto no localizado!",
        405 => "¡Método no permitido!",
        406 => "¡No aceptable!",
        407 => "¡Se requiere autenticación de proxy!",
        408 => "¡Tiempo de espera excedido!",
        409 => "¡Conflicto!",
        410 => "¡El recurso ya no está disponible!",
        411 => "¡Error en la longitud del contenido!",
        412 => "¡Fallo de precondición!",
        413 => "¡La entidad solicitada es demasiado grande!",
        414 => "¡El URI enviado es demasiado largo!",

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

        302 => "Trouvé (redirection temporaire) !",
        303 => "Voir ailleurs",
        304 => "Non modifié",
        305 => "Utiliser le proxy",
        307 => "Redirection temporaire !",
        308 => "Redirection permanente !",
        400 => "Requête incorrecte !",
        401 => "Authentification requise !",
        402 => "Paiement requis !",
        403 => "Accès interdit!",
        404 => "Objet non trouvé!",
        405 => "Méthode interdite!",
        406 => "Non acceptable !",
        407 => "Authentification proxy requise !",
        408 => "Délai d’attente de la requête dépassé !",
        409 => "Conflit !",
        410 => "Cette ressource n'existe plus!",
        411 => "Longueur du contenu invalide!",
        412 => "Échec de la précondition !",
        413 => "Corps de requête trop volumineux !",
        414 => "L’URI transmis est trop long !",

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

        302 => "Aimsíodh (atreorú sealadach)!",
        303 => "Féach eile",
        304 => "Gan athrú",
        305 => "Úsáid seachfhreastalaí",
        307 => "Atreorú sealadach!",
        308 => "Atreorú buan!",
        400 => "Iarratas mícheart!",
        401 => "Is gá fíordheimhniú!",
        402 => "Íocaíocht de dhíth!",
        403 => "Rochtain neamhcheadaithe!",
        404 => "Aidhm ar iarraidh!",
        405 => "Modh neamhcheadaithe!",
        406 => "Neamhghlactha!",
        407 => "Fíordheimhniú seachfhreastalaí de dhíth!",
        408 => "Iarratas thar am!",
        409 => "Coinbhleacht!",
        410 => "Acmhainn imithe!",
        411 => "Content-Length mícheart!",
        412 => "Theip ar réamhchoinníoll!",
        413 => "Eintiteas an iarratais ró-mhór!",
        414 => "URI ró-fhada cuirthe isteach!",

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

        302 => "Trovato (reindirizzamento temporaneo)!",
        303 => "Vedi altro",
        304 => "Non modificato",
        305 => "Usa proxy",
        307 => "Reindirizzamento temporaneo!",
        308 => "Reindirizzamento permanente!",
        400 => "Richiesta non valida!",
        401 => "Autenticazione richiesta!",
        402 => "È richiesto il pagamento!",
        403 => "Accesso negato!",
        404 => "Oggetto non trovato!",
        405 => "Metodo non consentito!",
        406 => "Non accettabile!",
        407 => "Autenticazione proxy richiesta!",
        408 => "Time-out della richiesta!",
        409 => "Conflitto!",
        410 => "La risorsa non è più disponibile!",
        411 => "Campo Content-Length non valido!",
        412 => "Precondizione non soddisfatta!",
        413 => "Entità della richiesta troppo grande!",
        414 => "URI troppo lungo!",

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

        302 => "一時的に移動しました!",
        303 => "他を参照せよ",
        304 => "未更新",
        305 => "プロキシを使用せよ",
        307 => "一時的なリダイレクト!",
        308 => "恒久的なリダイレクト!",
        400 => "不正なリクエスト!",
        401 => "認証が必要です!",
        402 => "お支払いが必要です!",
        403 => "アクセス拒否!",
        404 => "未検出!",
        405 => "許可されていないメソッド!",
        406 => "受理できません!",
        407 => "プロキシ認証が必要です!",
        408 => "リクエストタイムアウト!",
        409 => "競合が発生しました!",
        410 => "リソースはもう使えない!",
        411 => "不正なContent-Length!",
        412 => "前提条件を満たしていません!",
        413 => "ペイロードが大きすぎる!",
        414 => "URI が長すぎます!",

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

        302 => "임시로 이동되었습니다!",
        303 => "다른 참조",
        304 => "수정되지 않음",
        305 => "프록시 사용",
        307 => "임시 리디렉션!",
        308 => "영구 리디렉션!",
        400 => "잘못된 요청!",
        401 => "인증 필요!",
        402 => "결제가 필요합니다!",
        403 => "접근이 거부됨!",
        404 => "객체 없음!",
        405 => "허용되지 않는 요청 방식!",
        406 => "허용되지 않음!",
        407 => "프록시 인증이 필요합니다!",
        408 => "요청 시간 초과!",
        409 => "충돌!",
        410 => "요청한 리소스는 더 이상 제공되지 않습니다!",
        411 => "잘못된 Content-Length!",
        412 => "사전 조건이 충족되지 않았습니다!",
        413 => "요청 본문이 너무 큽니다!",
        414 => "제출한 URI가 너무 깁니다!",

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

        302 => "Funnet (midlertidig omdirigering)!",
        303 => "Se annet",
        304 => "Ikke endret",
        305 => "Bruk proxy",
        307 => "Midlertidig omdirigering!",
        308 => "Permanent omdirigering!",
        400 => "Ugyldig forespørsel!",
        401 => "Autentisering kreves!",
        402 => "Betaling kreves!",
        403 => "Adgang forbudt!",
        404 => "Objektet ble ikke funnet!",
        405 => "Metoden er ikke tillatt!",
        406 => "Ikke akseptabelt!",
        407 => "Proxy-autentisering kreves!",
        408 => "Tidsgrense overskredet!",
        409 => "Konflikt!",
        410 => "Ressursen er ikke lenger tilgjengelig!",
        411 => "Feil Content-Length!",
        412 => "Forutsetning ikke oppfylt!",
        413 => "Forespørselens innhold er for stort!",
        414 => "Forespurt URI for lang!",

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

        302 => "Gevonden (tijdelijke omleiding)!",
        303 => "Zie andere",
        304 => "Niet gewijzigd",
        305 => "Proxy gebruiken",
        307 => "Tijdelijke omleiding!",
        308 => "Permanente omleiding!",
        400 => "Ongeldig verzoek!",
        401 => "Authenticatie vereist!",
        402 => "Betaling vereist!",
        403 => "Toegang verboden!",
        404 => "Object niet gevonden!",
        405 => "Methode niet toegestaan!",
        406 => "Niet acceptabel!",
        407 => "Proxy-authenticatie vereist!",
        408 => "Tijdlimiet overschreden!",
        409 => "Conflict!",
        410 => "Dit object is niet langer beschikbaar!",
        411 => "Ongeldige Content-Length!",
        412 => "Voorwaarde niet voldaan!",
        413 => "Aanvraaginhoud te groot!",
        414 => "Aangeboden URI te lang!",

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

        302 => "Znaleziono (tymczasowe przekierowanie)!",
        303 => "Zobacz inne",
        304 => "Nie zmodyfikowano",
        305 => "Użyj serwera proxy",
        307 => "Tymczasowe przekierowanie!",
        308 => "Stałe przekierowanie!",
        400 => "Nieprawidłowe żądanie!",
        401 => "Wymagane uwierzytelnienie!",
        402 => "Wymagana płatność!",
        403 => "Zabroniony dostęp!",
        404 => "Nie znaleziono obiektu!",
        405 => "Niedozwolona metoda!",
        406 => "Nieakceptowalne!",
        407 => "Wymagana autoryzacja proxy!",
        408 => "Przedawnione żądanie!",
        409 => "Konflikt!",
        410 => "Zasób usunięty!",
        411 => "Błędny nagłówek Content-Length!",
        412 => "Warunek wstępny niespełniony!",
        413 => "Treść żądania zbyt duża!",
        414 => "Zbyt długie URI!",

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

        302 => "Encontrado (redirecionamento temporário)!",
        303 => "Ver outro",
        304 => "Não modificado",
        305 => "Usar proxy",
        307 => "Redirecionamento temporário!",
        308 => "Redirecionamento permanente!",
        400 => "Requisição inválida!",
        401 => "Autenticação necessária!",
        402 => "Pagamento necessário!",
        403 => "Acesso Proibido!",
        404 => "Objeto não encontrado!",
        405 => "Método não permitido!",
        406 => "Não aceitável!",
        407 => "Autenticação de proxy necessária!",
        408 => "Tempo excedido!",
        409 => "Conflito!",
        410 => "Recurso não está mais disponível!",
        411 => "Content-Length inválido!",
        412 => "Falha na pré-condição!",
        413 => "Volume de dados muito grande!",
        414 => "URI enviado é muito longo!",

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

        302 => "Encontrado (redirecionamento temporário)!",
        303 => "Ver outro",
        304 => "Não modificado",
        305 => "Usar proxy",
        307 => "Redirecionamento temporário!",
        308 => "Redirecionamento permanente!",
        400 => "Pedido incorreto!",
        401 => "Autenticação necessária!",
        402 => "Pagamento exigido!",
        403 => "Acesso proibido!",
        404 => "Objeto não encontrado!",
        405 => "Método não permitido!",
        406 => "Não aceitável!",
        407 => "Autenticação de proxy necessária!",
        408 => "Tempo excedido!",
        409 => "Conflito!",
        410 => "Recurso já não está disponível!",
        411 => "Content-Length incorreto!",
        412 => "Falha na pré-condição!",
        413 => "Volume de dados demasiado grande!",
        414 => "URI demasiado longo!",

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

        302 => "Găsit (redirecționare temporară)!",
        303 => "Vezi altele",
        304 => "Neschimbat",
        305 => "Utilizați proxy",
        307 => "Redirecționare temporară!",
        308 => "Redirecționare permanentă!",
        400 => "Cerere nevalidă!",
        401 => "Autentificare necesară!",
        402 => "Plata necesară!",
        403 => "Accesul interzis!",
        404 => "Obiectul nu a fost gasit!",
        405 => "Metodă nepermisă!",
        406 => "Inacceptabil!",
        407 => "Este necesară autentificarea prin proxy!",
        408 => "Time-out al cererii!",
        409 => "Conflict!",
        410 => "Resursa nu mai este disponibilă!",
        411 => "Content-Length invalid!",
        412 => "Precondiția a eșuat!",
        413 => "Entitatea cererii este prea mare!",
        414 => "URI-ul trimis este prea lung!",

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

        302 => "Найдено (временное перенаправление)!",
        303 => "смотреть другое",
        304 => "не изменялось",
        305 => "использовать прокси",
        307 => "Временное перенаправление!",
        308 => "Постоянное перенаправление!",
        400 => "Неверный запрос!",
        401 => "Необходима аутентификация!",
        402 => "Требуется оплата!",
        403 => "Доступ запрещён!",
        404 => "Объект не найден!",
        405 => "Метод не поддерживается!",
        406 => "Неприемлемо!",
        407 => "Требуется аутентификация прокси!",
        408 => "Истекло время ожидания!",
        409 => "Конфликт!",
        410 => "Документ удалён!",
        411 => "Неверный заголовок Content-Length!",
        412 => "Предусловие не выполнено!",
        413 => "Размер запроса слишком велик!",
        414 => "URI слишком длинный!",

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

        302 => "Пронађено (привремено преусмеравање)!",
        303 => "Погледај друго",
        304 => "Није измењено",
        305 => "Користи прокси",
        307 => "Привремено преусмеравање!",
        308 => "Трајно преусмеравање!",
        400 => "Лош захтев!",
        401 => "Обавезна аутентификација!",
        402 => "Потребно плаћање!",
        403 => "Забрањен приступ!",
        404 => "Објекат није пронађен!",
        405 => "Метод није дозвољен!",
        406 => "Неприхватљиво!",
        407 => "Потребна је прокси аутентикација!",
        408 => "Захтеву је истекло време!",
        409 => "Сукоб!",
        410 => "Ресурс није више доступан!",
        411 => "Неисправно Content-Length заглавље!",
        412 => "Предуслов није испуњен!",
        413 => "Тело захтева је превелико!",
        414 => "Послати УРИ је предугачак!",

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

        302 => "Hittad (tillfällig omdirigering)!",
        303 => "Se annat",
        304 => "Inte ändrad",
        305 => "Använd proxy",
        307 => "Tillfällig omdirigering!",
        308 => "Permanent omdirigering!",
        400 => "Felaktig förfrågan!",
        401 => "Autentisering krävs!",
        402 => "Betalning krävs!",
        403 => "Åtkomst förbjuden!",
        404 => "Objektet hittas ej!",
        405 => "Metoden inte tillåten!",
        406 => "Inte acceptabelt!",
        407 => "Proxyautentisering krävs!",
        408 => "Tidsgränsen överskreds!",
        409 => "Konflikt!",
        410 => "Resursen är inte längre tillgänglig!",
        411 => "Felaktig Content-Length!",
        412 => "Förhandsvillkor uppfylldes inte!",
        413 => "Begärans innehåll är för stort!",
        414 => "Efterfrågad URI för lång!",

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

        302 => "Bulundu (geçici yönlendirme)!",
        303 => "Başka bir yere bakın",
        304 => "DeÄŸiÅŸtirilmedi",
        305 => "Vekil sunucu kullan",
        307 => "Geçici yönlendirme!",
        308 => "Kalıcı yönlendirme!",
        400 => "Hatalı istek!",
        401 => "Kimlik doÄŸrulama gerekli!",
        402 => "Ödeme gerekli!",
        403 => "EriÅŸim engellendi!",
        404 => "Nesne mevcut deÄŸil!",
        405 => "Yönteme izin verilmedi!",
        406 => "Kabul edilemez!",
        407 => "Vekil sunucu kimlik doğrulaması gerekli!",
        408 => "İstekte zaman aşımı!",
        409 => "Çakışma!",
        410 => "Kaynak artık mevcut değil!",
        411 => "Hatalı Content-Length başlığı!",
        412 => "Önkoşul karşılanamadı!",
        413 => "İstek gövdesi çok büyük!",
        414 => "Gönderilen URI çok uzun!",

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

        302 => "已找到(临时重定向)!",
        303 => "查看其他",
        304 => "未修改",
        305 => "使用代理",
        307 => "临时重定向!",
        308 => "永久重定向!",
        400 => "无效请求!",
        401 => "需要认证!",
        402 => "需要付款!",
        403 => "禁止访问!",
        404 => "找不到对象!",
        405 => "请求的方法不允许!",
        406 => "不可接受!",
        407 => "需要代理身份验证!",
        408 => "请求超时!",
        409 => "冲突!",
        410 => "资源不再可用!",
        411 => "无效的 Content-Length!",
        412 => "先决条件未满足!",
        413 => "请求体过大!",
        414 => "提交的 URI 过长!",

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

        302 => "已找到(臨時重新導向)!",
        303 => "查看其他",
        304 => "未修改",
        305 => "使用代理",
        307 => "臨時重新導向!",
        308 => "永久重新導向!",
        400 => "請求錯誤!",
        401 => "需要認證!",
        402 => "需要付款!",
        403 => "禁止訪問!",
        404 => "找不到物件!",
        405 => "請求的方法不允許!",
        406 => "不可接受!",
        407 => "需要代理伺服器驗證!",
        408 => "請求超時!",
        409 => "衝突!",
        410 => "資源不再可用!",
        411 => "無效的 Content-Length!",
        412 => "先決條件未滿足!",
        413 => "請求體過大!",
        414 => "提交的 URI 過長!",

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

our $STATUS_TO_TYPE =
{
    301 => "moved_permanently",
    302 => "moved_temporarily",
    307 => "redirect_temporarily",
    308 => "redirect_permanent",
    400 => "bad_request",
    401 => "unauthorized",
    402 => "payment_required",
    403 => "forbidden",
    404 => "not_found",
    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",

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

    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, @_ ) ); }

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

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

# Returns a status line for a given code
# e.g. status_message( 404 ) would yield "Not found"
sub status_message
{
    my $self = shift( @_ );
    my( $code, $lang );
    if( scalar( @_ ) == 2 )
    {
        ( $code, $lang ) = @_;
    }
    else
    {

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


    my $status = Apache2::API::Status->new;
    say $status->status_message( 429 => 'ja_JP' );
    # Or without the language code parameter, it will default to en_GB
    say $status->status_message( 429 );

    # Is success
    say $status->is_info( 102 ); # true
    say $status->is_success( 200 ); # true
    say $status->is_redirect( 302 ); # true
    say $status->is_error( 404 ); # true
    say $status->is_client_error( 403 ); # true
    say $status->is_server_error( 501 ); # true

=head1 VERSION

    v0.2.1

=head1 DESCRIPTION

This module allows to get the localised version of the HTTP status for a given code for currently supported languages: fr_FR (French), en_GB (British English) and ja_JP (Japanese), de_DE (German), ko_KR (Korean), ru_RU (Russian), zh_CN (simplified Ch...

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

Provided with a 3-digits HTTP code and an optional language code such as C<en_GB> and this will return the status message in its localised form.

This is useful to provide response to error in the user preferred language. L<Apache2::API/reply> uses it to set a json response with the HTTP error code along with a localised status message.

If no language code is provided, this will default to C<en_GB>.

See L</supported_languages> for the supported languages.

=head2 status_to_type

Provided with a status code, such as C<404>, and this returns a status type such as C<not_found>.

This is used to build a rfc9457 compliant error.

=head2 supported_languages

This will return a sorted array reference of support languages for status codes.

The following language codes are currently supported: de_DE (German), en_GB (British English), fr_FR (French), ja_JP (Japanese), ko_KR (Korean), ru_RU (Russian) and zh_TW (Traditional Chinese as spoken in Taiwan).

Feel free to contribute those codes in other languages.

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

=head2 HTTP_FORBIDDEN (403)

See L<rfc 7231, section 6.5.3|https://tools.ietf.org/html/rfc7231#section-6.5.3>

See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403>

This is returned to indicate the client is barred from accessing the resource.

This is different from C<405 Method Not Allowed>, which is used when the client has proper permission to access the resource, but is using a method not allowed, such as using C<PUT> instead of C<GET> method.

=head2 HTTP_NOT_FOUND (404)

See L<rfc 7231, section 6.5.4|https://tools.ietf.org/html/rfc7231#section-6.5.4>

See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404>

This is returned to indicate the resource does not exist anymore.

=head2 HTTP_METHOD_NOT_ALLOWED (405)

See L<rfc 7231, section 6.5.5|https://tools.ietf.org/html/rfc7231#section-6.5.5>

This is returned to indicate the client it used a L<method|https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods> not allowed, such as using C<PUT> instead of C<GET>. The server can point out the supported methods with the C<Allow> header, such a...

    HTTP/1.1 405 Method Not Allowed

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

=head2 HTTP_CONFLICT (409)

See L<rfc 7231, section 6.5.8|https://tools.ietf.org/html/rfc7231#section-6.5.8>

This is returned to indicate a request conflict with the current state of the target resource, such as uploading with C<PUT> a file older than the remote one.

=head2 HTTP_GONE (410)

See L<rfc 7231, section 6.5.9|https://tools.ietf.org/html/rfc7231#section-6.5.9>

This is returned to indicate that the target resource is gone permanently. The subtle difference with the status code C<404> is that with C<404>, the resource may be only temporally unavailable whereas with C<410>, this is irremediable. For example:

    HTTP/1.1 410 Gone
    Server: Apache/2.4
    Content-Type: text/plain
    Content-Length: 30

    The resource has been removed.

=head2 HTTP_LENGTH_REQUIRED (411)

t/04.status.t  view on Meta::CPAN

        'HTTP_MOVED_TEMPORARILY'                  => 302,
        'HTTP_SEE_OTHER'                          => 303,
        'HTTP_NOT_MODIFIED'                       => 304,
        'HTTP_USE_PROXY'                          => 305,
        'HTTP_TEMPORARY_REDIRECT'                 => 307,
        'HTTP_PERMANENT_REDIRECT'                 => 308,
        'HTTP_BAD_REQUEST'                        => 400,
        'HTTP_UNAUTHORIZED'                       => 401,
        'HTTP_PAYMENT_REQUIRED'                   => 402,
        'HTTP_FORBIDDEN'                          => 403,
        'HTTP_NOT_FOUND'                          => 404,
        'HTTP_METHOD_NOT_ALLOWED'                 => 405,
        'HTTP_NOT_ACCEPTABLE'                     => 406,
        'HTTP_PROXY_AUTHENTICATION_REQUIRED'      => 407,
        'HTTP_REQUEST_TIME_OUT'                   => 408,
        'HTTP_CONFLICT'                           => 409,
        'HTTP_GONE'                               => 410,
        'HTTP_LENGTH_REQUIRED'                    => 411,
        'HTTP_PRECONDITION_FAILED'                => 412,
        'HTTP_REQUEST_ENTITY_TOO_LARGE'           => 413,
        'HTTP_REQUEST_URI_TOO_LARGE'              => 414,

t/04.status.t  view on Meta::CPAN

ok( $s->is_error( HTTP_REQUEST_RANGE_NOT_SATISFIABLE ), 'is_error' );
ok( $s->is_error( HTTP_RANGE_NOT_SATISFIABLE ), 'is_error' );
ok( $s->is_error( HTTP_NO_CODE ), 'is_error' );
ok( $s->is_error( HTTP_UNORDERED_COLLECTION ), 'is_error' );
ok( Apache2::API::Status->is_error( HTTP_TOO_EARLY ), 'is_error' );

ok( !$s->is_success( HTTP_NOT_FOUND ), 'is_success' );

is( $s->status_message(0), undef, 'status_message' );
is( $s->status_message(200), 'OK', 'status_message' );
is( $s->status_message(404), 'Object not found!', 'status_message' );
is( $s->status_message(999), undef, 'status_message' );


ok( !$s->is_info( HTTP_NOT_FOUND ), 'is_info' );
ok( !$s->is_success( HTTP_NOT_FOUND ), 'is_success' );
ok( !$s->is_redirect( HTTP_NOT_FOUND ), 'is_redirect' );
ok( !$s->is_error( HTTP_CONTINUE ), 'is_error' );
ok( !$s->is_client_error( HTTP_CONTINUE ), 'is_client_error' );
ok( !$s->is_server_error( HTTP_NOT_FOUND ), 'is_server_error' );
ok( !$s->is_server_error(999), 'is_server_error' );
ok( !$s->is_info(99), 'is_info' );
ok( !$s->is_success(99), 'is_success' );
ok( !$s->is_redirect(99), 'is_redirect' );

ok( $s->is_cacheable_by_default( $_ ),
  "Cacheable by default [$_] " . $s->status_message( $_ )
) for( 200, 203, 204, 206, 300, 301, 308, 404, 405, 410, 414, 451, 501 );

ok( !$s->is_cacheable_by_default( $_ ),
  "... is not cacheable [$_] " . $s->status_message( $_ )
) for( 100, 201, 302, 400, 500 );

done_testing();

__END__



( run in 2.125 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )