<<

NAME

ProductOpener::HTTP - utility functions around http (handling headers, cookies, redirect, etc.)

SYNOPSIS

ProductOpener::Web consists of functions used only in OpenFoodFacts website for different tasks.

DESCRIPTION

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.

FUNCTIONS

get_cors_headers($allow_credentials = 0, $sub_domain_only = 0)

We handle CORS headers from Perl code, NGINX should not interfere. So this is the central place for it.

Some parts needs to be more strict than others (eg. auth).

Parameters

$allow_credentials - boolean

Whether we should add the Access-Control-Allow-Credential header, should be used with caution. We will effectively put the headers only if subdomains matches.

We need to send the header Access-Control-Allow-Credentials=true so that websites such has hunger.openfoodfacts.org that send a query to world.openfoodfacts.org/cgi/auth.pl can read the resulting response.

$sub_domain_only - boolean

If true tells to restrict Access to main domain, that is domain.tld (eg. openfoodfacts.org) It defaults to False, but as a precaution, setting $allow_credentials to True turns it to True, if allow-credentials is given.

returns

Reference to a Hashmap with headers.

write_cors_headers($allow_credentials = 0, $sub_domain_only = 0)

This function write cors_headers in response.

see get_cors_headers to see how they are computed and parameters

set_http_response_header($request_ref, $header_name, $header_value)

This function sets a header in the response.

Parameters

$request_ref - Reference to the request object.

$header_name - Name of the header.

$header_value - Value of the header.

write_http_response_headers($request_ref)

This function writes the headers in the response.

Parameters

$request_ref - Reference to the request object.

<<