view release on metacpan or search on metacpan
lib/Apache2/API/Query.pm view on Meta::CPAN
=item has_changed()
If the query is actually changed by any of the modifier methods (strip, strip_except, strip_null, strip_like, or replace) it sets an internal changed flag which can be access by:
$qq->has_changed
revert() resets the has_changed flag to false.
=back
=head2 OUTPUT METHODS
=over 4
=item "$qq", stringify(), stringify($separator)
Return the current parameter set as a conventional param=value query string, using $separator as the separator if given. e.g.
foo=1&bar=2&bar=3
Note that all parameters and values are URI escaped by stringify(), so that query-string reserved characters do not occur within elements. For instance, a parameter set of:
lib/Apache2/API/Request.pm view on Meta::CPAN
{
$self->_load_class( 'Module::Generic::HeaderValue' ) || return( $self->pass_error );
# Typical value from Ajax call: application/json, text/javascript, */*
my $all = Module::Generic::HeaderValue->new_from_multi( $accept_raw ) ||
return( $self->pass_error( Module::Generic::HeaderValue->error ) );
$self->{acceptables} = $all;
}
return( $self->{acceptables} );
}
# The allowed methods, GET, POST, PUT, OPTIONS, HEAD, etc
sub allowed { return( shift->_try( 'request', 'allowed', @_ ) ); }
sub allow_methods { return( shift->_try( 'request', 'allow_methods', @_ ) ); }
sub allow_options { return( shift->_try( 'request', 'allow_options', @_ ) ); }
sub allow_overrides { return( shift->_try( 'request', 'allow_overrides', @_ ) ); }
# APR::Request::Apache2->handle( $r );
sub apr { return( shift->_set_get_object( { field => 'apr', no_init => 1 }, 'APR::Request', @_ ) ); }
lib/Apache2/API/Request.pm view on Meta::CPAN
# e.g.: gzip, deflate, br
my $encoding = $req->accept_encoding;
# en-GB,fr-FR;q=0.8,fr;q=0.6,ja;q=0.4,en;q=0.2
my $lang = $req->accept_language;
my $type = $req->accept_type;
my $version = $req->accept_version;
# GET, POST, PUT, OPTIONS, HEAD, etc
my $methods = $req->allowed;
# get an APR::Request::Apache2 object
my $apr = $req->apr;
# query string as an hash reference
my $hash_ref = $req->args; # also an APR::Request::Param::Table object
my $status = $req->args_status;
lib/Apache2/API/Request.pm view on Meta::CPAN
=item 1. C<application/json>
=item 2. C<text/javascript>
=item 3. C<*/*>
=back
=head2 allowed
Gets or sets the allowed methods bitmask such as GET, POST, PUT, OPTIONS, HEAD, etc, by calling L<Apache2::RequestRec/allowed>
It returns a bitvector of the allowed methods.
For example, if the module can handle only C<GET> and C<POST> methods it could start with:
use Apache2::API;
unless( $r->method_number == Apache2::Const::M_GET ||
$r->method_number == Apache2::Const::M_POST )
{
$r->allowed( $r->allowed | ( 1 << Apache2::Const::M_GET ) | ( 1 << Apache2::Const::M_POST ) );
return( Apache2::Const::HTTP_METHOD_NOT_ALLOWED );
}
See also L</allowed_methods>
=head2 allow_methods
$req->allow_methods( $reset );
$req->allow_methods( $reset, @methods );
Provided with a reset boolean and a list of HTTP methods, and this will set the allowed methods such as GET, POST, PUT, OPTIONS, HEAD, etc, by calling L<Apache2::Access/allow_methods>
If the reset boolean passed is a true value, then all the previously allowed methods are removed, otherwise they are left unchanged.
For example, to allow only C<GET> and C<POST>, notwithstanding what was set previously:
$req->allow_methods( 1, qw( GET POST ) );
It does not return anything. This is used only to set the allowed method. To retrieve them, see L</allowed>
=head2 allow_options
lib/Apache2/API/Status.pm view on Meta::CPAN
HTTP_FORBIDDEN
HTTP_NOT_FOUND
HTTP_OK
HTTP_TEMPORARY_REDIRECT
HTTP_INTERNAL_SERVER_ERROR
=head2 HTTP_CONTINUE (100)
See L<rfc 7231, section 5.1.1|https://tools.ietf.org/html/rfc7231#section-5.1.1> and section L<6.2.1|https://tools.ietf.org/html/rfc7231#section-6.2.1> and L<Mozilla docs|https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/100>
This is provisional response returned by the web server upon an abbreviated request to find out whether the web server will accept the actual request. For example when the client is sending a large file in chunks, such as in C<PUT> request (here a 74...
PUT /some//big/file.mp4 HTTP/1.1
Host: www.example.org
Content-Type: video/mp4
Content-Length: 778043392
Expect: 100-continue
If the server refused, it could return a C<413 Request Entity Too Large> or C<405 Method Not Allowed> or even C<401 Unauthorized>, or even a C<417 Expectation Failed> if it does not support this feature.
A response C<417 Expectation Failed> means the server is likely a HTTP/1.0 server or does not understand the request and the actual request must be sent, i.e. without the header field C<Expect: 100-continue>
In some REST API implementation, the server response code C<417> is used to mean the server understood the requested, but rejected it. This is a divergent use of the original purpose of this code.
lib/Apache2/API/Status.pm view on Meta::CPAN
<body>
<h1>Simple HTML5 webpage</h1>
<p>Hello, world!</p>
</body>
</html>
=head2 HTTP_CREATED (201)
See L<rfc7231, section 6.3.2|https://datatracker.ietf.org/doc/html/rfc7231#section-6.3.2>
This is returned to notify the related resource has been created, most likely by a C<PUT> request, such as:
PUT /some/where HTTP/1.1
Content-Type: text/html
Host: example.org
Then, the server would reply:
HTTP/1.1 201 Created
ETag: "foo-bar"
=head2 HTTP_ACCEPTED (202)
lib/Apache2/API/Status.pm view on Meta::CPAN
This was originally designed to inform the client that the resource could only be accessed once payment was made, but is now reserved and its current use is left at the discretion of the site implementing it.
=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
Content-Type: text/html
Content-Length: 32
Allow: GET, HEAD, OPTIONS, PUT
<h1>405 Try another method!</h1>
=head2 HTTP_NOT_ACCEPTABLE (406)
See L<rfc 7231, section 6.5.6|https://tools.ietf.org/html/rfc7231#section-6.5.6>
This is returned to the client to indicate its requirements are not supported and thus not acceptable. This is in response to L<Accept|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept>, L<Accept-Charset|https://developer.mozilla.org/e...
For example:
lib/Apache2/API/Status.pm view on Meta::CPAN
Connection: close
Content-Type: text/plain
Content-Length: 19
Too slow! Try again
=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
lib/Apache2/API/Status.pm view on Meta::CPAN
This is returned when the C<Content-Length> header was not provided by the client and the server requires it to be present. Most servers can do without.
=head2 HTTP_PRECONDITION_FAILED (412)
See L<rfc 7232 on Conditional Request|https://tools.ietf.org/html/rfc7232>
This is returned when some preconditions set by the client could not be met.
For example:
Issuing a C<PUT> request for a document if it does not already exist.
PUT /foo/new-article.md HTTP/1.1
Content-Type: text/markdown
If-None-Match: *
Update a document if it has not changed since last time (etag)
PUT /foo/old-article.md HTTP/1.1
If-Match: "1345-12315"
Content-Type: text/markdown
If those failed, it would return something like:
HTTP/1.1 412 Precondition Failed
Content-Type: text/plain
Content-Length: 64
The article you are tring to update has changed since last time.
If one adds the C<Prefer> header, the servers will return the current state of the resource, thus saving a round of request with a C<GET>, such as:
PUT /foo/old-article.md HTTP/1.1
If-Match: "1345-12315"
Content-Type: text/markdown
Prefer: return=representation
### Article version 2.1
Then, the server would respond something like:
HTTP/1.1 412 Precondition Failed
Content-Type: text/markdown
lib/Apache2/API/Status.pm view on Meta::CPAN
Same as previous. Used here for compatibility with C<HTTP::Status>
=head2 HTTP_EXPECTATION_FAILED (417)
See L<rfc 7231, section 6.5.14|https://tools.ietf.org/html/rfc7231#section-6.5.14>
This is returned when the server received an C<Expect> header field value it did not understand.
For example:
PUT /some//big/file.mp4 HTTP/1.1
Host: www.example.org
Content-Type: video/mp4
Content-Length: 778043392
Expect: 100-continue
Then, the server could respond with the following:
HTTP/1.1 417 Expectation Failed
Server: Apache/2.4
Content-Type: text/plain
lib/Apache2/API/Status.pm view on Meta::CPAN
Host: www.example.org
Accept: text/html; image/png; text/*; q=0.9
Accept-Language: en-GB; en
Accept-Charset: UTF-8
Accept-Encoding: gzip, deflate, br
=head2 HTTP_INSUFFICIENT_STORAGE (507)
See L<rfc 4918, section 11.5 on WebDAV|https://tools.ietf.org/html/rfc4918#section-11.5>
This is returned in the context of WebDav protocol when a C<POST> or C<PUT> request leads to storing data, but the operations fails, because the resource is too large to fit on the remaining space on the server disk.
=head2 HTTP_LOOP_DETECTED (508)
See L<rfc 5842, section 7.2 on WebDAV bindings|https://tools.ietf.org/html/rfc5842#section-7.2>
This is returned in the context of WebDav when the target resource is looping.
=head2 HTTP_BANDWIDTH_LIMIT_EXCEEDED (509)
This is returned by some web servers when the amount of bandwidth consumed exceeded the maximum possible.
t/lib/Test/Apache2/API/Request.pm view on Meta::CPAN
}
}
else
{
$opts->{log}->( "\$ref->[0] is not an Module::Generic::HeaderValue object." );
}
$cnt++ if( Scalar::Util::blessed( $ref->[1] ) && $ref->[1]->isa( 'Module::Generic::HeaderValue' ) && $ref->[1]->value->first eq 'text/javascript' );
}
} }) ); }
# The allowed methods, GET, POST, PUT, OPTIONS, HEAD, etc
sub allowed { return( shift->_test({ method => 'allowed', expect => sub
{
my $bitmask = shift( @_ );
my $opts = shift( @_ );
my $self = $opts->{object};
my $req = $self->api->request;
my $r = $self->_request;
my $cnt = 0;
$opts->{log}->( "\$bitmask is '$bitmask'" );
$opts->{log}->( "\$req->method_number = '" . $req->method_number . "'" );