Отменен

Nginx Module, Request intercept handler (1796702)

A Nginx module that intercepts requests and check if the request is cached. Outputs cached data or passes through the request to the next handler.

## Deliverables

Module Name: CoconutRouteCache The module can be enabled for the any of the directives (http/server/host). And only intercepts requests for that directive. Should handle these nginx config keys. coconut_route_cache_config_file '[url removed, login to view]' coconut_route_cache on or off coconut_route_redis_host '127.0.0.1' coconut_route_redis_port 6379 coconut_route_redis_db 1 * Reads JSON file: When nginx starts or reloads, the module should read the config file which is a JSON file, and store the data in memory. Also precompile all regexes, so they don't need to compile for every request. When nginx reloads gracefully, the config file has to be re-read because the config file can be changed. The saved config and compiled regexes will be later accessed on the function defined on the next point. If config file isn't found on start of nginx, log with crit and stop. Also do the same if the json parsing failed. Also if configuration is missing for redis, log with crit and stop but only if coconut_route_cache is set to on. The json file will contain multiple routes: { "index": { "regex": '/^(\/|\/[url removed, login to view])?$/', "action": 'Shop/cat/all' }, "category": { "regex": '/^\/([a-zA-Z0-9_-]+)\.html$/', "action": 'Shop/cat/$1' } } * Handle requests when a directive has the config 'coconut_route_cache' set to 'on' The module after its should then intercept all the requests before the request reached to the PHPbackend. When intercepted, the handler should loop through all routes in the config read given. Do a PCRE regexec against the request uri and "regex", continue until match is found. When match is found: 1. Check if there are submatches, if so: get the "action" from the route and replace the $1 with the first sub match found from the regexec function. Store the replacement in a variable called "action". Also even if there weren't any sub matches, just store the contents to that variable. It should handle to replace more than $1, the number just represent the position of the sub match. A regex could have more than one sub match, so it should handle $2+. 2. Create a variable: cache_key_no_session = SHA1(action) cache_key_session = SHA1(action + "|" + the contents of the COOKIE named 's') 3. Connect to redis using a connect function described later. Do a multi key get with the value of cache_key_no_session and cache_key_session. If at least one of the keys returned a string result then output the contents and end the request. If both keys are missed in redis cache, then pass through the request, but also include a request header "COCONUT_ROUTE_CACHE_KEY" with the value. So that the PHP scripts can access that header. Connect to redis function (Use the Asynch api from hiredis) The connection should be persistent between requests, just like the config above. There should be a seperate pconnect_to_redis function, that first checks if there already is a connection to redis, if so try to do the ping command and check that pong is replied. If pong isn't replied try to re-connect. If there is no redis connection already, then connect. If connection failure, error log with warning and pass through the request to the PHPbackend. * Latest: nginx, redis, pcre, json parsing: [url removed, login to view] * Planning tips 1. create a module that just logs all request before they are passed 2. setup config and validate, log 3. connect to redis and save a persistent connection, log 4. do ping/pong check with redis every request, log output, if fail reconnect and try again 5. read json file and compile regexes and keep stored in memory 6. implement the route identification and send header to next handler, verify that header is found 7. build cache key and check with redis 8. if cache exists output the data and close connection, else pass.

Квалификация: Программирование на С, Управление базами данных, Linux, MySQL, Установка скриптов, Shell Script, Архитектура ПО, SQL, UNIX

Показать больше nginx intercept json requests, using regex in c, regex matches, regex in c, regex c, redis get, programming tips, programming module, programming loop, programming function keys, persistent module, nginx 0.7, module programming, loop programming, index php cat, c programming regex, cache programming, at&t route it, json programming, redis

О работодателе:
( 0 отзыв(-а, -ов) ) Norrkoping, Sweden

ID проекта: #3756882

1 фрилансер в среднем готов выполнить эту работу за $255

alexpast

See private message.

$255 USD за 7 дней(-я)
(24 отзывов(-а))
5.3