ProductOpener::HTTP - utility functions around http (handling headers, cookies, redirect, etc.)
ProductOpener::Web consists of functions used only in OpenFoodFacts website for different tasks.
The module implements http utilities to use in different part of the code.
FIXME: a lot of functions in Display.pm should be moved here.
This function sets a header in the response.
This function writes the headers in the response.
This function returns the extension and query parameters that can be added to a redirect URL. e.g. if the URL is /ingredients.json?filter=strawberry we get a .json?filter=strawberry
A string with the extension and query parameters that can be added to a redirect URL.
This function instructs mod_perl to print redirect HTTP header (Location) and to terminate the request immediately. The mod_perl process is not terminated and will continue to serve future requests.
The request object may contain a cookie.
e.g. 302 for a temporary redirect
CGI.pm param() function returns a list when called in a list context (e.g. when param() is an argument of a function, or the value of a field in a hash). This causes issues for function signatures that expect a scalar, and that may get passed an empty list if the parameter is not set.
So instead of calling CGI.pm param() directly, we call single_param() to prefix it with scalar.
A scalar value for the parameter, or undef if the parameter is not defined.
Return a request parameter. The parameter can be passed in the query string, as a POST multipart form data parameter, in a POST JSON body, or in cookies for some parameters like product attribute parameters
A scalar value for the parameter, or undef if the parameter is not defined.
Note that we really want to return undef, and not use an empty return statement, as otherwise code like
my $options_ref = {
limit => request_param($request_ref, 'limit'),
get_synonyms => request_param($request_ref, 'get_synonyms')
};
will result in 'limit' being set to 'get_synonyms' value when the 'limit' parameter is not passed.
This goes against https://metacpan.org/pod/Perl::Critic::Policy::Subroutines::ProhibitExplicitReturnUndef but we are not using return undef to indicate an error, but to indicate that the parameter is not defined.
Creates a standardized LWP::UserAgent
[$args] - (Optional) Optional constructor arguments for LWP::UserAgent->new()Creates a standardized HTTP client with correct user agent.
A new LWP::UserAgent instance