<<

NAME

ProductOpener::Routing - determines which page to display or API to call based on the URL path

DESCRIPTION

load_routes()

Load OFF routes

a route is registered with: - Pattern: - a simple string (e.g. "api") without '/'': when you simply want to route with the first component of the path e.g. product/1234 -> product_route No regex is involved. It uses a hash key

                - Or a pattern that capture arguments (e.g. "org/[orgid]"):
                        - The value of the orgid param will be stored in $request_ref->{param}{orgid}
                        - Ending the pattern with a / means that it can be followed by anything
                        ! Mind the priority of the routes, the first one that matches will be used
                
        - Handler (sub)
        - (optional) Options : {
                - name
                - regex: 1 if the pattern is a true regex, 0 by default. 
                  When you don't want to use the default limited one.
                  Use named captures to store the arguments in $request_ref->{param}
                }

non regex routes will be matched first, then regex routes

analyze_request ( $request_ref )

Analyze request parameters and decide which method to call.

Parameters

$request_ref reference to a hash that will contain analyzed parameters

Details

It will analyze path and parameters.

Some information is set in request_ref, notably - polished query_string - page number (page) - api version (e.g v3), api action (e.g product) and api method (e.g. GET or POST) - requested page (text) - some boolean for routing : search / taxonomy / mission / product / tag / points - parameters for products, mission, tags, etc.

It handles redirect for renamed texts or products, .well-known/change-password

Sometimes we modify request parameters (param) to correspond to request_ref: - parameters for response format : json, jsonp, xml, ... - code parameter

register_route($routes_to_register)

Register routes in the routes hash and regex_routes array.

Parameters

$routes_to_register

Array of arrays.

Each array should contain 3 elements: - the pattern - the route handler (sub) - (optional) options { - route_name - regex: if present then the pattern is considered as a true regex pattern and the default and limited one won't be used }

match_route($request_ref, @components)

Match a route based on the components of the request. non regex routes are matched first, then regex routes

sub extract_tagtype_and_tag_value_pairs_from_components($request_ref, $components_ref)

Extract tag type / tag value pairs and store them in an array $request_ref->{tags}

e.g. /category/breakfast-cereals/label/organic/brand/monoprix

Tags can be prefixed by a - to indicate that we want products without this tag

is_no_index_page ($request_ref)

Return 1 if the page should not be indexed by web crawlers based on analyzed request, 0 otherwise.

set_rate_limit_attributes ($request_ref, $ip)

Set attributes related to rate-limiting in the request object:

- rate_limiter_user_requests: the number of requests performed by the user for the current minute - rate_limiter_limit: the maximum number of requests allowed for the current minute - rate_limiter_blocking: 1 if the user has reached the rate-limit, 0 otherwise

<<