8437 lines
700 KiB
HTML
8437 lines
700 KiB
HTML
<!DOCTYPE html><html lang="fr">
|
||
<head><meta charset="utf-8">
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"><title>ngx_lua - YannStatic</title>
|
||
|
||
<meta name="description" content="Name">
|
||
<link rel="canonical" href="https://static.rnmkcy.eu/2019/12/25/ngx_lua.html"><link rel="alternate" type="application/rss+xml" title="YannStatic" href="/feed.xml">
|
||
|
||
<!-- - include head/favicon.html - -->
|
||
<link rel="shortcut icon" type="image/png" href="/assets/favicon/favicon.png"><link rel="stylesheet" href="/assets/css/main.css"><link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" ><!-- start custom head snippets --><link rel="stylesheet" href="/assets/css/expand.css">
|
||
<!-- end custom head snippets --><script>(function() {
|
||
window.isArray = function(val) {
|
||
return Object.prototype.toString.call(val) === '[object Array]';
|
||
};
|
||
window.isString = function(val) {
|
||
return typeof val === 'string';
|
||
};
|
||
|
||
window.hasEvent = function(event) {
|
||
return 'on'.concat(event) in window.document;
|
||
};
|
||
|
||
window.isOverallScroller = function(node) {
|
||
return node === document.documentElement || node === document.body || node === window;
|
||
};
|
||
|
||
window.isFormElement = function(node) {
|
||
var tagName = node.tagName;
|
||
return tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA';
|
||
};
|
||
|
||
window.pageLoad = (function () {
|
||
var loaded = false, cbs = [];
|
||
window.addEventListener('load', function () {
|
||
var i;
|
||
loaded = true;
|
||
if (cbs.length > 0) {
|
||
for (i = 0; i < cbs.length; i++) {
|
||
cbs[i]();
|
||
}
|
||
}
|
||
});
|
||
return {
|
||
then: function(cb) {
|
||
cb && (loaded ? cb() : (cbs.push(cb)));
|
||
}
|
||
};
|
||
})();
|
||
})();
|
||
(function() {
|
||
window.throttle = function(func, wait) {
|
||
var args, result, thisArg, timeoutId, lastCalled = 0;
|
||
|
||
function trailingCall() {
|
||
lastCalled = new Date;
|
||
timeoutId = null;
|
||
result = func.apply(thisArg, args);
|
||
}
|
||
return function() {
|
||
var now = new Date,
|
||
remaining = wait - (now - lastCalled);
|
||
|
||
args = arguments;
|
||
thisArg = this;
|
||
|
||
if (remaining <= 0) {
|
||
clearTimeout(timeoutId);
|
||
timeoutId = null;
|
||
lastCalled = now;
|
||
result = func.apply(thisArg, args);
|
||
} else if (!timeoutId) {
|
||
timeoutId = setTimeout(trailingCall, remaining);
|
||
}
|
||
return result;
|
||
};
|
||
};
|
||
})();
|
||
(function() {
|
||
var Set = (function() {
|
||
var add = function(item) {
|
||
var i, data = this._data;
|
||
for (i = 0; i < data.length; i++) {
|
||
if (data[i] === item) {
|
||
return;
|
||
}
|
||
}
|
||
this.size ++;
|
||
data.push(item);
|
||
return data;
|
||
};
|
||
|
||
var Set = function(data) {
|
||
this.size = 0;
|
||
this._data = [];
|
||
var i;
|
||
if (data.length > 0) {
|
||
for (i = 0; i < data.length; i++) {
|
||
add.call(this, data[i]);
|
||
}
|
||
}
|
||
};
|
||
Set.prototype.add = add;
|
||
Set.prototype.get = function(index) { return this._data[index]; };
|
||
Set.prototype.has = function(item) {
|
||
var i, data = this._data;
|
||
for (i = 0; i < data.length; i++) {
|
||
if (this.get(i) === item) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
};
|
||
Set.prototype.is = function(map) {
|
||
if (map._data.length !== this._data.length) { return false; }
|
||
var i, j, flag, tData = this._data, mData = map._data;
|
||
for (i = 0; i < tData.length; i++) {
|
||
for (flag = false, j = 0; j < mData.length; j++) {
|
||
if (tData[i] === mData[j]) {
|
||
flag = true;
|
||
break;
|
||
}
|
||
}
|
||
if (!flag) { return false; }
|
||
}
|
||
return true;
|
||
};
|
||
Set.prototype.values = function() {
|
||
return this._data;
|
||
};
|
||
return Set;
|
||
})();
|
||
|
||
window.Lazyload = (function(doc) {
|
||
var queue = {js: [], css: []}, sources = {js: {}, css: {}}, context = this;
|
||
var createNode = function(name, attrs) {
|
||
var node = doc.createElement(name), attr;
|
||
for (attr in attrs) {
|
||
if (attrs.hasOwnProperty(attr)) {
|
||
node.setAttribute(attr, attrs[attr]);
|
||
}
|
||
}
|
||
return node;
|
||
};
|
||
var end = function(type, url) {
|
||
var s, q, qi, cbs, i, j, cur, val, flag;
|
||
if (type === 'js' || type ==='css') {
|
||
s = sources[type], q = queue[type];
|
||
s[url] = true;
|
||
for (i = 0; i < q.length; i++) {
|
||
cur = q[i];
|
||
if (cur.urls.has(url)) {
|
||
qi = cur, val = qi.urls.values();
|
||
qi && (cbs = qi.callbacks);
|
||
for (flag = true, j = 0; j < val.length; j++) {
|
||
cur = val[j];
|
||
if (!s[cur]) {
|
||
flag = false;
|
||
}
|
||
}
|
||
if (flag && cbs && cbs.length > 0) {
|
||
for (j = 0; j < cbs.length; j++) {
|
||
cbs[j].call(context);
|
||
}
|
||
qi.load = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
};
|
||
var load = function(type, urls, callback) {
|
||
var s, q, qi, node, i, cur,
|
||
_urls = typeof urls === 'string' ? new Set([urls]) : new Set(urls), val, url;
|
||
if (type === 'js' || type ==='css') {
|
||
s = sources[type], q = queue[type];
|
||
for (i = 0; i < q.length; i++) {
|
||
cur = q[i];
|
||
if (_urls.is(cur.urls)) {
|
||
qi = cur;
|
||
break;
|
||
}
|
||
}
|
||
val = _urls.values();
|
||
if (qi) {
|
||
callback && (qi.load || qi.callbacks.push(callback));
|
||
callback && (qi.load && callback());
|
||
} else {
|
||
q.push({
|
||
urls: _urls,
|
||
callbacks: callback ? [callback] : [],
|
||
load: false
|
||
});
|
||
for (i = 0; i < val.length; i++) {
|
||
node = null, url = val[i];
|
||
if (s[url] === undefined) {
|
||
(type === 'js' ) && (node = createNode('script', { src: url }));
|
||
(type === 'css') && (node = createNode('link', { rel: 'stylesheet', href: url }));
|
||
if (node) {
|
||
node.onload = (function(type, url) {
|
||
return function() {
|
||
end(type, url);
|
||
};
|
||
})(type, url);
|
||
(doc.head || doc.body).appendChild(node);
|
||
s[url] = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
};
|
||
return {
|
||
js: function(url, callback) {
|
||
load('js', url, callback);
|
||
},
|
||
css: function(url, callback) {
|
||
load('css', url, callback);
|
||
}
|
||
};
|
||
})(this.document);
|
||
})();
|
||
</script><script>
|
||
(function() {
|
||
var TEXT_VARIABLES = {
|
||
version: '2.2.6',
|
||
sources: {
|
||
font_awesome: 'https://use.fontawesome.com/releases/v5.0.13/css/all.css',
|
||
jquery: '/assets/js/jquery.min.js',
|
||
leancloud_js_sdk: '//cdn.jsdelivr.net/npm/leancloud-storage@3.13.2/dist/av-min.js',
|
||
chart: 'https://cdn.bootcss.com/Chart.js/2.7.2/Chart.bundle.min.js',
|
||
gitalk: {
|
||
js: 'https://cdn.bootcss.com/gitalk/1.2.2/gitalk.min.js',
|
||
css: 'https://cdn.bootcss.com/gitalk/1.2.2/gitalk.min.css'
|
||
},
|
||
valine: 'https://unpkg.com/valine/dist/Valine.min.js'
|
||
},
|
||
site: {
|
||
toc: {
|
||
selectors: 'h1,h2,h3'
|
||
}
|
||
},
|
||
paths: {
|
||
search_js: '/assets/search.js'
|
||
}
|
||
};
|
||
window.TEXT_VARIABLES = TEXT_VARIABLES;
|
||
})();
|
||
</script>
|
||
</head>
|
||
<body>
|
||
<div class="root" data-is-touch="false">
|
||
<div class="layout--page js-page-root"><!----><div class="page__main js-page-main page__viewport hide-footer has-aside has-aside cell cell--auto">
|
||
|
||
<div class="page__main-inner"><div class="page__header d-print-none"><header class="header"><div class="main">
|
||
<div class="header__title">
|
||
<div class="header__brand"><svg id="svg" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400" height="478.9473684210526" viewBox="0, 0, 400,478.9473684210526"><g id="svgg"><path id="path0" d="M308.400 56.805 C 306.970 56.966,303.280 57.385,300.200 57.738 C 290.906 58.803,278.299 59.676,269.200 59.887 L 260.600 60.085 259.400 61.171 C 258.010 62.428,256.198 63.600,255.645 63.600 C 255.070 63.600,252.887 65.897,252.598 66.806 C 252.460 67.243,252.206 67.600,252.034 67.600 C 251.397 67.600,247.206 71.509,247.202 72.107 C 247.201 72.275,246.390 73.190,245.400 74.138 C 243.961 75.517,243.598 76.137,243.592 77.231 C 243.579 79.293,241.785 83.966,240.470 85.364 C 239.176 86.740,238.522 88.365,237.991 91.521 C 237.631 93.665,236.114 97.200,235.554 97.200 C 234.938 97.200,232.737 102.354,232.450 104.472 C 232.158 106.625,230.879 109.226,229.535 110.400 C 228.933 110.926,228.171 113.162,226.434 119.500 C 226.178 120.435,225.795 121.200,225.584 121.200 C 225.373 121.200,225.200 121.476,225.200 121.813 C 225.200 122.149,224.885 122.541,224.500 122.683 C 223.606 123.013,223.214 123.593,223.204 124.600 C 223.183 126.555,220.763 132.911,219.410 134.562 C 218.443 135.742,217.876 136.956,217.599 138.440 C 217.041 141.424,215.177 146.434,214.532 146.681 C 214.240 146.794,214.000 147.055,214.000 147.261 C 214.000 147.467,213.550 148.086,213.000 148.636 C 212.450 149.186,212.000 149.893,212.000 150.208 C 212.000 151.386,208.441 154.450,207.597 153.998 C 206.319 153.315,204.913 150.379,204.633 147.811 C 204.365 145.357,202.848 142.147,201.759 141.729 C 200.967 141.425,199.200 137.451,199.200 135.974 C 199.200 134.629,198.435 133.224,196.660 131.311 C 195.363 129.913,194.572 128.123,193.870 125.000 C 193.623 123.900,193.236 122.793,193.010 122.540 C 190.863 120.133,190.147 118.880,188.978 115.481 C 188.100 112.928,187.151 111.003,186.254 109.955 C 185.358 108.908,184.518 107.204,183.847 105.073 C 183.280 103.273,182.497 101.329,182.108 100.753 C 181.719 100.177,180.904 98.997,180.298 98.131 C 179.693 97.265,178.939 95.576,178.624 94.378 C 178.041 92.159,177.125 90.326,175.023 87.168 C 174.375 86.196,173.619 84.539,173.342 83.486 C 172.800 81.429,171.529 79.567,170.131 78.785 C 169.654 78.517,168.697 77.511,168.006 76.549 C 167.316 75.587,166.594 74.800,166.402 74.800 C 166.210 74.800,164.869 73.633,163.421 72.206 C 160.103 68.936,161.107 69.109,146.550 69.301 C 133.437 69.474,128.581 70.162,126.618 72.124 C 126.248 72.495,125.462 72.904,124.872 73.033 C 124.282 73.163,123.088 73.536,122.219 73.863 C 121.349 74.191,119.028 74.638,117.061 74.858 C 113.514 75.254,109.970 76.350,108.782 77.419 C 107.652 78.436,100.146 80.400,97.388 80.400 C 95.775 80.400,93.167 81.360,91.200 82.679 C 90.430 83.195,89.113 83.804,88.274 84.031 C 85.875 84.681,78.799 90.910,74.400 96.243 L 73.400 97.456 73.455 106.028 C 73.526 117.055,74.527 121.238,77.820 124.263 C 78.919 125.273,80.400 127.902,80.400 128.842 C 80.400 129.202,81.075 130.256,81.900 131.186 C 83.563 133.059,85.497 136.346,86.039 138.216 C 86.233 138.886,87.203 140.207,88.196 141.153 C 89.188 142.098,90.000 143.104,90.000 143.388 C 90.000 144.337,92.129 148.594,92.869 149.123 C 93.271 149.410,93.600 149.831,93.600 150.059 C 93.600 150.286,93.932 150.771,94.337 151.136 C 94.743 151.501,95.598 153.004,96.237 154.475 C 96.877 155.947,97.760 157.351,98.200 157.596 C 98.640 157.841,99.900 159.943,101.000 162.267 C 102.207 164.817,103.327 166.644,103.825 166.876 C 104.278 167.087,105.065 168.101,105.573 169.130 C 107.658 173.348,108.097 174.093,110.006 176.647 C 111.103 178.114,112.000 179.725,112.000 180.227 C 112.000 181.048,113.425 183.163,114.678 184.200 C 115.295 184.711,117.396 188.733,117.720 190.022 C 117.855 190.562,118.603 191.633,119.381 192.402 C 120.160 193.171,121.496 195.258,122.351 197.039 C 123.206 198.820,124.167 200.378,124.487 200.501 C 124.807 200.624,125.953 202.496,127.034 204.662 C 128.114 206.828,129.676 209.299,130.505 210.153 C 131.333 211.007,132.124 212.177,132.262 212.753 C 132.618 214.239,134.291 217.048,136.288 219.516 C 137.230 220.679,138.000 221.923,138.000 222.280 C 138.000 223.140,139.924 226.400,140.431 226.400 C 140.650 226.400,141.167 227.190,141.581 228.156 C 141.995 229.122,142.524 230.029,142.756 230.173 C 142.988 230.316,143.381 231.187,143.629 232.107 C 143.901 233.119,144.651 234.320,145.527 235.145 C 146.323 235.896,147.551 237.776,148.256 239.323 C 148.961 240.869,149.822 242.467,150.169 242.872 C 150.516 243.277,150.800 243.747,150.800 243.916 C 150.800 244.084,151.178 244.546,151.640 244.941 C 152.102 245.337,153.117 247.042,153.896 248.730 C 154.674 250.419,155.885 252.393,156.587 253.117 C 157.288 253.842,158.453 255.832,159.175 257.541 C 159.991 259.470,161.083 261.238,162.057 262.207 C 162.921 263.065,163.741 264.225,163.880 264.784 C 164.202 266.074,165.821 269.140,166.738 270.193 C 167.716 271.317,169.600 274.181,169.600 274.543 C 169.600 275.323,171.398 278.721,172.342 279.726 L 173.400 280.852 173.501 347.096 C 173.584 401.667,173.696 413.450,174.136 413.969 C 174.430 414.316,175.270 415.545,176.002 416.700 C 176.735 417.855,177.566 418.800,177.849 418.800 C 178.505 418.800,179.956 420.251,181.626 422.576 C 182.346 423.579,183.220 424.401,183.568 424.402 C 183.916 424.404,184.716 424.674,185.346 425.002 C 186.694 425.706,205.876 425.863,210.404 425.207 C 211.837 425.000,214.626 424.647,216.602 424.422 C 218.578 424.198,221.096 423.671,222.197 423.251 C 225.651 421.936,234.760 420.742,244.200 420.367 C 254.932 419.940,255.342 419.867,256.938 418.105 C 258.873 415.970,262.469 412.173,263.741 410.922 C 268.897 405.853,268.378 414.164,268.506 334.626 C 268.624 260.876,268.527 264.457,270.487 262.095 C 270.963 261.522,272.681 256.931,273.205 254.833 C 273.645 253.071,274.761 250.935,275.900 249.677 C 276.395 249.131,276.800 248.378,276.800 248.006 C 276.800 246.948,279.199 240.273,279.832 239.569 C 280.145 239.221,280.400 238.714,280.400 238.442 C 280.400 238.169,280.826 237.374,281.347 236.673 C 281.868 235.973,282.391 234.759,282.510 233.975 C 282.628 233.191,283.088 231.751,283.530 230.775 C 283.973 229.799,284.463 228.550,284.618 228.000 C 284.773 227.450,285.400 226.253,286.010 225.339 C 286.620 224.426,287.347 222.986,287.625 222.139 C 289.193 217.363,291.339 212.217,292.021 211.600 C 292.431 211.229,293.600 208.484,293.600 207.893 C 293.600 207.570,293.978 206.338,294.441 205.153 C 295.255 203.068,295.626 202.309,297.773 198.331 C 298.328 197.303,298.950 195.773,299.155 194.931 C 299.786 192.337,301.043 189.208,301.943 187.992 C 302.414 187.354,302.800 186.740,302.800 186.628 C 302.800 186.516,303.250 185.440,303.800 184.237 C 304.350 183.035,304.800 181.764,304.800 181.414 C 304.800 180.310,306.817 175.830,307.626 175.136 C 308.052 174.771,308.400 174.224,308.400 173.920 C 308.400 173.617,308.760 172.663,309.200 171.800 C 309.640 170.937,310.000 169.819,310.000 169.316 C 310.000 168.227,312.179 163.482,312.987 162.811 C 313.490 162.394,314.327 160.096,316.017 154.494 C 316.300 153.556,316.772 152.589,317.066 152.345 C 317.360 152.102,317.600 151.654,317.600 151.351 C 317.600 151.048,317.783 150.800,318.006 150.800 C 318.520 150.800,319.275 149.024,320.385 145.200 C 321.312 142.009,321.939 140.531,323.182 138.600 C 324.471 136.600,325.199 135.111,325.219 134.439 C 325.257 133.119,327.075 128.319,327.930 127.280 C 329.603 125.247,330.395 123.800,330.397 122.771 C 330.400 121.619,331.518 118.006,332.053 117.420 C 332.244 117.211,332.400 116.797,332.400 116.501 C 332.400 116.204,332.849 115.546,333.398 115.037 C 334.472 114.042,335.431 111.724,336.008 108.730 C 336.435 106.511,337.850 103.325,338.913 102.188 C 339.725 101.319,341.600 96.369,341.600 95.093 C 341.600 94.285,342.786 91.895,343.300 91.667 C 343.465 91.593,343.600 91.183,343.600 90.754 C 343.600 90.326,343.884 89.866,344.231 89.733 C 346.502 88.861,346.588 65.600,344.320 65.600 C 343.429 65.600,340.000 62.351,340.000 61.507 C 340.000 61.160,339.041 60.335,337.869 59.674 C 336.698 59.013,335.433 58.005,335.060 57.436 L 334.382 56.400 322.691 56.457 C 316.261 56.488,309.830 56.645,308.400 56.805 M376.400 57.549 C 376.400 57.782,376.747 58.157,377.171 58.384 C 378.343 59.012,380.402 62.302,380.384 63.520 L 380.368 64.600 379.753 63.465 C 378.904 61.899,378.656 62.357,379.395 64.126 C 379.728 64.922,380.026 66.165,380.057 66.887 C 380.112 68.165,380.121 68.157,380.400 66.600 C 380.580 65.594,380.686 67.004,380.686 70.400 C 380.686 73.598,380.576 75.147,380.415 74.200 L 380.144 72.600 379.939 74.200 C 379.749 75.684,379.730 75.643,379.667 73.633 C 379.574 70.643,379.356 71.152,378.822 75.600 C 378.571 77.690,378.058 80.660,377.683 82.200 L 377.000 85.000 376.746 83.400 C 376.606 82.520,376.502 86.255,376.514 91.700 C 376.526 97.145,376.695 101.600,376.888 101.600 C 380.700 101.600,381.297 98.218,381.125 77.588 L 381.000 62.576 379.983 60.600 C 379.046 58.781,376.400 56.528,376.400 57.549 M324.808 74.604 C 327.263 75.874,327.008 81.222,324.349 84.211 C 323.581 85.075,321.200 90.546,321.200 91.449 C 321.200 92.087,319.203 96.289,318.260 97.635 C 317.897 98.154,317.600 98.952,317.600 99.409 C 317.600 99.866,317.434 100.411,317.232 100.620 C 317.029 100.829,316.497 102.080,316.049 103.400 C 315.601 104.720,314.507 107.237,313.617 108.992 C 312.728 110.748,312.000 112.415,312.000 112.697 C 312.000 112.978,311.654 113.972,311.231 114.904 C 310.808 115.837,309.889 117.933,309.189 119.562 C 308.489 121.191,307.575 123.132,307.158 123.874 C 306.741 124.617,306.399 125.534,306.399 125.912 C 306.398 126.290,306.038 127.189,305.599 127.910 C 305.159 128.630,304.800 129.514,304.800 129.875 C 304.800 130.236,303.916 132.346,302.835 134.565 C 301.755 136.784,300.478 139.680,299.998 141.000 C 299.518 142.320,298.391 144.930,297.493 146.800 C 295.933 150.048,295.066 152.122,293.981 155.200 C 293.709 155.970,292.873 157.843,292.122 159.361 C 291.371 160.880,290.124 163.850,289.352 165.961 C 287.937 169.831,287.646 170.471,285.551 174.309 C 284.918 175.469,284.400 176.755,284.400 177.167 C 284.400 178.039,282.061 183.699,281.571 184.011 C 281.116 184.301,278.953 189.495,278.605 191.133 C 278.449 191.866,277.633 193.683,276.790 195.170 C 275.015 198.302,273.200 202.606,273.200 203.682 C 273.200 204.479,271.552 207.953,270.394 209.600 C 269.551 210.798,267.600 216.315,267.600 217.502 C 267.600 217.964,267.366 218.581,267.081 218.871 C 266.123 219.847,264.000 223.139,264.000 223.648 C 264.000 224.862,261.733 230.962,260.992 231.741 C 259.946 232.841,258.632 235.681,258.066 238.062 C 257.591 240.061,256.412 242.719,254.244 246.674 C 253.499 248.035,252.804 249.835,252.700 250.674 C 252.596 251.513,252.126 253.624,251.655 255.364 L 250.800 258.528 250.790 326.564 C 250.781 394.972,250.734 397.275,249.322 398.305 C 248.925 398.595,248.240 399.144,247.800 399.525 C 246.609 400.557,243.279 401.197,236.800 401.640 C 233.610 401.858,228.750 402.468,226.000 402.995 C 219.686 404.206,216.314 404.661,202.633 406.153 C 194.013 407.093,190.060 405.271,190.884 400.737 C 191.623 396.672,191.048 272.414,190.280 270.200 C 189.208 267.110,188.079 264.878,187.096 263.904 C 186.086 262.902,185.571 262.105,184.446 259.800 C 184.017 258.920,183.031 257.300,182.257 256.200 C 181.482 255.100,180.264 253.030,179.549 251.600 C 178.834 250.170,177.665 248.276,176.951 247.391 C 176.236 246.505,174.924 244.357,174.034 242.617 C 173.144 240.877,171.862 238.764,171.185 237.922 C 170.508 237.079,169.284 235.087,168.464 233.495 C 167.644 231.903,166.406 229.824,165.713 228.876 C 165.019 227.927,163.801 225.816,163.005 224.184 C 162.209 222.552,161.343 221.078,161.079 220.908 C 160.307 220.411,159.057 218.422,157.408 215.062 C 156.560 213.336,155.627 211.832,155.334 211.719 C 155.040 211.607,154.800 211.335,154.800 211.115 C 154.800 210.895,154.350 210.181,153.800 209.527 C 153.250 208.873,152.800 208.005,152.800 207.598 C 152.800 207.190,152.551 206.608,152.246 206.303 C 151.942 205.999,151.308 204.996,150.838 204.075 C 150.368 203.154,149.807 202.400,149.592 202.400 C 149.376 202.400,149.200 202.143,149.200 201.829 C 149.200 201.514,148.928 200.986,148.597 200.654 C 148.265 200.322,147.660 199.274,147.252 198.325 C 146.844 197.376,145.822 195.700,144.981 194.600 C 144.139 193.500,142.660 191.070,141.693 189.200 C 140.727 187.330,139.518 185.350,139.007 184.800 C 138.496 184.250,137.424 182.540,136.625 181.000 C 134.927 177.729,134.425 176.908,133.574 176.009 C 133.229 175.645,132.292 174.009,131.492 172.374 C 130.691 170.738,129.491 168.807,128.825 168.083 C 128.159 167.358,126.949 165.378,126.138 163.683 C 125.326 161.987,123.883 159.638,122.931 158.463 C 121.979 157.288,121.200 156.096,121.200 155.814 C 121.200 155.061,119.237 151.677,118.465 151.098 C 117.877 150.657,116.870 148.821,115.136 145.028 C 114.841 144.383,114.060 143.277,113.400 142.570 C 112.740 141.863,111.660 140.230,111.000 138.942 C 110.340 137.654,109.023 135.472,108.074 134.092 C 107.125 132.713,105.886 130.574,105.320 129.338 C 104.755 128.103,104.001 126.774,103.646 126.386 C 101.555 124.102,100.800 123.138,100.800 122.750 C 100.800 121.775,98.336 117.300,97.017 115.881 C 96.241 115.045,95.487 113.875,95.341 113.281 C 95.196 112.686,94.969 112.110,94.836 112.000 C 94.704 111.890,94.066 111.080,93.419 110.200 C 92.772 109.320,92.056 108.474,91.829 108.319 C 91.568 108.142,91.751 107.624,92.322 106.919 C 92.821 106.304,93.332 105.491,93.458 105.113 C 93.584 104.736,94.010 104.324,94.406 104.198 C 94.802 104.072,95.216 103.736,95.325 103.450 C 95.831 102.132,101.677 100.204,109.319 98.835 C 110.594 98.607,113.114 97.717,114.919 96.858 C 116.723 95.998,119.370 95.082,120.800 94.822 C 126.541 93.779,129.129 93.065,131.866 91.770 C 133.443 91.025,135.513 90.244,136.466 90.036 C 147.927 87.531,149.748 87.332,151.504 88.400 C 152.688 89.120,154.800 91.559,154.800 92.206 C 154.800 92.388,155.044 92.821,155.342 93.169 C 155.640 93.516,156.479 95.150,157.205 96.800 C 159.339 101.648,160.545 104.186,160.815 104.400 C 161.225 104.725,163.999 110.690,164.009 111.269 C 164.014 111.561,164.370 112.250,164.800 112.800 C 165.230 113.350,165.586 114.037,165.591 114.327 C 165.596 114.616,166.050 115.443,166.600 116.164 C 167.150 116.886,167.600 117.706,167.600 117.989 C 167.600 118.496,169.140 121.915,171.119 125.800 C 173.546 130.567,175.200 134.063,175.200 134.430 C 175.200 134.647,175.906 136.071,176.769 137.594 C 177.633 139.117,178.815 141.497,179.398 142.882 C 179.981 144.267,180.739 145.940,181.083 146.600 C 184.292 152.754,185.631 155.598,185.841 156.700 C 185.978 157.415,186.221 158.000,186.382 158.000 C 186.542 158.000,187.017 158.667,187.437 159.483 C 187.857 160.298,188.605 161.583,189.100 162.338 C 189.595 163.094,190.000 163.965,190.000 164.275 C 190.000 164.585,190.360 165.584,190.800 166.494 C 191.240 167.405,191.600 168.327,191.600 168.544 C 191.600 168.760,191.854 169.221,192.164 169.569 C 193.061 170.572,195.200 174.660,195.200 175.369 C 195.200 176.118,196.944 179.652,198.176 181.400 C 199.143 182.772,200.646 186.122,200.958 187.600 C 201.074 188.150,201.986 189.842,202.985 191.359 C 203.983 192.877,204.800 194.251,204.800 194.414 C 204.800 194.576,205.069 195.224,205.398 195.854 C 205.727 196.484,206.113 197.620,206.257 198.377 C 206.873 201.624,207.803 202.448,210.708 202.317 C 212.806 202.223,213.403 202.047,213.758 201.417 C 214.001 200.986,214.413 200.400,214.674 200.115 C 215.194 199.544,215.299 199.225,216.026 196.000 C 216.715 192.940,217.808 190.527,218.779 189.921 C 219.230 189.638,219.600 189.209,219.600 188.965 C 219.600 188.722,219.886 187.949,220.236 187.247 C 220.586 186.545,221.001 185.033,221.158 183.886 C 221.431 181.894,223.031 178.570,224.175 177.621 C 224.671 177.209,226.514 171.933,226.977 169.600 C 227.086 169.050,227.834 167.610,228.639 166.400 C 230.126 164.167,231.643 160.379,232.397 157.015 C 232.643 155.916,233.461 154.340,234.406 153.145 C 235.283 152.036,236.000 150.813,236.000 150.428 C 236.000 149.072,238.382 142.593,239.099 142.000 C 239.967 141.282,241.395 138.005,241.779 135.850 C 242.048 134.341,243.035 132.111,245.779 126.818 C 246.515 125.398,247.204 123.588,247.310 122.796 C 247.513 121.285,249.390 116.977,250.014 116.591 C 250.214 116.468,250.750 115.525,251.205 114.496 C 251.951 112.810,252.300 111.597,252.966 108.374 C 253.083 107.809,253.543 106.927,253.989 106.413 C 254.435 105.898,254.800 105.254,254.800 104.982 C 254.800 104.709,255.042 104.393,255.337 104.279 C 255.633 104.166,256.453 102.212,257.159 99.937 C 258.408 95.914,260.308 91.600,260.830 91.600 C 260.972 91.600,261.495 90.311,261.992 88.736 C 263.478 84.031,265.484 80.400,266.600 80.400 C 266.847 80.400,267.849 80.013,268.825 79.540 C 270.427 78.763,271.536 78.652,280.200 78.394 C 289.735 78.110,294.288 77.648,305.800 75.798 C 311.107 74.945,317.548 74.261,322.120 74.065 C 322.956 74.029,324.165 74.272,324.808 74.604 M377.200 77.600 C 376.930 78.724,376.787 79.720,376.881 79.814 C 376.975 79.909,377.285 79.078,377.569 77.969 C 377.853 76.860,377.997 75.864,377.888 75.755 C 377.779 75.646,377.470 76.476,377.200 77.600 M379.083 81.295 C 378.987 81.793,378.905 81.480,378.901 80.600 C 378.896 79.720,378.975 79.313,379.075 79.695 C 379.175 80.078,379.179 80.798,379.083 81.295 M379.017 97.475 C 378.756 98.515,377.778 99.561,377.042 99.587 C 376.844 99.594,377.159 99.159,377.742 98.619 C 378.324 98.080,378.800 97.360,378.800 97.019 C 378.800 96.679,378.910 96.400,379.043 96.400 C 379.177 96.400,379.165 96.884,379.017 97.475 M376.000 106.733 C 376.000 106.990,375.798 107.155,375.550 107.100 C 375.303 107.045,375.018 107.225,374.917 107.500 C 374.816 107.775,374.906 108.000,375.118 108.000 C 375.663 108.000,376.565 106.832,376.257 106.524 C 376.116 106.382,376.000 106.477,376.000 106.733 M368.842 118.760 C 368.159 119.399,367.600 119.739,367.600 119.516 C 367.600 119.294,367.285 119.450,366.900 119.864 C 366.515 120.278,366.335 120.442,366.500 120.228 C 366.933 119.668,366.870 119.313,366.300 119.094 C 365.959 118.963,365.784 119.387,365.748 120.429 L 365.696 121.955 366.748 121.301 L 367.800 120.646 366.700 121.845 C 365.643 122.997,364.962 128.400,365.874 128.400 C 368.662 128.400,370.373 125.543,370.965 119.900 C 371.250 117.186,370.792 116.939,368.842 118.760 M366.800 118.765 C 366.800 119.171,367.823 119.111,368.255 118.678 C 368.408 118.525,368.143 118.400,367.667 118.400 C 367.190 118.400,366.800 118.564,366.800 118.765 M364.571 130.229 C 365.353 131.010,365.402 131.465,364.636 130.830 C 364.203 130.471,364.002 130.474,363.774 130.842 C 363.585 131.147,363.645 131.219,363.938 131.038 C 364.649 130.599,364.486 131.141,363.631 132.059 C 363.147 132.579,362.664 132.767,362.331 132.566 C 361.912 132.314,361.916 132.390,362.349 132.923 C 363.040 133.776,362.667 133.810,361.829 132.971 C 361.257 132.400,361.200 132.420,361.200 133.192 C 361.200 133.966,361.388 134.031,363.300 133.921 L 365.400 133.800 365.521 131.700 C 365.631 129.788,365.566 129.600,364.792 129.600 C 364.020 129.600,364.000 129.657,364.571 130.229 M358.676 143.967 C 358.414 144.315,357.975 144.618,357.700 144.640 C 357.425 144.662,356.750 144.707,356.200 144.740 C 355.262 144.796,355.200 144.937,355.200 146.990 L 355.200 149.180 356.500 148.940 C 358.166 148.633,360.341 145.633,360.394 143.567 C 360.407 143.068,359.127 143.366,358.676 143.967 M354.019 155.180 C 353.700 155.382,353.307 155.466,353.147 155.367 C 352.986 155.268,352.754 155.351,352.630 155.552 C 352.506 155.752,352.674 156.019,353.002 156.146 C 353.331 156.272,353.600 156.171,353.600 155.921 C 353.600 155.671,353.703 155.569,353.828 155.695 C 354.186 156.053,352.506 159.074,351.796 159.346 C 351.427 159.488,351.261 159.424,351.403 159.195 C 351.537 158.978,351.304 158.800,350.884 158.800 C 350.212 158.800,350.111 159.143,350.037 161.676 C 349.991 163.258,349.863 164.698,349.753 164.876 C 349.116 165.907,352.306 164.618,353.452 163.382 C 354.411 162.347,355.049 160.026,354.657 159.003 C 354.529 158.671,354.599 158.400,354.813 158.400 C 355.026 158.400,355.200 157.590,355.200 156.600 C 355.200 154.752,355.026 154.543,354.019 155.180 M351.742 157.415 C 351.099 158.112,351.016 158.397,351.412 158.549 C 352.006 158.777,352.938 157.872,352.530 157.463 C 352.385 157.318,352.477 157.200,352.733 157.200 C 352.990 157.200,353.200 157.020,353.200 156.800 C 353.200 156.178,352.680 156.398,351.742 157.415 M349.200 166.400 C 349.200 166.840,349.380 167.200,349.600 167.200 C 349.820 167.200,350.000 166.840,350.000 166.400 C 350.000 165.960,349.820 165.600,349.600 165.600 C 349.380 165.600,349.200 165.960,349.200 166.400 M349.200 168.125 C 349.200 169.147,347.018 170.853,346.420 170.299 C 345.985 169.895,345.945 169.909,346.207 170.368 C 346.447 170.789,346.360 170.870,345.870 170.682 C 345.108 170.390,344.891 171.065,344.714 174.281 C 344.642 175.595,344.740 176.221,344.980 175.981 C 345.189 175.771,345.648 175.600,346.000 175.600 C 347.291 175.600,348.825 174.587,349.030 173.600 C 349.143 173.050,349.408 171.949,349.618 171.154 C 350.114 169.275,350.106 167.600,349.600 167.600 C 349.380 167.600,349.200 167.836,349.200 168.125 M344.308 177.983 C 344.031 178.967,344.197 179.537,344.632 179.101 C 344.760 178.973,344.801 178.448,344.724 177.934 L 344.584 177.000 344.308 177.983 M343.475 180.550 C 343.359 180.852,342.703 181.295,342.018 181.534 C 341.294 181.786,340.872 181.807,341.010 181.584 C 341.140 181.373,341.102 181.203,340.924 181.206 C 339.513 181.233,338.922 186.400,340.330 186.400 C 342.959 186.400,344.081 185.167,344.611 181.700 C 344.870 180.004,344.016 179.140,343.475 180.550 M339.079 190.957 C 338.915 191.374,338.875 191.809,338.991 191.924 C 339.355 192.289,339.676 191.691,339.524 190.931 C 339.383 190.235,339.362 190.236,339.079 190.957 M337.847 193.021 C 337.699 193.408,337.773 193.540,338.044 193.373 C 338.344 193.187,338.338 193.368,338.026 193.952 C 337.776 194.418,337.478 194.800,337.362 194.800 C 337.247 194.800,337.256 194.632,337.383 194.428 C 337.509 194.223,337.468 193.966,337.291 193.856 C 337.114 193.747,336.933 194.105,336.888 194.651 C 336.830 195.349,336.953 195.555,337.303 195.345 C 337.636 195.145,337.619 195.270,337.251 195.723 C 336.663 196.448,336.371 196.585,336.447 196.100 C 336.574 195.297,336.339 195.151,335.723 195.651 C 335.275 196.015,335.147 196.033,335.344 195.705 C 335.539 195.380,335.448 195.283,335.081 195.424 C 334.684 195.577,334.496 196.474,334.437 198.496 C 334.391 200.067,334.246 201.526,334.114 201.738 C 333.692 202.422,336.913 201.667,337.635 200.913 C 339.315 199.159,340.274 192.400,338.843 192.400 C 338.426 192.400,337.978 192.679,337.847 193.021 M333.867 202.667 C 333.720 202.813,333.600 203.263,333.600 203.667 C 333.600 204.070,333.414 204.400,333.186 204.400 C 332.920 204.400,332.943 204.722,333.251 205.300 C 333.692 206.126,333.674 206.153,333.043 205.632 C 332.449 205.142,332.372 205.142,332.477 205.632 C 332.546 205.951,332.351 206.146,332.032 206.077 C 331.542 205.972,331.542 206.049,332.032 206.643 C 332.553 207.274,332.526 207.292,331.700 206.851 C 330.904 206.427,330.800 206.466,330.800 207.186 C 330.800 207.819,331.060 208.000,331.971 208.000 C 333.747 208.000,334.400 207.078,334.400 204.571 C 334.400 202.375,334.347 202.186,333.867 202.667 M329.000 207.600 C 328.864 207.820,329.123 208.000,329.576 208.000 C 330.029 208.000,330.400 207.820,330.400 207.600 C 330.400 207.380,330.141 207.200,329.824 207.200 C 329.507 207.200,329.136 207.380,329.000 207.600 M327.674 218.030 C 327.280 218.661,327.028 218.755,326.624 218.420 C 326.226 218.090,326.035 218.132,325.859 218.590 C 325.730 218.925,325.394 219.197,325.113 219.194 C 324.754 219.190,324.780 219.071,325.200 218.800 C 325.620 218.529,325.646 218.410,325.287 218.406 C 325.006 218.403,324.672 218.669,324.546 218.998 C 324.419 219.326,324.185 219.514,324.025 219.415 C 323.864 219.316,323.733 219.489,323.733 219.800 C 323.733 220.111,323.928 220.248,324.167 220.106 C 324.476 219.920,324.478 220.011,324.171 220.423 C 323.935 220.740,323.705 221.610,323.660 222.356 L 323.579 223.712 325.406 223.461 C 328.523 223.034,328.800 222.734,328.800 219.786 C 328.800 217.070,328.533 216.654,327.674 218.030 M322.571 229.829 C 323.377 230.634,323.391 231.057,322.591 230.392 C 322.086 229.973,322.022 229.992,322.218 230.503 C 322.515 231.275,320.840 232.901,320.057 232.601 C 319.589 232.421,319.577 232.491,319.992 232.991 C 320.657 233.791,320.234 233.777,319.429 232.971 C 318.857 232.400,318.800 232.418,318.800 233.171 C 318.800 234.761,323.026 234.369,323.350 232.750 C 323.844 230.278,323.669 229.200,322.771 229.200 C 322.018 229.200,322.000 229.257,322.571 229.829 M317.902 240.600 C 317.797 241.150,317.866 241.600,318.055 241.600 C 318.245 241.600,318.400 241.150,318.400 240.600 C 318.400 240.050,318.331 239.600,318.247 239.600 C 318.162 239.600,318.007 240.050,317.902 240.600 M317.751 243.016 C 317.891 243.380,317.785 243.600,317.494 243.553 C 316.516 243.396,315.600 244.104,315.600 245.016 C 315.600 245.592,315.144 246.270,314.400 246.800 C 312.963 247.824,312.828 248.800,314.125 248.800 C 315.272 248.800,316.919 247.102,317.763 245.051 C 318.511 243.233,318.572 242.400,317.957 242.400 C 317.714 242.400,317.621 242.677,317.751 243.016 M313.900 244.676 C 313.197 244.859,312.866 246.800,313.538 246.800 C 314.018 246.800,315.200 245.427,315.200 244.869 C 315.200 244.384,315.082 244.367,313.900 244.676 M312.110 254.400 C 312.182 255.358,312.620 255.445,312.957 254.567 C 313.299 253.677,313.272 253.600,312.625 253.600 C 312.296 253.600,312.076 253.943,312.110 254.400 M308.700 255.105 C 308.161 255.223,308.000 255.669,308.000 257.040 L 308.000 258.821 309.141 258.231 C 310.253 257.656,311.600 256.018,311.600 255.241 C 311.600 254.864,310.116 254.795,308.700 255.105 M306.490 265.670 C 306.129 266.031,306.134 266.282,306.510 266.745 C 306.917 267.247,306.885 267.307,306.320 267.095 C 305.852 266.920,305.705 267.008,305.848 267.380 C 305.961 267.676,305.859 268.040,305.621 268.187 C 305.382 268.335,305.308 268.651,305.455 268.889 C 305.607 269.135,305.539 269.210,305.298 269.061 C 304.600 268.629,303.413 269.228,304.066 269.682 C 304.431 269.935,304.315 269.972,303.700 269.799 C 303.075 269.623,302.800 269.717,302.800 270.106 C 302.800 270.679,304.556 270.918,306.260 270.577 C 307.236 270.382,308.000 268.610,308.000 266.540 C 308.000 265.151,307.371 264.789,306.490 265.670 M302.360 279.200 C 302.129 281.000,302.202 281.531,302.625 281.108 C 302.749 280.985,302.792 280.100,302.721 279.142 L 302.592 277.400 302.360 279.200 M301.922 301.700 C 301.988 308.795,302.184 323.870,302.357 335.200 L 302.671 355.800 302.735 322.300 C 302.787 295.732,302.697 288.800,302.300 288.800 C 301.908 288.799,301.826 291.581,301.922 301.700 M301.293 325.200 C 301.293 325.970,301.375 326.285,301.476 325.900 C 301.576 325.515,301.576 324.885,301.476 324.500 C 301.375 324.115,301.293 324.430,301.293 325.200 M301.778 343.200 C 301.778 350.130,301.833 352.965,301.899 349.500 C 301.966 346.035,301.966 340.365,301.899 336.900 C 301.833 333.435,301.778 336.270,301.778 343.200 M301.367 368.400 C 301.367 372.690,301.426 374.445,301.498 372.300 C 301.570 370.155,301.570 366.645,301.498 364.500 C 301.426 362.355,301.367 364.110,301.367 368.400 M302.167 368.400 C 302.167 372.690,302.226 374.445,302.298 372.300 C 302.370 370.155,302.370 366.645,302.298 364.500 C 302.226 362.355,302.167 364.110,302.167 368.400 M301.765 388.600 C 301.766 392.560,301.826 394.126,301.898 392.080 C 301.971 390.034,301.971 386.794,301.898 384.880 C 301.824 382.966,301.765 384.640,301.765 388.600 M302.360 391.800 C 302.228 397.520,302.183 402.275,302.260 402.367 C 302.725 402.920,302.803 401.063,302.707 391.760 L 302.600 381.400 302.360 391.800 M302.166 417.100 C 302.303 418.309,302.266 418.637,302.066 418.000 C 301.758 417.020,301.746 417.027,301.481 418.327 C 301.331 419.059,301.030 419.542,300.809 419.406 C 300.569 419.257,300.514 419.433,300.673 419.845 C 300.865 420.347,300.794 420.444,300.406 420.204 C 300.041 419.978,299.971 420.030,300.182 420.370 C 300.367 420.671,300.154 421.097,299.637 421.459 C 299.169 421.787,298.906 422.249,299.053 422.486 C 299.230 422.772,298.985 422.833,298.326 422.667 C 297.618 422.490,297.333 422.581,297.333 422.986 C 297.333 424.188,301.802 422.782,302.160 421.467 C 302.730 419.370,302.912 415.200,302.433 415.200 C 302.094 415.200,302.015 415.766,302.166 417.100 M301.392 421.066 C 300.997 421.800,300.510 422.400,300.310 422.400 C 300.109 422.400,300.318 421.877,300.773 421.238 C 301.228 420.599,301.614 419.744,301.632 419.338 C 301.654 418.814,301.728 418.764,301.887 419.166 C 302.010 419.477,301.787 420.332,301.392 421.066 M296.700 428.863 C 296.825 429.337,296.763 429.625,296.563 429.502 C 296.363 429.379,296.181 429.795,296.158 430.427 C 296.135 431.064,296.286 431.470,296.498 431.339 C 296.708 431.210,296.681 431.475,296.438 431.929 C 296.195 432.384,295.772 432.890,295.498 433.055 C 295.172 433.250,295.193 433.116,295.557 432.667 C 296.403 431.625,295.788 431.412,294.796 432.404 C 294.274 432.926,293.621 433.194,293.162 433.074 C 292.743 432.964,292.488 433.019,292.597 433.195 C 292.706 433.372,292.526 433.619,292.198 433.746 C 291.869 433.872,291.614 434.206,291.632 434.487 C 291.656 434.889,291.707 434.892,291.865 434.500 C 291.976 434.225,292.592 434.000,293.233 434.000 C 293.875 434.000,294.400 433.808,294.400 433.573 C 294.400 433.325,294.743 433.255,295.219 433.406 C 296.590 433.841,297.118 432.990,297.093 430.386 C 297.081 429.074,296.937 428.000,296.773 428.000 C 296.609 428.000,296.576 428.388,296.700 428.863 M291.344 436.690 C 291.375 437.070,291.130 437.385,290.800 437.390 C 290.470 437.396,290.196 437.670,290.190 438.000 C 290.185 438.330,289.870 438.575,289.490 438.544 C 289.111 438.514,288.800 438.631,288.800 438.804 C 288.800 438.978,289.430 439.120,290.200 439.120 C 290.970 439.120,291.600 438.947,291.600 438.736 C 291.600 438.525,291.375 438.467,291.100 438.606 C 290.825 438.745,290.915 438.601,291.300 438.286 C 292.021 437.694,292.277 436.000,291.644 436.000 C 291.449 436.000,291.314 436.311,291.344 436.690 M285.855 441.400 C 285.729 441.730,285.799 442.000,286.013 442.000 C 286.226 442.000,286.400 442.199,286.400 442.443 C 286.400 442.686,286.130 442.782,285.800 442.655 C 285.470 442.529,285.200 442.599,285.200 442.813 C 285.200 443.026,284.975 443.155,284.700 443.100 C 284.425 443.045,284.253 443.248,284.317 443.551 C 284.397 443.927,284.175 444.034,283.617 443.889 C 283.168 443.771,282.800 443.827,282.800 444.012 C 282.800 444.198,283.533 444.340,284.428 444.327 C 286.123 444.304,286.800 443.518,286.800 441.574 C 286.800 440.658,286.184 440.544,285.855 441.400 M276.550 444.987 C 276.125 446.094,276.600 446.326,277.319 445.363 C 277.946 444.523,277.957 444.400,277.406 444.400 C 277.059 444.400,276.674 444.664,276.550 444.987 M278.813 445.366 C 278.611 445.897,278.076 446.449,277.623 446.593 C 277.170 446.736,276.800 447.032,276.800 447.251 C 276.800 447.469,276.608 447.529,276.373 447.383 C 276.139 447.238,275.980 447.363,276.021 447.660 C 276.158 448.661,276.002 449.200,275.576 449.200 C 275.343 449.200,275.272 449.007,275.418 448.770 C 275.564 448.534,275.305 448.578,274.842 448.867 C 274.379 449.156,274.000 449.529,274.000 449.696 C 274.000 450.260,275.086 450.005,276.109 449.200 C 276.669 448.760,277.391 448.400,277.716 448.400 C 278.422 448.400,280.400 445.914,280.400 445.027 C 280.400 444.042,279.220 444.294,278.813 445.366 M257.000 451.008 C 258.320 451.531,259.130 451.984,258.800 452.015 C 258.470 452.047,258.805 452.246,259.544 452.459 C 261.569 453.042,260.890 453.185,258.424 452.696 C 256.890 452.391,256.470 452.186,257.000 452.000 C 257.585 451.795,257.396 451.645,256.151 451.330 C 254.663 450.952,254.551 450.982,254.575 451.753 C 254.602 452.656,250.090 454.563,248.956 454.128 C 248.620 453.999,248.400 454.175,248.400 454.573 C 248.400 455.396,266.016 455.239,268.312 454.395 C 269.666 453.898,270.800 452.268,270.800 450.820 C 270.800 449.524,267.666 449.652,266.400 451.000 C 265.883 451.550,265.212 452.000,264.908 452.000 C 264.595 452.000,264.841 451.582,265.475 451.037 L 266.595 450.073 264.998 450.164 C 264.119 450.213,262.791 450.574,262.046 450.965 C 260.733 451.655,260.612 451.651,258.137 450.838 C 254.718 449.716,254.008 449.822,257.000 451.008 M264.224 451.013 C 263.796 451.336,263.256 451.603,263.024 451.606 C 262.791 451.609,262.842 451.766,263.138 451.953 C 263.533 452.204,263.388 452.367,262.591 452.567 C 261.994 452.716,261.407 452.740,261.286 452.619 C 261.165 452.499,261.397 452.400,261.800 452.400 C 262.203 452.400,262.414 452.280,262.267 452.134 C 262.121 451.988,262.496 451.551,263.101 451.163 C 264.434 450.309,265.310 450.191,264.224 451.013 M244.600 454.800 C 243.406 455.104,243.407 455.106,244.900 455.153 C 245.725 455.179,246.400 455.020,246.400 454.800 C 246.400 454.359,246.332 454.359,244.600 454.800 M177.117 456.300 C 177.846 460.186,177.950 460.200,205.800 460.200 C 231.503 460.200,232.712 460.104,233.812 457.977 C 234.778 456.110,234.554 455.381,233.413 456.678 C 232.424 457.802,232.052 457.398,232.796 456.007 C 233.169 455.310,232.965 455.267,229.327 455.267 C 227.200 455.267,225.685 455.405,225.959 455.574 C 227.765 456.691,223.663 457.200,212.140 457.291 L 200.600 457.382 212.400 457.600 L 224.200 457.818 212.800 457.911 C 206.530 457.962,199.330 458.138,196.800 458.302 L 192.200 458.600 196.600 458.821 C 200.754 459.030,200.576 459.052,193.400 459.221 C 179.763 459.542,179.364 459.479,178.135 456.815 C 177.280 454.960,176.822 454.728,177.117 456.300 M213.200 456.000 C 202.160 456.212,202.015 456.225,208.600 456.409 C 218.664 456.691,224.396 456.564,224.912 456.048 C 225.158 455.802,225.189 455.641,224.980 455.691 C 224.771 455.740,219.470 455.880,213.200 456.000 M228.400 455.767 C 228.400 456.087,225.703 457.600,225.153 457.589 C 224.849 457.583,225.410 457.146,226.400 456.619 C 228.468 455.518,228.400 455.547,228.400 455.767 M178.800 456.698 C 178.800 457.396,181.430 458.828,183.084 459.030 C 184.464 459.198,184.428 459.166,182.688 458.666 C 181.637 458.365,180.332 457.700,179.788 457.189 C 179.245 456.678,178.800 456.457,178.800 456.698 M191.100 459.891 C 190.275 459.978,188.925 459.978,188.100 459.891 C 187.275 459.805,187.950 459.734,189.600 459.734 C 191.250 459.734,191.925 459.805,191.100 459.891 " stroke="none" fill="#110909" fill-rule="evenodd"></path><path id="path1" d="M315.800 79.457 C 314.576 79.816,310.540 80.184,305.400 80.406 C 294.808 80.863,274.714 81.597,272.600 81.605 C 271.226 81.609,270.877 81.800,270.131 82.953 C 269.588 83.791,268.574 84.578,267.432 85.048 C 265.850 85.698,265.571 85.990,265.377 87.200 C 264.147 94.856,263.163 97.200,261.180 97.200 C 260.610 97.200,260.394 97.618,260.197 99.100 C 259.271 106.084,257.676 110.000,255.758 110.000 C 255.265 110.000,254.400 113.191,254.400 115.011 C 254.400 117.522,252.793 120.986,251.204 121.901 C 249.757 122.733,249.643 122.937,249.416 125.095 C 248.784 131.103,247.568 134.000,245.680 134.000 C 244.928 134.000,243.599 138.868,243.600 141.620 C 243.600 143.320,241.779 146.339,240.569 146.643 C 239.680 146.867,239.287 148.077,238.374 153.400 C 237.737 157.113,236.518 159.144,234.900 159.187 C 234.625 159.194,234.400 159.245,234.399 159.300 C 234.396 159.969,233.097 166.512,232.755 167.580 C 232.159 169.446,230.887 170.800,229.730 170.800 C 228.888 170.800,228.799 170.980,228.793 172.700 C 228.777 177.171,226.187 183.969,224.490 183.993 C 223.766 184.003,223.199 185.736,223.203 187.926 C 223.207 190.544,221.407 194.782,219.762 196.024 C 218.593 196.908,218.428 197.303,218.016 200.200 C 217.245 205.624,216.158 206.823,211.293 207.620 C 206.293 208.439,205.420 207.663,204.006 201.144 C 203.177 197.324,202.919 196.673,202.113 196.367 C 200.301 195.678,199.658 194.650,199.002 191.391 C 197.985 186.336,197.720 185.724,196.440 185.468 C 195.040 185.188,194.107 183.377,193.566 179.889 C 193.015 176.333,192.476 175.195,191.225 174.945 C 190.582 174.816,189.982 174.314,189.697 173.667 C 188.696 171.389,188.000 169.051,188.000 167.969 C 188.000 166.257,187.247 164.951,185.817 164.181 C 184.469 163.455,182.400 158.433,182.400 155.886 C 182.400 155.128,182.082 154.656,181.299 154.251 C 179.494 153.318,178.966 152.398,177.826 148.200 C 176.393 142.922,176.501 143.200,175.882 143.200 C 174.976 143.200,173.520 141.334,173.169 139.721 C 172.013 134.411,171.263 132.601,170.057 132.218 C 169.131 131.924,168.197 129.888,167.205 126.000 C 166.624 123.721,166.157 122.760,165.264 122.000 C 163.940 120.874,162.000 117.136,162.000 115.712 C 162.000 114.272,160.955 112.095,159.777 111.081 C 159.192 110.579,158.479 109.545,158.191 108.784 C 157.135 105.990,156.407 103.775,156.223 102.800 C 156.119 102.250,155.350 101.066,154.513 100.169 C 153.159 98.718,151.174 94.159,151.194 92.549 C 151.208 91.501,150.082 91.329,145.054 91.611 L 139.909 91.900 138.620 93.350 C 136.958 95.218,134.975 95.810,127.503 96.672 C 122.690 97.227,121.566 97.477,121.390 98.030 C 120.937 99.459,118.330 100.676,114.701 101.154 C 104.304 102.524,104.660 102.445,103.600 103.631 C 102.395 104.982,99.766 106.400,98.470 106.400 C 97.029 106.400,95.925 107.958,96.642 108.981 C 96.949 109.419,97.200 110.098,97.200 110.489 C 97.200 110.880,97.342 111.200,97.517 111.200 C 98.788 111.200,101.585 115.200,102.167 117.851 C 102.333 118.607,103.041 119.581,103.960 120.320 C 104.795 120.991,105.706 122.138,105.986 122.870 C 106.265 123.601,106.744 124.771,107.051 125.468 C 107.357 126.166,107.717 127.285,107.851 127.956 C 107.990 128.650,108.418 129.279,108.842 129.413 C 110.104 129.814,112.000 131.996,112.000 133.047 C 112.000 134.227,113.366 137.028,114.162 137.479 C 115.055 137.985,117.600 141.897,117.600 142.764 C 117.600 144.220,118.346 145.523,119.604 146.263 C 120.292 146.668,121.129 147.630,121.463 148.400 C 121.798 149.170,122.305 150.250,122.590 150.800 C 122.875 151.350,123.232 152.380,123.383 153.089 C 123.624 154.216,125.570 156.400,126.333 156.400 C 126.669 156.400,127.366 157.960,128.226 160.638 C 128.670 162.018,129.233 162.883,129.971 163.319 C 131.053 163.958,133.623 168.611,134.158 170.900 C 134.299 171.505,134.669 172.000,134.978 172.000 C 135.727 172.000,138.000 174.789,138.000 175.707 C 138.000 176.929,139.615 179.693,141.600 181.871 C 142.959 183.362,143.562 184.401,143.750 185.577 C 143.937 186.744,144.467 187.667,145.606 188.806 C 146.483 189.683,147.200 190.555,147.200 190.744 C 147.200 190.933,147.614 191.698,148.120 192.444 C 148.626 193.190,149.274 194.636,149.560 195.659 C 149.956 197.072,150.389 197.683,151.365 198.209 C 152.660 198.906,152.882 199.268,154.377 203.112 C 154.828 204.274,155.807 205.834,156.551 206.578 C 157.946 207.972,159.783 211.368,160.184 213.293 C 160.319 213.942,160.864 214.619,161.526 214.962 C 162.139 215.279,162.976 216.227,163.385 217.069 C 163.794 217.911,164.460 219.255,164.864 220.054 C 165.269 220.854,165.600 221.743,165.600 222.028 C 165.600 222.313,166.500 223.415,167.600 224.475 C 168.710 225.545,169.600 226.764,169.600 227.215 C 169.600 228.408,171.401 231.721,172.366 232.303 C 172.825 232.580,173.200 232.997,173.200 233.230 C 173.200 233.463,173.630 234.226,174.156 234.927 C 174.682 235.627,175.228 236.747,175.370 237.416 C 175.721 239.080,177.063 241.200,177.765 241.200 C 178.082 241.200,178.823 242.235,179.411 243.500 C 182.028 249.122,182.596 250.126,183.256 250.299 C 183.966 250.484,186.000 253.919,186.000 254.931 C 186.000 255.726,187.197 258.000,187.616 258.000 C 188.263 258.000,191.195 262.825,191.653 264.644 C 191.900 265.624,192.394 266.647,192.751 266.917 C 195.392 268.915,196.072 272.892,195.716 284.262 C 195.492 291.417,195.532 292.065,196.315 294.062 C 196.777 295.238,197.214 296.560,197.286 297.000 C 197.402 297.700,197.668 297.781,199.409 297.651 C 200.504 297.569,205.360 297.438,210.200 297.361 C 247.758 296.760,245.017 296.970,245.400 294.671 C 245.554 293.752,245.812 284.540,245.975 274.200 C 246.303 253.367,246.325 253.191,248.991 250.400 C 250.117 249.221,250.399 248.530,250.779 246.028 C 251.209 243.193,252.267 240.622,253.628 239.104 C 254.794 237.804,255.949 235.014,256.237 232.800 C 256.395 231.590,256.946 229.929,257.462 229.108 C 257.978 228.287,258.400 227.382,258.400 227.097 C 258.400 226.812,258.895 226.036,259.500 225.373 C 260.256 224.545,260.839 223.174,261.364 220.984 C 262.126 217.808,263.605 214.460,264.864 213.063 C 265.477 212.384,267.600 206.292,267.600 205.215 C 267.600 204.957,268.050 204.157,268.600 203.436 C 269.150 202.714,269.600 201.883,269.600 201.588 C 269.600 201.293,269.929 200.680,270.332 200.226 C 270.735 199.772,271.288 198.590,271.562 197.600 C 272.089 195.695,273.656 191.481,274.652 189.288 C 274.980 188.567,275.598 187.758,276.024 187.492 C 276.489 187.202,276.800 186.563,276.800 185.899 C 276.800 185.290,277.153 184.028,277.585 183.096 C 278.017 182.163,278.541 180.624,278.748 179.676 C 279.138 177.897,280.933 174.800,281.574 174.800 C 281.773 174.800,282.058 174.215,282.207 173.500 C 282.962 169.877,285.022 164.610,286.266 163.121 C 287.002 162.239,287.697 161.041,287.809 160.459 C 288.584 156.433,290.138 152.384,291.288 151.395 C 291.821 150.936,292.542 149.540,292.942 148.191 C 294.988 141.289,295.428 140.114,296.334 139.141 C 297.599 137.783,299.163 134.163,299.184 132.548 C 299.205 130.883,301.058 126.899,301.942 126.619 C 302.688 126.382,303.631 124.017,304.419 120.400 C 305.153 117.036,305.597 116.074,306.934 114.949 C 308.162 113.915,309.198 111.041,309.981 106.492 C 310.254 104.910,311.142 103.557,312.916 102.020 C 313.321 101.669,313.884 100.189,314.214 98.608 C 315.257 93.612,315.926 91.844,317.323 90.400 C 319.055 88.610,319.600 87.558,319.600 86.007 C 319.600 85.322,319.955 84.026,320.390 83.126 C 321.209 81.431,321.179 81.242,319.853 79.717 C 318.944 78.671,318.567 78.647,315.800 79.457 M226.082 397.496 C 227.558 397.573,230.078 397.573,231.682 397.497 C 233.287 397.421,232.080 397.358,229.000 397.358 C 225.920 397.357,224.607 397.419,226.082 397.496 " stroke="none" fill="#f33434" fill-rule="evenodd"></path><path id="path2" d="M261.429 29.829 C 261.027 30.230,260.800 31.170,260.800 32.429 L 260.800 34.400 253.000 34.400 L 245.200 34.400 245.200 37.000 L 245.200 39.600 242.600 39.600 L 240.000 39.600 240.000 42.400 L 240.000 45.200 237.200 45.200 L 234.400 45.200 234.400 47.781 L 234.400 50.362 231.900 50.481 L 229.400 50.600 229.281 53.081 L 229.163 55.563 226.681 55.681 L 224.200 55.800 224.088 60.881 L 223.976 65.962 221.488 66.081 L 219.000 66.200 218.883 72.200 L 218.766 78.200 217.483 78.800 C 216.742 79.146,215.958 79.949,215.628 80.700 C 215.018 82.086,215.328 82.000,210.400 82.147 C 209.410 82.176,208.468 82.380,208.306 82.600 C 208.144 82.820,208.012 82.190,208.012 81.200 C 208.012 79.217,208.254 78.669,209.300 78.283 C 209.685 78.141,210.000 77.749,210.000 77.413 C 210.000 77.076,210.163 76.800,210.362 76.800 C 210.562 76.800,210.517 76.351,210.262 75.803 C 210.008 75.255,209.678 74.805,209.529 74.803 C 209.379 74.801,208.974 74.517,208.629 74.171 C 208.083 73.625,208.000 73.622,208.000 74.143 C 208.000 74.473,207.717 75.026,207.371 75.371 C 206.800 75.943,206.809 76.002,207.471 76.025 C 208.818 76.072,206.315 76.901,204.539 76.996 L 202.878 77.085 202.580 73.043 C 202.162 67.368,202.158 66.850,202.530 67.080 C 202.711 67.192,202.622 66.905,202.333 66.442 C 202.044 65.979,201.536 65.587,201.204 65.572 C 200.765 65.551,200.799 65.465,201.330 65.256 C 201.731 65.098,202.031 64.816,201.995 64.629 C 201.960 64.442,202.151 64.154,202.419 63.988 C 202.755 63.781,202.641 63.604,202.053 63.417 C 201.428 63.218,201.200 62.820,201.200 61.924 C 201.200 60.822,201.268 60.756,201.889 61.251 C 202.327 61.599,202.254 61.378,201.689 60.646 C 201.200 60.011,200.800 59.280,200.800 59.021 C 200.800 58.519,199.060 57.117,197.900 56.686 C 197.515 56.542,197.200 56.239,197.200 56.013 C 197.200 55.786,196.858 55.600,196.439 55.600 C 195.954 55.600,195.527 55.167,195.261 54.404 C 194.997 53.645,194.325 52.961,193.422 52.530 C 192.640 52.157,192.000 51.627,192.000 51.353 C 192.000 50.874,190.852 50.306,190.141 50.434 C 187.737 50.864,186.000 50.354,186.000 49.216 C 186.000 45.761,183.461 45.200,167.823 45.200 L 155.200 45.200 155.200 43.033 C 155.200 39.302,156.306 39.600,142.437 39.600 C 128.529 39.600,129.200 39.434,129.200 42.880 L 129.200 45.200 113.643 45.200 C 96.155 45.200,97.600 44.910,97.600 48.421 L 97.600 50.376 92.500 50.488 L 87.400 50.600 87.281 53.100 L 87.162 55.600 81.981 55.600 L 76.800 55.600 76.800 58.182 L 76.800 60.763 74.100 60.882 L 71.400 61.000 71.281 63.500 L 71.162 66.000 66.604 66.000 C 61.356 66.000,60.800 66.334,60.800 69.489 L 60.800 71.200 58.823 71.200 C 55.933 71.200,55.600 71.850,55.600 77.489 L 55.600 82.000 53.629 82.000 C 50.272 82.000,50.400 81.434,50.400 96.261 L 50.400 109.264 48.882 109.861 C 45.893 111.035,45.126 115.878,45.246 132.844 C 45.311 141.929,45.396 143.185,45.960 143.336 C 46.497 143.480,46.487 143.515,45.900 143.554 C 45.374 143.588,45.200 143.952,45.200 145.020 C 45.200 146.872,46.257 148.941,47.048 148.637 C 47.374 148.512,47.537 148.578,47.410 148.784 C 47.124 149.246,49.772 149.788,50.405 149.397 C 50.736 149.192,50.786 149.620,50.585 150.957 C 50.342 152.581,50.398 152.804,51.055 152.832 C 51.476 152.849,51.583 152.951,51.300 153.065 C 51.025 153.176,50.800 153.442,50.800 153.657 C 50.800 153.872,51.025 153.912,51.300 153.747 C 51.690 153.513,51.696 153.575,51.328 154.030 C 50.951 154.497,51.052 154.801,51.828 155.549 C 52.363 156.063,52.800 156.736,52.800 157.043 C 52.800 157.351,53.489 157.901,54.332 158.266 C 55.597 158.814,55.833 159.093,55.685 159.865 C 55.564 160.499,55.694 160.800,56.089 160.800 C 56.756 160.800,57.748 162.569,57.827 163.900 C 57.891 164.979,57.853 164.991,57.149 164.123 C 56.776 163.663,56.760 163.543,57.100 163.747 C 57.375 163.912,57.600 163.857,57.600 163.624 C 57.600 163.391,57.409 163.200,57.176 163.200 C 56.943 163.200,56.864 163.020,57.000 162.800 C 57.136 162.580,57.046 162.400,56.800 162.400 C 56.554 162.400,56.464 162.220,56.600 162.000 C 56.736 161.780,56.657 161.600,56.424 161.600 C 55.959 161.600,55.884 162.526,56.239 163.851 C 56.648 165.372,59.969 166.291,60.032 164.900 C 60.056 164.349,60.109 164.327,60.278 164.800 C 60.396 165.130,60.786 165.646,61.146 165.946 C 61.627 166.347,61.668 166.541,61.300 166.679 C 60.505 166.977,60.677 168.799,61.500 168.806 C 62.094 168.811,62.110 168.869,61.603 169.189 C 61.131 169.488,61.109 169.669,61.499 170.059 C 62.179 170.739,63.318 170.853,63.684 170.278 C 63.918 169.910,63.989 169.913,63.994 170.287 C 63.997 170.556,64.241 170.682,64.536 170.569 C 65.422 170.229,66.051 171.427,66.103 173.550 C 66.130 174.652,66.298 175.463,66.476 175.353 C 66.654 175.243,66.803 175.478,66.806 175.876 C 66.811 176.490,66.871 176.509,67.200 176.000 C 67.413 175.670,67.591 175.595,67.594 175.833 C 67.604 176.569,67.100 176.815,66.537 176.348 C 66.116 175.999,66.000 176.086,66.000 176.751 C 66.000 177.333,66.251 177.600,66.800 177.600 C 67.240 177.600,67.600 177.865,67.600 178.188 C 67.600 178.511,68.140 179.175,68.800 179.663 C 69.460 180.151,70.000 180.787,70.000 181.075 C 70.000 181.364,70.248 181.600,70.551 181.600 C 71.390 181.600,72.167 182.669,71.517 182.930 C 71.115 183.091,71.122 183.144,71.549 183.168 C 72.003 183.195,72.008 183.309,71.575 183.830 C 71.146 184.347,71.145 184.519,71.571 184.782 C 71.967 185.027,71.975 185.142,71.603 185.266 C 70.105 185.765,73.138 191.382,74.740 191.075 C 75.512 190.928,76.005 191.147,76.686 191.939 C 77.625 193.030,77.909 193.838,77.200 193.400 C 76.980 193.264,76.800 193.343,76.800 193.576 C 76.800 193.809,76.966 194.000,77.169 194.000 C 77.650 194.000,80.000 196.350,80.000 196.831 C 80.000 197.034,80.501 197.200,81.114 197.200 C 82.225 197.200,82.228 197.208,82.088 199.600 C 81.976 201.533,82.066 202.000,82.551 202.000 C 82.882 202.000,83.263 202.178,83.397 202.395 C 83.537 202.622,83.377 202.689,83.021 202.553 C 82.539 202.368,82.400 202.602,82.400 203.597 C 82.400 205.014,84.330 207.200,85.581 207.200 C 86.520 207.200,88.369 208.847,87.700 209.087 C 86.925 209.365,87.092 210.799,87.900 210.806 C 88.415 210.811,88.464 210.898,88.086 211.138 C 87.467 211.531,87.870 212.800,88.613 212.800 C 88.904 212.800,89.224 212.485,89.324 212.100 C 89.462 211.573,89.519 211.623,89.554 212.300 C 89.601 213.216,91.200 213.673,91.200 212.771 C 91.200 211.179,92.422 213.923,92.459 215.601 C 92.498 217.299,92.615 217.607,93.153 217.422 C 93.687 217.237,93.677 217.293,93.100 217.743 C 92.356 218.323,92.155 219.200,92.767 219.200 C 92.968 219.200,93.217 218.975,93.319 218.700 C 93.454 218.334,93.700 218.387,94.238 218.900 C 94.641 219.285,94.768 219.600,94.519 219.600 C 94.270 219.600,93.976 219.375,93.865 219.100 C 93.739 218.788,93.651 218.851,93.632 219.267 C 93.614 219.633,93.375 220.008,93.100 220.100 C 92.442 220.320,93.245 222.645,93.929 222.500 C 94.188 222.445,94.400 222.580,94.400 222.800 C 94.400 223.020,94.760 223.200,95.200 223.200 C 95.640 223.200,96.000 223.020,96.000 222.800 C 96.000 222.580,96.180 222.400,96.400 222.400 C 96.620 222.400,96.800 222.604,96.800 222.853 C 96.800 223.102,97.169 223.626,97.620 224.017 C 98.127 224.457,98.280 224.827,98.020 224.988 C 97.138 225.533,97.524 227.996,98.500 228.046 C 99.111 228.078,99.188 228.149,98.741 228.268 C 96.951 228.743,99.917 232.935,102.372 233.402 C 103.403 233.598,103.602 233.755,103.172 234.032 C 102.679 234.349,102.683 234.460,103.200 234.830 C 103.652 235.155,103.676 235.311,103.300 235.464 C 101.817 236.065,103.129 237.527,104.900 237.247 C 105.065 237.221,105.179 237.335,105.153 237.500 C 105.017 238.360,105.249 239.200,105.624 239.200 C 105.857 239.200,105.919 238.992,105.762 238.738 C 105.566 238.422,105.653 238.387,106.038 238.628 C 106.347 238.821,106.780 239.001,107.000 239.029 C 107.220 239.056,107.625 239.106,107.900 239.139 C 108.253 239.182,108.400 240.139,108.400 242.400 C 108.400 244.978,108.517 245.600,109.000 245.600 C 109.330 245.600,109.600 245.780,109.600 246.000 C 109.600 246.220,109.330 246.400,109.000 246.400 C 108.107 246.400,108.275 247.852,109.275 248.784 C 110.252 249.694,111.825 249.868,112.135 249.100 C 112.249 248.818,112.351 248.925,112.368 249.347 C 112.391 249.871,112.621 250.035,113.141 249.899 C 113.783 249.732,113.860 249.901,113.718 251.153 C 113.582 252.344,113.708 252.671,114.431 253.000 C 115.411 253.447,115.490 254.271,114.534 254.073 C 114.194 254.003,114.033 254.130,114.174 254.358 C 114.617 255.075,117.243 255.374,117.644 254.753 C 118.336 253.678,118.936 255.305,118.878 258.100 C 118.866 258.705,119.023 259.200,119.228 259.200 C 119.433 259.200,119.600 259.391,119.600 259.624 C 119.600 259.857,119.420 259.936,119.200 259.800 C 118.980 259.664,118.800 259.743,118.800 259.976 C 118.800 260.209,119.115 260.414,119.500 260.432 C 119.918 260.450,119.999 260.544,119.700 260.665 C 119.092 260.910,119.027 262.800,119.627 262.800 C 119.871 262.800,119.946 263.141,119.801 263.597 C 119.457 264.679,121.256 265.584,122.198 264.802 C 122.540 264.518,122.729 264.196,122.619 264.086 C 122.509 263.976,122.169 264.094,121.863 264.348 C 121.140 264.947,120.300 264.010,120.300 262.606 C 120.300 262.028,120.128 261.721,119.888 261.869 C 119.651 262.016,119.597 261.928,119.762 261.662 C 120.180 260.986,120.308 261.067,121.090 262.500 C 121.481 263.215,122.070 263.800,122.400 263.800 C 122.730 263.800,122.975 264.115,122.944 264.500 C 122.881 265.304,123.435 265.444,123.735 264.700 C 123.856 264.401,123.950 264.482,123.968 264.900 C 123.986 265.285,124.225 265.603,124.500 265.606 C 124.825 265.610,124.854 265.715,124.583 265.906 C 123.975 266.335,123.910 268.399,124.504 268.406 C 124.844 268.410,124.821 268.526,124.429 268.774 C 123.938 269.085,123.952 269.427,124.529 271.214 C 124.898 272.357,125.200 273.502,125.200 273.760 C 125.200 274.379,127.272 275.582,128.515 275.685 C 129.416 275.759,129.484 275.897,129.298 277.283 C 129.137 278.482,129.226 278.800,129.724 278.800 C 130.070 278.800,130.463 278.978,130.597 279.195 C 130.737 279.422,130.577 279.489,130.221 279.353 C 129.495 279.074,129.441 279.356,130.014 280.426 C 130.530 281.391,131.481 281.432,131.724 280.500 C 131.862 279.973,131.919 280.023,131.954 280.700 C 131.991 281.418,132.237 281.600,133.173 281.600 C 134.526 281.600,134.818 282.213,134.599 284.592 C 134.513 285.524,134.648 286.325,134.926 286.523 C 135.288 286.781,135.282 286.909,134.900 287.064 C 133.978 287.438,134.300 289.195,135.300 289.246 C 135.977 289.281,136.027 289.338,135.500 289.476 C 133.422 290.019,135.678 292.138,138.126 291.942 L 139.896 291.800 140.019 295.200 C 140.086 297.070,140.120 299.217,140.094 299.970 C 140.068 300.724,140.234 301.691,140.463 302.119 C 140.762 302.676,140.755 302.820,140.440 302.625 C 140.164 302.454,140.000 302.734,140.000 303.376 C 140.000 304.020,140.223 304.400,140.600 304.400 C 140.930 304.400,141.200 304.580,141.200 304.800 C 141.200 305.020,140.930 305.200,140.600 305.200 C 139.469 305.200,140.125 310.068,141.433 311.376 C 141.765 311.708,142.748 312.171,143.618 312.405 L 145.200 312.831 145.200 371.186 C 145.200 426.426,145.237 429.551,145.900 429.724 C 146.526 429.888,146.521 429.912,145.850 429.954 C 145.034 430.004,145.148 431.974,146.029 433.034 C 146.542 433.653,148.884 433.658,149.294 433.042 C 149.476 432.768,149.590 432.867,149.594 433.300 C 149.597 433.685,149.753 434.000,149.941 434.000 C 150.128 434.000,150.392 435.438,150.528 437.195 C 150.875 441.696,153.111 444.734,155.423 443.846 C 155.735 443.727,155.959 443.757,155.921 443.914 C 155.468 445.767,156.564 448.379,158.041 448.970 C 159.874 449.703,160.800 449.773,160.800 449.176 C 160.800 448.943,160.575 448.882,160.300 449.041 C 160.025 449.199,159.933 449.181,160.097 449.001 C 160.260 448.821,160.170 448.401,159.897 448.067 C 159.526 447.615,159.674 447.639,160.476 448.160 C 161.152 448.600,161.466 449.085,161.320 449.465 C 161.135 449.947,161.403 450.054,162.644 449.996 C 164.953 449.887,167.071 450.035,166.500 450.265 C 165.578 450.637,165.900 452.395,166.900 452.446 C 167.577 452.481,167.627 452.538,167.100 452.676 C 166.139 452.927,166.221 453.876,167.251 454.427 C 167.915 454.782,168.177 454.764,168.445 454.341 C 168.711 453.921,168.789 453.956,168.794 454.500 C 168.801 455.317,170.796 455.516,170.806 454.700 C 170.811 454.331,170.890 454.322,171.109 454.666 C 171.319 454.997,173.199 455.094,177.602 455.002 C 181.011 454.931,188.660 454.766,194.600 454.636 C 200.540 454.505,209.360 454.335,214.200 454.258 C 224.014 454.100,226.500 453.533,227.055 451.325 C 227.551 449.348,233.384 448.538,243.730 449.009 C 256.917 449.610,264.464 449.193,265.870 447.787 C 266.193 447.464,266.635 447.200,266.852 447.200 C 267.069 447.200,267.144 447.032,267.017 446.828 C 266.891 446.623,266.970 446.342,267.193 446.204 C 267.417 446.066,267.600 445.603,267.600 445.176 C 267.600 444.749,267.842 444.400,268.139 444.400 C 268.435 444.400,269.262 444.108,269.976 443.752 C 270.952 443.265,271.920 443.160,273.860 443.331 C 276.729 443.583,277.600 443.397,277.600 442.534 C 277.600 442.214,277.745 442.042,277.922 442.152 C 278.099 442.261,278.210 441.676,278.168 440.851 C 278.107 439.660,278.267 439.273,278.945 438.975 C 279.415 438.769,280.340 437.520,281.000 436.200 C 281.913 434.374,282.436 433.767,283.187 433.661 C 284.293 433.505,285.244 432.542,286.499 430.310 C 286.965 429.479,287.629 428.794,287.974 428.787 C 289.237 428.762,290.009 427.686,290.438 425.354 C 290.676 424.059,291.024 422.640,291.212 422.200 C 291.400 421.760,291.663 420.841,291.796 420.158 C 291.993 419.147,292.321 418.831,293.553 418.461 C 294.973 418.036,295.920 416.904,296.238 415.255 C 296.997 411.308,297.221 330.214,296.558 299.400 C 295.955 271.358,296.092 268.800,298.203 268.800 C 300.031 268.800,300.722 267.613,301.008 263.978 C 301.441 258.465,302.454 256.177,304.514 256.055 C 306.645 255.930,306.528 256.161,306.434 252.278 C 306.322 247.619,307.602 243.059,308.812 243.807 C 310.104 244.606,311.961 239.513,311.992 235.086 C 312.003 233.534,313.025 232.135,314.340 231.872 C 315.677 231.605,316.383 230.240,316.643 227.419 C 317.123 222.231,318.461 219.202,320.276 219.200 C 321.000 219.200,321.223 218.632,321.816 215.281 C 323.006 208.564,323.289 207.856,324.937 207.467 C 326.862 207.011,327.042 206.583,327.368 201.655 C 327.656 197.316,328.514 195.200,329.986 195.200 C 331.808 195.200,332.400 194.102,332.400 190.721 C 332.400 186.570,333.428 184.196,335.384 183.829 C 337.847 183.367,338.118 182.893,338.052 179.165 C 337.973 174.661,339.213 171.206,340.914 171.194 C 342.886 171.180,343.493 169.278,343.593 162.800 C 343.630 160.360,344.374 159.094,346.011 158.683 C 348.290 158.111,348.596 157.538,348.655 153.727 C 348.729 148.932,349.446 147.200,351.354 147.200 C 354.163 147.200,354.939 146.605,354.629 144.690 C 353.953 140.509,353.934 139.307,354.515 137.583 L 355.116 135.800 357.593 135.680 L 360.070 135.560 359.735 133.480 C 359.379 131.270,359.376 128.053,359.728 126.400 C 359.845 125.850,359.954 124.831,359.970 124.135 C 359.997 122.985,360.141 122.847,361.554 122.608 C 364.720 122.073,365.317 120.623,364.614 115.179 C 364.383 113.391,364.452 112.855,364.964 112.430 C 365.314 112.140,365.600 111.654,365.600 111.351 C 365.600 110.956,366.172 110.800,367.626 110.800 C 371.206 110.800,371.703 109.930,370.256 106.200 C 368.964 102.869,370.231 98.811,372.571 98.787 C 375.254 98.760,375.150 99.379,375.351 82.167 C 375.451 73.605,375.609 66.150,375.704 65.600 C 375.798 65.050,376.016 63.307,376.187 61.726 L 376.498 58.852 378.449 60.773 C 379.522 61.829,380.400 62.636,380.400 62.567 C 380.400 62.092,377.794 58.718,377.171 58.384 C 376.619 58.089,376.400 57.543,376.400 56.466 C 376.400 55.638,376.184 54.744,375.920 54.480 C 375.547 54.107,375.569 53.999,376.020 53.994 C 376.498 53.989,376.504 53.927,376.057 53.644 C 375.679 53.404,375.649 53.217,375.957 53.026 C 376.634 52.608,376.484 52.002,375.700 51.987 C 375.033 51.975,375.033 51.949,375.700 51.443 C 376.741 50.653,376.617 50.596,373.995 50.648 C 371.331 50.701,370.901 50.217,371.286 47.595 C 371.383 46.938,371.323 46.400,371.154 46.400 C 370.984 46.400,370.915 46.040,371.000 45.600 C 371.114 45.006,370.929 44.788,370.277 44.754 C 369.600 44.718,369.560 44.665,370.100 44.524 C 371.140 44.252,370.983 42.315,369.819 41.058 C 368.643 39.790,366.409 39.556,366.386 40.700 C 366.378 41.085,365.973 40.230,365.486 38.800 C 364.236 35.131,363.458 34.800,355.398 34.506 C 349.495 34.290,349.200 34.241,349.200 33.462 C 349.200 32.391,347.277 30.403,346.225 30.387 C 345.771 30.380,345.051 30.110,344.624 29.787 C 343.404 28.865,262.352 28.905,261.429 29.829 M336.041 52.915 C 336.788 53.418,337.629 54.306,337.909 54.888 C 338.189 55.470,339.089 56.352,339.909 56.850 C 341.718 57.947,343.142 59.395,343.603 60.608 C 343.792 61.104,344.714 61.936,345.653 62.455 C 348.866 64.234,348.982 64.715,349.129 76.862 L 349.257 87.523 348.024 91.062 C 347.346 93.008,346.453 94.870,346.039 95.200 C 344.949 96.069,344.135 97.886,343.642 100.554 C 343.172 103.101,341.887 106.084,340.653 107.495 C 339.818 108.450,338.000 113.240,338.000 114.486 C 338.000 115.154,335.627 119.969,334.785 121.008 C 334.604 121.232,333.787 123.392,332.970 125.807 C 331.569 129.951,330.153 132.811,329.216 133.390 C 328.987 133.531,328.800 134.052,328.800 134.548 C 328.800 135.043,328.350 136.597,327.800 138.000 C 327.250 139.403,326.799 140.833,326.797 141.176 C 326.796 141.519,325.986 143.055,324.997 144.588 C 324.009 146.121,323.200 147.711,323.200 148.120 C 323.200 149.488,319.793 157.627,319.090 157.937 C 318.668 158.123,317.600 160.736,317.600 161.581 C 317.600 161.957,317.167 163.119,316.639 164.163 C 316.110 165.208,315.565 166.660,315.428 167.391 C 315.291 168.122,314.914 168.940,314.589 169.209 C 314.265 169.478,314.000 169.946,314.000 170.249 C 314.000 170.552,313.838 170.800,313.639 170.800 C 313.275 170.800,312.592 172.384,311.998 174.600 C 311.331 177.094,309.716 181.210,309.138 181.892 C 308.198 182.999,306.400 186.984,306.400 187.959 C 306.400 188.443,306.040 189.584,305.600 190.494 C 305.160 191.405,304.800 192.373,304.800 192.644 C 304.800 192.916,304.384 193.647,303.874 194.269 C 302.673 195.737,301.762 197.737,301.049 200.475 C 300.290 203.389,299.057 206.043,298.031 206.972 C 297.574 207.386,297.200 207.961,297.200 208.250 C 297.200 208.540,296.750 209.760,296.200 210.963 C 295.650 212.165,295.200 213.553,295.200 214.048 C 295.200 215.174,293.762 218.235,292.531 219.731 C 292.019 220.353,291.600 221.097,291.600 221.385 C 291.600 221.673,291.335 222.419,291.011 223.044 C 290.687 223.668,290.315 224.994,290.184 225.989 C 289.857 228.472,289.335 229.556,287.402 231.769 C 286.840 232.412,286.284 233.402,286.165 233.969 C 286.047 234.536,285.601 236.093,285.175 237.428 C 284.749 238.764,284.400 240.144,284.400 240.495 C 284.400 240.846,283.600 241.992,282.622 243.041 C 281.350 244.408,280.773 245.411,280.591 246.575 C 280.132 249.517,278.620 253.782,277.677 254.800 C 275.724 256.908,274.723 260.046,273.596 267.600 C 273.415 268.810,273.252 300.765,273.234 338.611 C 273.196 414.736,273.436 407.850,270.727 410.503 C 270.107 411.110,269.600 411.781,269.600 411.994 C 269.600 412.207,269.150 412.676,268.600 413.037 C 268.050 413.397,267.600 413.941,267.600 414.246 C 267.600 414.551,267.418 414.800,267.195 414.800 C 266.973 414.800,265.448 416.105,263.806 417.700 C 260.346 421.063,260.015 421.351,258.975 421.903 C 257.905 422.470,253.442 423.102,248.200 423.429 C 244.018 423.690,242.432 423.946,236.400 425.332 C 233.847 425.919,228.529 426.747,221.400 427.668 C 211.896 428.895,180.400 428.225,180.400 426.796 C 180.400 426.608,180.040 426.340,179.600 426.200 C 179.160 426.060,178.800 425.701,178.800 425.402 C 178.800 424.570,176.495 422.351,173.604 420.400 C 173.441 420.290,173.186 419.811,173.038 419.335 C 172.890 418.859,171.964 417.690,170.980 416.737 C 169.996 415.784,169.099 414.713,168.986 414.357 C 168.874 414.002,168.739 384.031,168.687 347.755 L 168.594 281.800 167.676 279.092 C 167.085 277.349,166.266 275.893,165.379 275.005 C 164.620 274.247,164.000 273.456,164.000 273.247 C 164.000 273.038,163.865 272.807,163.700 272.733 C 163.535 272.660,163.085 271.925,162.700 271.100 C 160.942 267.334,160.531 266.625,159.500 265.578 C 158.895 264.964,158.400 264.268,158.400 264.031 C 158.400 263.794,158.242 263.600,158.049 263.600 C 157.856 263.600,157.286 262.500,156.783 261.156 C 156.281 259.811,155.457 258.326,154.953 257.856 C 154.448 257.385,153.551 256.100,152.959 255.000 C 152.367 253.900,151.640 252.550,151.344 252.000 C 151.047 251.450,150.802 250.730,150.799 250.400 C 150.796 250.070,149.985 249.086,148.997 248.213 C 148.009 247.340,147.200 246.295,147.200 245.892 C 147.200 245.488,146.750 244.495,146.200 243.686 C 145.650 242.877,145.198 241.941,145.196 241.607 C 145.194 241.273,144.389 240.100,143.407 239.000 C 142.425 237.900,141.617 236.750,141.611 236.444 C 141.595 235.641,139.888 232.256,139.313 231.887 C 138.684 231.484,136.000 227.445,136.000 226.902 C 136.000 225.972,134.480 223.311,133.183 221.972 C 132.422 221.187,131.594 220.107,131.342 219.572 C 131.090 219.037,130.383 217.520,129.771 216.200 C 129.158 214.880,128.346 213.576,127.964 213.302 C 127.062 212.654,125.200 209.315,125.200 208.345 C 125.200 207.930,124.302 206.648,123.204 205.495 C 122.106 204.343,121.206 203.263,121.204 203.096 C 121.202 202.928,120.857 202.028,120.438 201.096 C 120.019 200.163,119.575 198.944,119.452 198.388 C 119.329 197.831,118.503 196.841,117.616 196.188 C 116.567 195.415,115.866 194.510,115.611 193.600 C 115.014 191.465,113.875 189.439,112.039 187.247 C 111.099 186.124,110.112 184.375,109.772 183.229 C 109.383 181.920,108.627 180.668,107.643 179.700 C 106.047 178.131,105.506 177.234,103.959 173.600 C 103.444 172.390,102.375 170.770,101.584 170.000 C 100.793 169.230,99.933 168.015,99.673 167.300 C 99.413 166.585,99.001 165.467,98.758 164.815 C 98.514 164.163,97.694 163.038,96.935 162.315 C 95.375 160.828,93.600 157.660,93.600 156.362 C 93.600 155.866,92.868 154.793,91.884 153.848 C 90.319 152.344,88.465 149.184,87.802 146.888 C 87.657 146.386,86.832 145.322,85.969 144.523 C 85.106 143.725,84.400 142.828,84.400 142.530 C 84.400 142.233,84.243 141.677,84.050 141.295 C 82.425 138.066,81.863 137.183,80.527 135.758 C 79.687 134.862,78.480 132.862,77.845 131.314 C 77.155 129.635,76.216 128.117,75.515 127.550 C 74.258 126.532,73.200 124.828,73.200 123.821 C 73.200 123.134,70.498 119.200,70.026 119.200 C 68.793 119.200,68.124 98.449,69.284 96.221 C 70.012 94.824,73.140 91.335,76.800 87.838 C 77.790 86.892,78.983 85.594,79.452 84.954 C 79.920 84.314,81.148 83.368,82.181 82.853 C 83.213 82.337,84.156 81.659,84.276 81.347 C 84.755 80.098,89.321 78.497,95.000 77.587 C 99.028 76.942,100.937 76.450,101.800 75.834 C 103.816 74.397,106.850 73.284,110.000 72.826 C 115.212 72.068,118.971 71.094,119.600 70.338 C 120.339 69.449,125.510 67.603,127.292 67.591 C 129.350 67.578,135.558 66.092,137.515 65.144 C 142.230 62.862,158.566 63.988,163.340 66.924 C 165.399 68.190,173.200 75.642,173.200 76.343 C 173.200 76.547,173.476 76.820,173.813 76.950 C 174.151 77.079,174.924 78.237,175.532 79.523 C 176.140 80.808,177.124 82.385,177.719 83.026 C 178.314 83.667,178.800 84.421,178.800 84.700 C 178.800 84.980,179.138 85.972,179.551 86.904 C 179.964 87.837,180.623 89.500,181.015 90.600 C 181.408 91.700,182.330 93.307,183.065 94.172 C 183.799 95.037,184.400 96.081,184.400 96.493 C 184.400 96.905,184.742 97.907,185.161 98.721 C 185.579 99.534,186.145 100.920,186.420 101.800 C 186.694 102.680,187.505 104.089,188.223 104.930 C 188.941 105.772,189.648 106.936,189.793 107.516 C 189.939 108.097,190.405 109.334,190.829 110.264 C 191.253 111.195,191.600 112.312,191.600 112.747 C 191.600 113.183,192.045 114.067,192.588 114.713 C 193.823 116.181,195.240 119.022,196.420 122.400 C 196.920 123.830,197.708 125.450,198.170 126.000 C 199.438 127.506,200.333 129.285,201.220 132.063 C 202.106 134.836,203.384 137.229,204.241 137.720 C 204.549 137.896,204.800 138.296,204.800 138.610 C 204.800 138.924,205.159 139.770,205.599 140.490 C 206.038 141.211,206.398 142.155,206.399 142.589 C 206.401 144.094,208.153 149.036,208.384 148.190 C 208.904 146.286,212.639 141.605,213.641 141.601 C 213.774 141.600,214.300 139.544,214.811 137.031 C 215.746 132.428,216.083 131.769,218.565 129.701 C 218.894 129.427,219.272 128.527,219.406 127.701 C 220.039 123.779,221.476 119.594,222.628 118.321 C 224.090 116.705,225.200 114.430,225.200 113.048 C 225.200 111.056,226.935 106.636,228.103 105.652 C 229.629 104.368,230.249 103.011,230.506 100.397 C 230.774 97.671,232.578 93.583,233.635 93.307 C 234.446 93.095,235.221 90.968,236.002 86.808 C 236.422 84.572,238.628 80.400,239.390 80.400 C 239.621 80.400,240.031 79.545,240.300 78.500 C 241.580 73.526,242.070 72.142,243.051 70.727 C 243.633 69.887,244.354 69.200,244.654 69.200 C 244.954 69.200,245.200 69.028,245.200 68.817 C 245.200 68.484,248.095 65.524,253.800 60.024 C 256.505 57.415,258.565 56.926,268.203 56.600 C 276.256 56.328,282.385 55.719,285.800 54.850 C 289.639 53.874,295.458 53.093,301.400 52.756 C 304.920 52.557,308.250 52.332,308.800 52.257 C 313.924 51.555,334.768 52.058,336.041 52.915 M66.400 178.984 C 66.400 179.306,66.794 179.936,67.275 180.384 C 68.216 181.260,69.600 181.482,69.600 180.757 C 69.600 180.514,69.336 180.416,69.013 180.540 C 68.690 180.664,68.302 180.565,68.151 180.321 C 67.969 180.026,68.065 179.990,68.438 180.215 C 68.917 180.503,68.919 180.453,68.451 179.877 C 68.149 179.505,67.643 179.200,67.327 179.200 C 67.011 179.200,66.864 179.020,67.000 178.800 C 67.136 178.580,67.057 178.400,66.824 178.400 C 66.591 178.400,66.400 178.663,66.400 178.984 M74.406 188.197 C 75.295 189.267,75.305 189.314,74.500 188.635 C 73.704 187.964,73.165 188.232,73.878 188.945 C 74.308 189.375,74.377 190.433,73.958 190.174 C 73.754 190.048,73.691 189.776,73.819 189.570 C 73.946 189.363,73.765 189.085,73.415 188.950 C 72.946 188.770,72.892 188.571,73.209 188.189 C 73.508 187.829,73.511 187.592,73.219 187.412 C 72.989 187.269,72.800 186.947,72.800 186.696 C 72.800 186.421,72.921 186.391,73.106 186.620 C 73.274 186.829,73.859 187.539,74.406 188.197 M76.726 189.787 C 75.985 190.405,74.933 190.694,74.933 190.278 C 74.933 190.015,75.365 189.773,75.893 189.741 C 76.420 189.708,76.795 189.729,76.726 189.787 M76.806 195.100 C 76.821 195.809,77.632 196.603,78.385 196.645 C 79.397 196.702,79.398 196.598,78.400 195.600 C 77.595 194.795,76.795 194.544,76.806 195.100 M84.229 203.068 C 84.088 203.436,84.203 203.882,84.486 204.062 C 84.852 204.294,84.863 204.390,84.524 204.394 C 84.262 204.397,83.946 204.236,83.822 204.036 C 83.586 203.654,83.941 202.400,84.286 202.400 C 84.396 202.400,84.370 202.701,84.229 203.068 M87.187 206.149 C 87.194 206.341,86.946 206.287,86.636 206.030 C 86.204 205.672,86.003 205.672,85.780 206.032 C 85.572 206.368,85.384 206.314,85.120 205.843 C 84.917 205.480,84.594 205.280,84.403 205.398 C 84.212 205.516,83.952 205.446,83.826 205.242 C 83.567 204.823,84.625 204.892,85.055 205.322 C 85.645 205.911,86.070 205.565,85.549 204.919 C 85.117 204.382,85.231 204.403,86.087 205.019 C 86.686 205.448,87.181 205.957,87.187 206.149 M95.600 222.484 C 95.600 222.673,95.264 222.648,94.853 222.428 C 94.442 222.208,93.963 222.157,93.788 222.314 C 93.614 222.471,93.594 222.387,93.742 222.128 C 93.891 221.868,93.827 221.540,93.600 221.400 C 93.373 221.260,93.299 220.964,93.436 220.742 C 93.694 220.324,95.600 221.857,95.600 222.484 M100.787 229.477 C 100.794 229.300,101.205 229.438,101.700 229.785 C 102.688 230.476,103.072 232.879,102.138 232.521 C 101.856 232.413,101.665 232.116,101.713 231.862 C 101.761 231.608,101.461 231.399,101.047 231.398 C 100.633 231.397,100.003 230.954,99.647 230.415 C 99.194 229.728,99.163 229.534,99.543 229.767 C 99.966 230.027,100.023 229.890,99.801 229.150 C 99.524 228.222,99.532 228.219,100.146 229.000 C 100.492 229.440,100.780 229.655,100.787 229.477 M100.000 230.376 C 100.000 230.583,100.180 230.864,100.400 231.000 C 100.620 231.136,100.800 231.021,100.800 230.744 C 100.800 230.352,100.907 230.347,101.280 230.720 C 101.974 231.414,102.590 231.311,102.000 230.600 C 101.452 229.940,100.000 229.778,100.000 230.376 M103.200 237.951 C 103.200 238.463,104.376 239.357,104.667 239.067 C 104.957 238.776,104.063 237.600,103.551 237.600 C 103.358 237.600,103.200 237.758,103.200 237.951 M110.543 247.780 C 111.142 248.379,111.344 248.824,111.061 248.925 C 110.247 249.219,109.212 248.434,109.483 247.728 C 109.666 247.251,109.590 247.159,109.206 247.396 C 108.854 247.614,108.772 247.569,108.962 247.262 C 109.349 246.635,109.422 246.658,110.543 247.780 M137.004 290.894 C 137.182 290.732,137.198 290.825,137.040 291.101 C 136.828 291.470,136.544 291.491,135.965 291.181 C 135.532 290.949,135.300 290.562,135.450 290.319 C 135.633 290.023,135.879 290.093,136.201 290.533 C 136.464 290.893,136.825 291.055,137.004 290.894 M302.131 358.200 C 302.133 359.740,302.205 360.321,302.292 359.491 C 302.379 358.661,302.377 357.401,302.289 356.691 C 302.200 355.981,302.129 356.660,302.131 358.200 M302.134 378.800 C 302.134 380.450,302.205 381.125,302.291 380.300 C 302.378 379.475,302.378 378.125,302.291 377.300 C 302.205 376.475,302.134 377.150,302.134 378.800 " stroke="none" fill="#f7f7f7" fill-rule="evenodd"></path><path id="path3" d="M316.200 74.482 C 313.780 74.675,309.100 75.267,305.800 75.798 C 294.288 77.648,289.735 78.110,280.200 78.394 C 271.536 78.652,270.427 78.763,268.825 79.540 C 267.849 80.013,266.847 80.400,266.600 80.400 C 265.484 80.400,263.478 84.031,261.992 88.736 C 261.495 90.311,260.972 91.600,260.830 91.600 C 260.308 91.600,258.408 95.914,257.159 99.937 C 256.453 102.212,255.633 104.166,255.337 104.279 C 255.042 104.393,254.800 104.709,254.800 104.982 C 254.800 105.254,254.435 105.898,253.989 106.413 C 253.543 106.927,253.083 107.809,252.966 108.374 C 252.300 111.597,251.951 112.810,251.205 114.496 C 250.750 115.525,250.214 116.468,250.014 116.591 C 249.390 116.977,247.513 121.285,247.310 122.796 C 247.204 123.588,246.515 125.398,245.779 126.818 C 243.035 132.111,242.048 134.341,241.779 135.850 C 241.395 138.005,239.967 141.282,239.099 142.000 C 238.382 142.593,236.000 149.072,236.000 150.428 C 236.000 150.813,235.283 152.036,234.406 153.145 C 233.461 154.340,232.643 155.916,232.397 157.015 C 231.643 160.379,230.126 164.167,228.639 166.400 C 227.834 167.610,227.086 169.050,226.977 169.600 C 226.514 171.933,224.671 177.209,224.175 177.621 C 223.031 178.570,221.431 181.894,221.158 183.886 C 221.001 185.033,220.586 186.545,220.236 187.247 C 219.886 187.949,219.600 188.722,219.600 188.965 C 219.600 189.209,219.230 189.638,218.779 189.921 C 217.808 190.527,216.715 192.940,216.026 196.000 C 215.299 199.225,215.194 199.544,214.674 200.115 C 214.413 200.400,214.001 200.986,213.758 201.417 C 213.403 202.047,212.806 202.223,210.708 202.317 C 207.803 202.448,206.873 201.624,206.257 198.377 C 206.113 197.620,205.727 196.484,205.398 195.854 C 205.069 195.224,204.800 194.576,204.800 194.414 C 204.800 194.251,203.983 192.877,202.985 191.359 C 201.986 189.842,201.074 188.150,200.958 187.600 C 200.646 186.122,199.143 182.772,198.176 181.400 C 196.944 179.652,195.200 176.118,195.200 175.369 C 195.200 174.660,193.061 170.572,192.164 169.569 C 191.854 169.221,191.600 168.760,191.600 168.544 C 191.600 168.327,191.240 167.405,190.800 166.494 C 190.360 165.584,190.000 164.585,190.000 164.275 C 190.000 163.965,189.595 163.094,189.100 162.338 C 188.605 161.583,187.857 160.298,187.437 159.483 C 187.017 158.667,186.542 158.000,186.382 158.000 C 186.221 158.000,185.978 157.415,185.841 156.700 C 185.631 155.598,184.292 152.754,181.083 146.600 C 180.739 145.940,179.981 144.267,179.398 142.882 C 178.815 141.497,177.633 139.117,176.769 137.594 C 175.906 136.071,175.200 134.647,175.200 134.430 C 175.200 134.063,173.546 130.567,171.119 125.800 C 169.140 121.915,167.600 118.496,167.600 117.989 C 167.600 117.706,167.150 116.886,166.600 116.164 C 166.050 115.443,165.596 114.616,165.591 114.327 C 165.586 114.037,165.230 113.350,164.800 112.800 C 164.370 112.250,164.014 111.561,164.009 111.269 C 163.999 110.690,161.225 104.725,160.815 104.400 C 160.545 104.186,159.339 101.648,157.205 96.800 C 156.479 95.150,155.640 93.516,155.342 93.169 C 155.044 92.821,154.800 92.388,154.800 92.206 C 154.800 91.559,152.688 89.120,151.504 88.400 C 149.748 87.332,147.927 87.531,136.466 90.036 C 135.513 90.244,133.443 91.025,131.866 91.770 C 129.129 93.065,126.541 93.779,120.800 94.822 C 119.370 95.082,116.723 95.998,114.919 96.858 C 113.114 97.717,110.594 98.607,109.319 98.835 C 101.677 100.204,95.831 102.132,95.325 103.450 C 95.216 103.736,94.802 104.072,94.406 104.198 C 94.010 104.324,93.584 104.736,93.458 105.113 C 93.332 105.491,92.821 106.304,92.322 106.919 C 91.751 107.624,91.568 108.142,91.829 108.319 C 92.056 108.474,92.772 109.320,93.419 110.200 C 94.066 111.080,94.704 111.890,94.836 112.000 C 94.969 112.110,95.196 112.686,95.341 113.281 C 95.487 113.875,96.241 115.045,97.017 115.881 C 98.336 117.300,100.800 121.775,100.800 122.750 C 100.800 123.138,101.555 124.102,103.646 126.386 C 104.001 126.774,104.755 128.103,105.320 129.338 C 105.886 130.574,107.125 132.713,108.074 134.092 C 109.023 135.472,110.340 137.654,111.000 138.942 C 111.660 140.230,112.740 141.863,113.400 142.570 C 114.060 143.277,114.841 144.383,115.136 145.028 C 116.870 148.821,117.877 150.657,118.465 151.098 C 119.237 151.677,121.200 155.061,121.200 155.814 C 121.200 156.096,121.979 157.288,122.931 158.463 C 123.883 159.638,125.326 161.987,126.138 163.683 C 126.949 165.378,128.159 167.358,128.825 168.083 C 129.491 168.807,130.691 170.738,131.492 172.374 C 132.292 174.009,133.229 175.645,133.574 176.009 C 134.425 176.908,134.927 177.729,136.625 181.000 C 137.424 182.540,138.496 184.250,139.007 184.800 C 139.518 185.350,140.727 187.330,141.693 189.200 C 142.660 191.070,144.139 193.500,144.981 194.600 C 145.822 195.700,146.844 197.376,147.252 198.325 C 147.660 199.274,148.265 200.322,148.597 200.654 C 148.928 200.986,149.200 201.514,149.200 201.829 C 149.200 202.143,149.376 202.400,149.592 202.400 C 149.807 202.400,150.368 203.154,150.838 204.075 C 151.308 204.996,151.942 205.999,152.246 206.303 C 152.551 206.608,152.800 207.190,152.800 207.598 C 152.800 208.005,153.250 208.873,153.800 209.527 C 154.350 210.181,154.800 210.895,154.800 211.115 C 154.800 211.335,155.040 211.607,155.334 211.719 C 155.627 211.832,156.560 213.336,157.408 215.062 C 159.057 218.422,160.307 220.411,161.079 220.908 C 161.343 221.078,162.209 222.552,163.005 224.184 C 163.801 225.816,165.019 227.927,165.713 228.876 C 166.406 229.824,167.644 231.903,168.464 233.495 C 169.284 235.087,170.508 237.079,171.185 237.922 C 171.862 238.764,173.144 240.877,174.034 242.617 C 174.924 244.357,176.236 246.505,176.951 247.391 C 177.665 248.276,178.834 250.170,179.549 251.600 C 180.264 253.030,181.482 255.100,182.257 256.200 C 183.031 257.300,184.017 258.920,184.446 259.800 C 185.571 262.105,186.086 262.902,187.096 263.904 C 188.079 264.878,189.208 267.110,190.280 270.200 C 191.048 272.414,191.623 396.672,190.884 400.737 C 190.060 405.271,194.013 407.093,202.633 406.153 C 216.314 404.661,219.686 404.206,226.000 402.995 C 228.750 402.468,233.610 401.858,236.800 401.640 C 243.279 401.197,246.609 400.557,247.800 399.525 C 248.240 399.144,248.925 398.595,249.322 398.305 C 250.734 397.275,250.781 394.972,250.790 326.564 L 250.800 258.528 251.655 255.364 C 252.126 253.624,252.596 251.513,252.700 250.674 C 252.804 249.835,253.499 248.035,254.244 246.674 C 256.412 242.719,257.591 240.061,258.066 238.062 C 258.632 235.681,259.946 232.841,260.992 231.741 C 261.733 230.962,264.000 224.862,264.000 223.648 C 264.000 223.139,266.123 219.847,267.081 218.871 C 267.366 218.581,267.600 217.964,267.600 217.502 C 267.600 216.315,269.551 210.798,270.394 209.600 C 271.552 207.953,273.200 204.479,273.200 203.682 C 273.200 202.606,275.015 198.302,276.790 195.170 C 277.633 193.683,278.449 191.866,278.605 191.133 C 278.953 189.495,281.116 184.301,281.571 184.011 C 282.061 183.699,284.400 178.039,284.400 177.167 C 284.400 176.755,284.918 175.469,285.551 174.309 C 287.646 170.471,287.937 169.831,289.352 165.961 C 290.124 163.850,291.371 160.880,292.122 159.361 C 292.873 157.843,293.709 155.970,293.981 155.200 C 295.066 152.122,295.933 150.048,297.493 146.800 C 298.391 144.930,299.518 142.320,299.998 141.000 C 300.478 139.680,301.755 136.784,302.835 134.565 C 303.916 132.346,304.800 130.236,304.800 129.875 C 304.800 129.514,305.159 128.630,305.599 127.910 C 306.038 127.189,306.398 126.290,306.399 125.912 C 306.399 125.534,306.741 124.617,307.158 123.874 C 307.575 123.132,308.489 121.191,309.189 119.562 C 309.889 117.933,310.808 115.837,311.231 114.904 C 311.654 113.972,312.000 112.978,312.000 112.697 C 312.000 112.415,312.728 110.748,313.617 108.992 C 314.507 107.237,315.601 104.720,316.049 103.400 C 316.497 102.080,317.029 100.829,317.232 100.620 C 317.434 100.411,317.600 99.866,317.600 99.409 C 317.600 98.952,317.897 98.154,318.260 97.635 C 319.203 96.289,321.200 92.087,321.200 91.449 C 321.200 90.546,323.581 85.075,324.349 84.211 C 327.008 81.222,327.263 75.874,324.808 74.604 C 323.551 73.954,322.918 73.945,316.200 74.482 M319.853 79.717 C 321.179 81.242,321.209 81.431,320.390 83.126 C 319.955 84.026,319.600 85.322,319.600 86.007 C 319.600 87.558,319.055 88.610,317.323 90.400 C 315.926 91.844,315.257 93.612,314.214 98.608 C 313.884 100.189,313.321 101.669,312.916 102.020 C 311.142 103.557,310.254 104.910,309.981 106.492 C 309.198 111.041,308.162 113.915,306.934 114.949 C 305.597 116.074,305.153 117.036,304.419 120.400 C 303.631 124.017,302.688 126.382,301.942 126.619 C 301.058 126.899,299.205 130.883,299.184 132.548 C 299.163 134.163,297.599 137.783,296.334 139.141 C 295.428 140.114,294.988 141.289,292.942 148.191 C 292.542 149.540,291.821 150.936,291.288 151.395 C 290.138 152.384,288.584 156.433,287.809 160.459 C 287.697 161.041,287.002 162.239,286.266 163.121 C 285.022 164.610,282.962 169.877,282.207 173.500 C 282.058 174.215,281.773 174.800,281.574 174.800 C 280.933 174.800,279.138 177.897,278.748 179.676 C 278.541 180.624,278.017 182.163,277.585 183.096 C 277.153 184.028,276.800 185.290,276.800 185.899 C 276.800 186.563,276.489 187.202,276.024 187.492 C 275.598 187.758,274.980 188.567,274.652 189.288 C 273.656 191.481,272.089 195.695,271.562 197.600 C 271.288 198.590,270.735 199.772,270.332 200.226 C 269.929 200.680,269.600 201.293,269.600 201.588 C 269.600 201.883,269.150 202.714,268.600 203.436 C 268.050 204.157,267.600 204.957,267.600 205.215 C 267.600 206.292,265.477 212.384,264.864 213.063 C 263.605 214.460,262.126 217.808,261.364 220.984 C 260.839 223.174,260.256 224.545,259.500 225.373 C 258.895 226.036,258.400 226.812,258.400 227.097 C 258.400 227.382,257.978 228.287,257.462 229.108 C 256.946 229.929,256.395 231.590,256.237 232.800 C 255.949 235.014,254.794 237.804,253.628 239.104 C 252.267 240.622,251.209 243.193,250.779 246.028 C 250.399 248.530,250.117 249.221,248.991 250.400 C 246.325 253.191,246.303 253.367,245.975 274.200 C 245.812 284.540,245.554 293.752,245.400 294.671 C 245.017 296.970,247.758 296.760,210.200 297.361 C 205.360 297.438,200.504 297.569,199.409 297.651 C 197.668 297.781,197.402 297.700,197.286 297.000 C 197.214 296.560,196.777 295.238,196.315 294.062 C 195.532 292.065,195.492 291.417,195.716 284.262 C 196.072 272.892,195.392 268.915,192.751 266.917 C 192.394 266.647,191.900 265.624,191.653 264.644 C 191.195 262.825,188.263 258.000,187.616 258.000 C 187.197 258.000,186.000 255.726,186.000 254.931 C 186.000 253.919,183.966 250.484,183.256 250.299 C 182.596 250.126,182.028 249.122,179.411 243.500 C 178.823 242.235,178.082 241.200,177.765 241.200 C 177.063 241.200,175.721 239.080,175.370 237.416 C 175.228 236.747,174.682 235.627,174.156 234.927 C 173.630 234.226,173.200 233.463,173.200 233.230 C 173.200 232.997,172.825 232.580,172.366 232.303 C 171.401 231.721,169.600 228.408,169.600 227.215 C 169.600 226.764,168.710 225.545,167.600 224.475 C 166.500 223.415,165.600 222.313,165.600 222.028 C 165.600 221.743,165.269 220.854,164.864 220.054 C 164.460 219.255,163.794 217.911,163.385 217.069 C 162.976 216.227,162.139 215.279,161.526 214.962 C 160.864 214.619,160.319 213.942,160.184 213.293 C 159.783 211.368,157.946 207.972,156.551 206.578 C 155.807 205.834,154.828 204.274,154.377 203.112 C 152.882 199.268,152.660 198.906,151.365 198.209 C 150.389 197.683,149.956 197.072,149.560 195.659 C 149.274 194.636,148.626 193.190,148.120 192.444 C 147.614 191.698,147.200 190.933,147.200 190.744 C 147.200 190.555,146.483 189.683,145.606 188.806 C 144.467 187.667,143.937 186.744,143.750 185.577 C 143.562 184.401,142.959 183.362,141.600 181.871 C 139.615 179.693,138.000 176.929,138.000 175.707 C 138.000 174.789,135.727 172.000,134.978 172.000 C 134.669 172.000,134.299 171.505,134.158 170.900 C 133.623 168.611,131.053 163.958,129.971 163.319 C 129.233 162.883,128.670 162.018,128.226 160.638 C 127.366 157.960,126.669 156.400,126.333 156.400 C 125.570 156.400,123.624 154.216,123.383 153.089 C 123.232 152.380,122.875 151.350,122.590 150.800 C 122.305 150.250,121.798 149.170,121.463 148.400 C 121.129 147.630,120.292 146.668,119.604 146.263 C 118.346 145.523,117.600 144.220,117.600 142.764 C 117.600 141.897,115.055 137.985,114.162 137.479 C 113.366 137.028,112.000 134.227,112.000 133.047 C 112.000 131.996,110.104 129.814,108.842 129.413 C 108.418 129.279,107.990 128.650,107.851 127.956 C 107.717 127.285,107.357 126.166,107.051 125.468 C 106.744 124.771,106.265 123.601,105.986 122.870 C 105.706 122.138,104.795 120.991,103.960 120.320 C 103.041 119.581,102.333 118.607,102.167 117.851 C 101.585 115.200,98.788 111.200,97.517 111.200 C 97.342 111.200,97.200 110.880,97.200 110.489 C 97.200 110.098,96.949 109.419,96.642 108.981 C 95.925 107.958,97.029 106.400,98.470 106.400 C 99.766 106.400,102.395 104.982,103.600 103.631 C 104.660 102.445,104.304 102.524,114.701 101.154 C 118.330 100.676,120.937 99.459,121.390 98.030 C 121.566 97.477,122.690 97.227,127.503 96.672 C 134.975 95.810,136.958 95.218,138.620 93.350 L 139.909 91.900 145.054 91.611 C 150.082 91.329,151.208 91.501,151.194 92.549 C 151.174 94.159,153.159 98.718,154.513 100.169 C 155.350 101.066,156.119 102.250,156.223 102.800 C 156.407 103.775,157.135 105.990,158.191 108.784 C 158.479 109.545,159.192 110.579,159.777 111.081 C 160.955 112.095,162.000 114.272,162.000 115.712 C 162.000 117.136,163.940 120.874,165.264 122.000 C 166.157 122.760,166.624 123.721,167.205 126.000 C 168.197 129.888,169.131 131.924,170.057 132.218 C 171.263 132.601,172.013 134.411,173.169 139.721 C 173.520 141.334,174.976 143.200,175.882 143.200 C 176.501 143.200,176.393 142.922,177.826 148.200 C 178.966 152.398,179.494 153.318,181.299 154.251 C 182.082 154.656,182.400 155.128,182.400 155.886 C 182.400 158.433,184.469 163.455,185.817 164.181 C 187.247 164.951,188.000 166.257,188.000 167.969 C 188.000 169.051,188.696 171.389,189.697 173.667 C 189.982 174.314,190.582 174.816,191.225 174.945 C 192.476 175.195,193.015 176.333,193.566 179.889 C 194.107 183.377,195.040 185.188,196.440 185.468 C 197.720 185.724,197.985 186.336,199.002 191.391 C 199.658 194.650,200.301 195.678,202.113 196.367 C 202.919 196.673,203.177 197.324,204.006 201.144 C 205.420 207.663,206.293 208.439,211.293 207.620 C 216.158 206.823,217.245 205.624,218.016 200.200 C 218.428 197.303,218.593 196.908,219.762 196.024 C 221.407 194.782,223.207 190.544,223.203 187.926 C 223.199 185.736,223.766 184.003,224.490 183.993 C 226.187 183.969,228.777 177.171,228.793 172.700 C 228.799 170.980,228.888 170.800,229.730 170.800 C 230.887 170.800,232.159 169.446,232.755 167.580 C 233.097 166.512,234.396 159.969,234.399 159.300 C 234.400 159.245,234.625 159.194,234.900 159.187 C 236.518 159.144,237.737 157.113,238.374 153.400 C 239.287 148.077,239.680 146.867,240.569 146.643 C 241.779 146.339,243.600 143.320,243.600 141.620 C 243.599 138.868,244.928 134.000,245.680 134.000 C 247.568 134.000,248.784 131.103,249.416 125.095 C 249.643 122.937,249.757 122.733,251.204 121.901 C 252.793 120.986,254.400 117.522,254.400 115.011 C 254.400 113.191,255.265 110.000,255.758 110.000 C 257.676 110.000,259.271 106.084,260.197 99.100 C 260.394 97.618,260.610 97.200,261.180 97.200 C 263.163 97.200,264.147 94.856,265.377 87.200 C 265.571 85.990,265.850 85.698,267.432 85.048 C 268.574 84.578,269.588 83.791,270.131 82.953 C 270.877 81.800,271.226 81.609,272.600 81.605 C 274.714 81.597,294.808 80.863,305.400 80.406 C 310.540 80.184,314.576 79.816,315.800 79.457 C 318.567 78.647,318.944 78.671,319.853 79.717 M231.682 397.497 C 230.078 397.573,227.558 397.573,226.082 397.496 C 224.607 397.419,225.920 397.357,229.000 397.358 C 232.080 397.358,233.287 397.421,231.682 397.497 " stroke="none" fill="#d11212" fill-rule="evenodd"></path><path id="path4" d="M370.933 45.800 C 370.933 46.130,371.052 46.400,371.197 46.400 C 371.343 46.400,371.383 46.938,371.286 47.595 C 370.932 50.007,371.360 50.588,373.587 50.720 C 375.497 50.834,377.101 49.767,375.714 49.305 C 375.478 49.226,375.377 48.810,375.489 48.381 C 375.606 47.933,375.493 47.600,375.223 47.600 C 374.964 47.600,374.859 47.428,374.989 47.218 C 375.319 46.684,373.339 45.461,372.603 45.743 C 372.271 45.871,372.000 45.801,372.000 45.587 C 372.000 45.374,371.760 45.200,371.467 45.200 C 371.173 45.200,370.933 45.470,370.933 45.800 M308.800 52.257 C 308.250 52.332,304.920 52.557,301.400 52.756 C 295.458 53.093,289.639 53.874,285.800 54.850 C 282.385 55.719,276.256 56.328,268.203 56.600 C 258.565 56.926,256.505 57.415,253.800 60.024 C 248.095 65.524,245.200 68.484,245.200 68.817 C 245.200 69.028,244.954 69.200,244.654 69.200 C 244.354 69.200,243.633 69.887,243.051 70.727 C 242.070 72.142,241.580 73.526,240.300 78.500 C 240.031 79.545,239.621 80.400,239.390 80.400 C 238.628 80.400,236.422 84.572,236.002 86.808 C 235.221 90.968,234.446 93.095,233.635 93.307 C 232.578 93.583,230.774 97.671,230.506 100.397 C 230.249 103.011,229.629 104.368,228.103 105.652 C 226.935 106.636,225.200 111.056,225.200 113.048 C 225.200 114.430,224.090 116.705,222.628 118.321 C 221.476 119.594,220.039 123.779,219.406 127.701 C 219.272 128.527,218.894 129.427,218.565 129.701 C 216.083 131.769,215.746 132.428,214.811 137.031 C 214.300 139.544,213.774 141.600,213.641 141.601 C 212.639 141.605,208.904 146.286,208.384 148.190 C 208.153 149.036,206.401 144.094,206.399 142.589 C 206.398 142.155,206.038 141.211,205.599 140.490 C 205.159 139.770,204.800 138.924,204.800 138.610 C 204.800 138.296,204.549 137.896,204.241 137.720 C 203.384 137.229,202.106 134.836,201.220 132.063 C 200.333 129.285,199.438 127.506,198.170 126.000 C 197.708 125.450,196.920 123.830,196.420 122.400 C 195.240 119.022,193.823 116.181,192.588 114.713 C 192.045 114.067,191.600 113.183,191.600 112.747 C 191.600 112.312,191.253 111.195,190.829 110.264 C 190.405 109.334,189.939 108.097,189.793 107.516 C 189.648 106.936,188.941 105.772,188.223 104.930 C 187.505 104.089,186.694 102.680,186.420 101.800 C 186.145 100.920,185.579 99.534,185.161 98.721 C 184.742 97.907,184.400 96.905,184.400 96.493 C 184.400 96.081,183.799 95.037,183.065 94.172 C 182.330 93.307,181.408 91.700,181.015 90.600 C 180.623 89.500,179.964 87.837,179.551 86.904 C 179.138 85.972,178.800 84.980,178.800 84.700 C 178.800 84.421,178.314 83.667,177.719 83.026 C 177.124 82.385,176.140 80.808,175.532 79.523 C 174.924 78.237,174.151 77.079,173.813 76.950 C 173.476 76.820,173.200 76.547,173.200 76.343 C 173.200 75.642,165.399 68.190,163.340 66.924 C 158.566 63.988,142.230 62.862,137.515 65.144 C 135.558 66.092,129.350 67.578,127.292 67.591 C 125.510 67.603,120.339 69.449,119.600 70.338 C 118.971 71.094,115.212 72.068,110.000 72.826 C 106.850 73.284,103.816 74.397,101.800 75.834 C 100.937 76.450,99.028 76.942,95.000 77.587 C 89.321 78.497,84.755 80.098,84.276 81.347 C 84.156 81.659,83.213 82.337,82.181 82.853 C 81.148 83.368,79.920 84.314,79.452 84.954 C 78.983 85.594,77.790 86.892,76.800 87.838 C 73.140 91.335,70.012 94.824,69.284 96.221 C 68.124 98.449,68.793 119.200,70.026 119.200 C 70.498 119.200,73.200 123.134,73.200 123.821 C 73.200 124.828,74.258 126.532,75.515 127.550 C 76.216 128.117,77.155 129.635,77.845 131.314 C 78.480 132.862,79.687 134.862,80.527 135.758 C 81.863 137.183,82.425 138.066,84.050 141.295 C 84.243 141.677,84.400 142.233,84.400 142.530 C 84.400 142.828,85.106 143.725,85.969 144.523 C 86.832 145.322,87.657 146.386,87.802 146.888 C 88.465 149.184,90.319 152.344,91.884 153.848 C 92.868 154.793,93.600 155.866,93.600 156.362 C 93.600 157.660,95.375 160.828,96.935 162.315 C 97.694 163.038,98.514 164.163,98.758 164.815 C 99.001 165.467,99.413 166.585,99.673 167.300 C 99.933 168.015,100.793 169.230,101.584 170.000 C 102.375 170.770,103.444 172.390,103.959 173.600 C 105.506 177.234,106.047 178.131,107.643 179.700 C 108.627 180.668,109.383 181.920,109.772 183.229 C 110.112 184.375,111.099 186.124,112.039 187.247 C 113.875 189.439,115.014 191.465,115.611 193.600 C 115.866 194.510,116.567 195.415,117.616 196.188 C 118.503 196.841,119.329 197.831,119.452 198.388 C 119.575 198.944,120.019 200.163,120.438 201.096 C 120.857 202.028,121.202 202.928,121.204 203.096 C 121.206 203.263,122.106 204.343,123.204 205.495 C 124.302 206.648,125.200 207.930,125.200 208.345 C 125.200 209.315,127.062 212.654,127.964 213.302 C 128.346 213.576,129.158 214.880,129.771 216.200 C 130.383 217.520,131.090 219.037,131.342 219.572 C 131.594 220.107,132.422 221.187,133.183 221.972 C 134.480 223.311,136.000 225.972,136.000 226.902 C 136.000 227.445,138.684 231.484,139.313 231.887 C 139.888 232.256,141.595 235.641,141.611 236.444 C 141.617 236.750,142.425 237.900,143.407 239.000 C 144.389 240.100,145.194 241.273,145.196 241.607 C 145.198 241.941,145.650 242.877,146.200 243.686 C 146.750 244.495,147.200 245.488,147.200 245.892 C 147.200 246.295,148.009 247.340,148.997 248.213 C 149.985 249.086,150.796 250.070,150.799 250.400 C 150.802 250.730,151.047 251.450,151.344 252.000 C 151.640 252.550,152.367 253.900,152.959 255.000 C 153.551 256.100,154.448 257.385,154.953 257.856 C 155.457 258.326,156.281 259.811,156.783 261.156 C 157.286 262.500,157.856 263.600,158.049 263.600 C 158.242 263.600,158.400 263.794,158.400 264.031 C 158.400 264.268,158.895 264.964,159.500 265.578 C 160.531 266.625,160.942 267.334,162.700 271.100 C 163.085 271.925,163.535 272.660,163.700 272.733 C 163.865 272.807,164.000 273.038,164.000 273.247 C 164.000 273.456,164.620 274.247,165.379 275.005 C 166.266 275.893,167.085 277.349,167.676 279.092 L 168.594 281.800 168.687 347.755 C 168.739 384.031,168.874 414.002,168.986 414.357 C 169.099 414.713,169.996 415.784,170.980 416.737 C 171.964 417.690,172.890 418.859,173.038 419.335 C 173.186 419.811,173.441 420.290,173.604 420.400 C 176.495 422.351,178.800 424.570,178.800 425.402 C 178.800 425.701,179.160 426.060,179.600 426.200 C 180.040 426.340,180.400 426.608,180.400 426.796 C 180.400 428.225,211.896 428.895,221.400 427.668 C 228.529 426.747,233.847 425.919,236.400 425.332 C 242.432 423.946,244.018 423.690,248.200 423.429 C 253.442 423.102,257.905 422.470,258.975 421.903 C 260.015 421.351,260.346 421.063,263.806 417.700 C 265.448 416.105,266.973 414.800,267.195 414.800 C 267.418 414.800,267.600 414.551,267.600 414.246 C 267.600 413.941,268.050 413.397,268.600 413.037 C 269.150 412.676,269.600 412.207,269.600 411.994 C 269.600 411.781,270.107 411.110,270.727 410.503 C 273.436 407.850,273.196 414.736,273.234 338.611 C 273.252 300.765,273.415 268.810,273.596 267.600 C 274.723 260.046,275.724 256.908,277.677 254.800 C 278.620 253.782,280.132 249.517,280.591 246.575 C 280.773 245.411,281.350 244.408,282.622 243.041 C 283.600 241.992,284.400 240.846,284.400 240.495 C 284.400 240.144,284.749 238.764,285.175 237.428 C 285.601 236.093,286.047 234.536,286.165 233.969 C 286.284 233.402,286.840 232.412,287.402 231.769 C 289.335 229.556,289.857 228.472,290.184 225.989 C 290.315 224.994,290.687 223.668,291.011 223.044 C 291.335 222.419,291.600 221.673,291.600 221.385 C 291.600 221.097,292.019 220.353,292.531 219.731 C 293.762 218.235,295.200 215.174,295.200 214.048 C 295.200 213.553,295.650 212.165,296.200 210.963 C 296.750 209.760,297.200 208.540,297.200 208.250 C 297.200 207.961,297.574 207.386,298.031 206.972 C 299.057 206.043,300.290 203.389,301.049 200.475 C 301.762 197.737,302.673 195.737,303.874 194.269 C 304.384 193.647,304.800 192.916,304.800 192.644 C 304.800 192.373,305.160 191.405,305.600 190.494 C 306.040 189.584,306.400 188.443,306.400 187.959 C 306.400 186.984,308.198 182.999,309.138 181.892 C 309.716 181.210,311.331 177.094,311.998 174.600 C 312.592 172.384,313.275 170.800,313.639 170.800 C 313.838 170.800,314.000 170.552,314.000 170.249 C 314.000 169.946,314.265 169.478,314.589 169.209 C 314.914 168.940,315.291 168.122,315.428 167.391 C 315.565 166.660,316.110 165.208,316.639 164.163 C 317.167 163.119,317.600 161.957,317.600 161.581 C 317.600 160.736,318.668 158.123,319.090 157.937 C 319.793 157.627,323.200 149.488,323.200 148.120 C 323.200 147.711,324.009 146.121,324.997 144.588 C 325.986 143.055,326.796 141.519,326.797 141.176 C 326.799 140.833,327.250 139.403,327.800 138.000 C 328.350 136.597,328.800 135.043,328.800 134.548 C 328.800 134.052,328.987 133.531,329.216 133.390 C 330.153 132.811,331.569 129.951,332.970 125.807 C 333.787 123.392,334.604 121.232,334.785 121.008 C 335.627 119.969,338.000 115.154,338.000 114.486 C 338.000 113.240,339.818 108.450,340.653 107.495 C 341.887 106.084,343.172 103.101,343.642 100.554 C 344.135 97.886,344.949 96.069,346.039 95.200 C 346.453 94.870,347.346 93.008,348.024 91.062 L 349.257 87.523 349.129 76.862 C 348.982 64.715,348.866 64.234,345.653 62.455 C 344.714 61.936,343.792 61.104,343.603 60.608 C 343.142 59.395,341.718 57.947,339.909 56.850 C 339.089 56.352,338.189 55.470,337.909 54.888 C 336.563 52.089,336.034 51.993,322.241 52.060 C 315.398 52.093,309.350 52.182,308.800 52.257 M335.060 57.436 C 335.433 58.005,336.698 59.013,337.869 59.674 C 339.041 60.335,340.000 61.160,340.000 61.507 C 340.000 62.351,343.429 65.600,344.320 65.600 C 346.588 65.600,346.502 88.861,344.231 89.733 C 343.884 89.866,343.600 90.326,343.600 90.754 C 343.600 91.183,343.465 91.593,343.300 91.667 C 342.786 91.895,341.600 94.285,341.600 95.093 C 341.600 96.369,339.725 101.319,338.913 102.188 C 337.850 103.325,336.435 106.511,336.008 108.730 C 335.431 111.724,334.472 114.042,333.398 115.037 C 332.849 115.546,332.400 116.204,332.400 116.501 C 332.400 116.797,332.244 117.211,332.053 117.420 C 331.518 118.006,330.400 121.619,330.397 122.771 C 330.395 123.800,329.603 125.247,327.930 127.280 C 327.075 128.319,325.257 133.119,325.219 134.439 C 325.199 135.111,324.471 136.600,323.182 138.600 C 321.939 140.531,321.312 142.009,320.385 145.200 C 319.275 149.024,318.520 150.800,318.006 150.800 C 317.783 150.800,317.600 151.048,317.600 151.351 C 317.600 151.654,317.360 152.102,317.066 152.345 C 316.772 152.589,316.300 153.556,316.017 154.494 C 314.327 160.096,313.490 162.394,312.987 162.811 C 312.179 163.482,310.000 168.227,310.000 169.316 C 310.000 169.819,309.640 170.937,309.200 171.800 C 308.760 172.663,308.400 173.617,308.400 173.920 C 308.400 174.224,308.052 174.771,307.626 175.136 C 306.817 175.830,304.800 180.310,304.800 181.414 C 304.800 181.764,304.350 183.035,303.800 184.237 C 303.250 185.440,302.800 186.516,302.800 186.628 C 302.800 186.740,302.414 187.354,301.943 187.992 C 301.043 189.208,299.786 192.337,299.155 194.931 C 298.950 195.773,298.328 197.303,297.773 198.331 C 295.626 202.309,295.255 203.068,294.441 205.153 C 293.978 206.338,293.600 207.570,293.600 207.893 C 293.600 208.484,292.431 211.229,292.021 211.600 C 291.339 212.217,289.193 217.363,287.625 222.139 C 287.347 222.986,286.620 224.426,286.010 225.339 C 285.400 226.253,284.773 227.450,284.618 228.000 C 284.463 228.550,283.973 229.799,283.530 230.775 C 283.088 231.751,282.628 233.191,282.510 233.975 C 282.391 234.759,281.868 235.973,281.347 236.673 C 280.826 237.374,280.400 238.169,280.400 238.442 C 280.400 238.714,280.145 239.221,279.832 239.569 C 279.199 240.273,276.800 246.948,276.800 248.006 C 276.800 248.378,276.395 249.131,275.900 249.677 C 274.761 250.935,273.645 253.071,273.205 254.833 C 272.681 256.931,270.963 261.522,270.487 262.095 C 268.527 264.457,268.624 260.876,268.506 334.626 C 268.378 414.164,268.897 405.853,263.741 410.922 C 262.469 412.173,258.873 415.970,256.938 418.105 C 255.342 419.867,254.932 419.940,244.200 420.367 C 234.760 420.742,225.651 421.936,222.197 423.251 C 221.096 423.671,218.578 424.198,216.602 424.422 C 214.626 424.647,211.837 425.000,210.404 425.207 C 205.876 425.863,186.694 425.706,185.346 425.002 C 184.716 424.674,183.916 424.404,183.568 424.402 C 183.220 424.401,182.346 423.579,181.626 422.576 C 179.956 420.251,178.505 418.800,177.849 418.800 C 177.566 418.800,176.735 417.855,176.002 416.700 C 175.270 415.545,174.430 414.316,174.136 413.969 C 173.696 413.450,173.584 401.667,173.501 347.096 L 173.400 280.852 172.342 279.726 C 171.398 278.721,169.600 275.323,169.600 274.543 C 169.600 274.181,167.716 271.317,166.738 270.193 C 165.821 269.140,164.202 266.074,163.880 264.784 C 163.741 264.225,162.921 263.065,162.057 262.207 C 161.083 261.238,159.991 259.470,159.175 257.541 C 158.453 255.832,157.288 253.842,156.587 253.117 C 155.885 252.393,154.674 250.419,153.896 248.730 C 153.117 247.042,152.102 245.337,151.640 244.941 C 151.178 244.546,150.800 244.084,150.800 243.916 C 150.800 243.747,150.516 243.277,150.169 242.872 C 149.822 242.467,148.961 240.869,148.256 239.323 C 147.551 237.776,146.323 235.896,145.527 235.145 C 144.651 234.320,143.901 233.119,143.629 232.107 C 143.381 231.187,142.988 230.316,142.756 230.173 C 142.524 230.029,141.995 229.122,141.581 228.156 C 141.167 227.190,140.650 226.400,140.431 226.400 C 139.924 226.400,138.000 223.140,138.000 222.280 C 138.000 221.923,137.230 220.679,136.288 219.516 C 134.291 217.048,132.618 214.239,132.262 212.753 C 132.124 212.177,131.333 211.007,130.505 210.153 C 129.676 209.299,128.114 206.828,127.034 204.662 C 125.953 202.496,124.807 200.624,124.487 200.501 C 124.167 200.378,123.206 198.820,122.351 197.039 C 121.496 195.258,120.160 193.171,119.381 192.402 C 118.603 191.633,117.855 190.562,117.720 190.022 C 117.396 188.733,115.295 184.711,114.678 184.200 C 113.425 183.163,112.000 181.048,112.000 180.227 C 112.000 179.725,111.103 178.114,110.006 176.647 C 108.097 174.093,107.658 173.348,105.573 169.130 C 105.065 168.101,104.278 167.087,103.825 166.876 C 103.327 166.644,102.207 164.817,101.000 162.267 C 99.900 159.943,98.640 157.841,98.200 157.596 C 97.760 157.351,96.877 155.947,96.237 154.475 C 95.598 153.004,94.743 151.501,94.337 151.136 C 93.932 150.771,93.600 150.286,93.600 150.059 C 93.600 149.831,93.271 149.410,92.869 149.123 C 92.129 148.594,90.000 144.337,90.000 143.388 C 90.000 143.104,89.188 142.098,88.196 141.153 C 87.203 140.207,86.233 138.886,86.039 138.216 C 85.497 136.346,83.563 133.059,81.900 131.186 C 81.075 130.256,80.400 129.202,80.400 128.842 C 80.400 127.902,78.919 125.273,77.820 124.263 C 74.527 121.238,73.526 117.055,73.455 106.028 L 73.400 97.456 74.400 96.243 C 78.799 90.910,85.875 84.681,88.274 84.031 C 89.113 83.804,90.430 83.195,91.200 82.679 C 93.167 81.360,95.775 80.400,97.388 80.400 C 100.146 80.400,107.652 78.436,108.782 77.419 C 109.970 76.350,113.514 75.254,117.061 74.858 C 119.028 74.638,121.349 74.191,122.219 73.863 C 123.088 73.536,124.282 73.163,124.872 73.033 C 125.462 72.904,126.248 72.495,126.618 72.124 C 128.581 70.162,133.437 69.474,146.550 69.301 C 161.107 69.109,160.103 68.936,163.421 72.206 C 164.869 73.633,166.210 74.800,166.402 74.800 C 166.594 74.800,167.316 75.587,168.006 76.549 C 168.697 77.511,169.654 78.517,170.131 78.785 C 171.529 79.567,172.800 81.429,173.342 83.486 C 173.619 84.539,174.375 86.196,175.023 87.168 C 177.125 90.326,178.041 92.159,178.624 94.378 C 178.939 95.576,179.693 97.265,180.298 98.131 C 180.904 98.997,181.719 100.177,182.108 100.753 C 182.497 101.329,183.280 103.273,183.847 105.073 C 184.518 107.204,185.358 108.908,186.254 109.955 C 187.151 111.003,188.100 112.928,188.978 115.481 C 190.147 118.880,190.863 120.133,193.010 122.540 C 193.236 122.793,193.623 123.900,193.870 125.000 C 194.572 128.123,195.363 129.913,196.660 131.311 C 198.435 133.224,199.200 134.629,199.200 135.974 C 199.200 137.451,200.967 141.425,201.759 141.729 C 202.848 142.147,204.365 145.357,204.633 147.811 C 204.913 150.379,206.319 153.315,207.597 153.998 C 208.441 154.450,212.000 151.386,212.000 150.208 C 212.000 149.893,212.450 149.186,213.000 148.636 C 213.550 148.086,214.000 147.467,214.000 147.261 C 214.000 147.055,214.240 146.794,214.532 146.681 C 215.177 146.434,217.041 141.424,217.599 138.440 C 217.876 136.956,218.443 135.742,219.410 134.562 C 220.763 132.911,223.183 126.555,223.204 124.600 C 223.214 123.593,223.606 123.013,224.500 122.683 C 224.885 122.541,225.200 122.149,225.200 121.813 C 225.200 121.476,225.373 121.200,225.584 121.200 C 225.795 121.200,226.178 120.435,226.434 119.500 C 228.171 113.162,228.933 110.926,229.535 110.400 C 230.879 109.226,232.158 106.625,232.450 104.472 C 232.737 102.354,234.938 97.200,235.554 97.200 C 236.114 97.200,237.631 93.665,237.991 91.521 C 238.522 88.365,239.176 86.740,240.470 85.364 C 241.785 83.966,243.579 79.293,243.592 77.231 C 243.598 76.137,243.961 75.517,245.400 74.138 C 246.390 73.190,247.201 72.275,247.202 72.107 C 247.206 71.509,251.397 67.600,252.034 67.600 C 252.206 67.600,252.460 67.243,252.598 66.806 C 252.887 65.897,255.070 63.600,255.645 63.600 C 256.198 63.600,258.010 62.428,259.400 61.171 L 260.600 60.085 269.200 59.887 C 278.299 59.676,290.906 58.803,300.200 57.738 C 303.280 57.385,306.970 56.966,308.400 56.805 C 309.830 56.645,316.261 56.488,322.691 56.457 L 334.382 56.400 335.060 57.436 M376.187 61.726 C 376.016 63.307,375.798 65.050,375.704 65.600 C 375.609 66.150,375.451 73.605,375.351 82.167 C 375.150 99.379,375.254 98.760,372.571 98.787 C 370.087 98.813,368.873 103.488,370.450 106.950 C 371.020 108.201,374.162 108.392,375.130 107.234 C 375.549 106.732,375.599 106.725,375.371 107.200 C 375.135 107.690,375.182 107.707,375.627 107.294 C 376.333 106.639,376.377 105.859,376.446 92.800 C 376.478 86.750,376.616 82.520,376.752 83.400 L 377.000 85.000 377.683 82.200 C 378.058 80.660,378.571 77.690,378.822 75.600 C 379.355 71.159,379.578 70.632,379.657 73.633 C 379.712 75.760,379.718 75.771,379.985 74.200 L 380.256 72.600 380.461 74.200 C 380.573 75.080,380.670 73.370,380.676 70.400 C 380.683 67.036,380.578 65.603,380.400 66.600 C 380.121 68.157,380.112 68.165,380.057 66.887 C 380.026 66.165,379.728 64.922,379.395 64.126 C 378.656 62.357,378.904 61.899,379.753 63.465 C 380.352 64.571,380.368 64.576,380.384 63.647 C 380.394 63.022,379.727 62.031,378.449 60.773 L 376.498 58.852 376.187 61.726 M201.200 61.934 C 201.200 62.660,201.453 63.211,201.857 63.367 C 202.761 63.714,202.887 63.481,202.436 62.294 C 201.850 60.753,201.200 60.564,201.200 61.934 M201.067 63.867 C 200.545 64.389,200.810 64.890,201.364 64.430 C 201.754 64.106,202.010 64.092,202.190 64.384 C 202.334 64.617,202.035 64.974,201.526 65.178 C 200.834 65.456,200.777 65.556,201.300 65.575 C 202.074 65.603,202.079 65.614,202.197 67.600 C 202.243 68.370,202.415 70.819,202.579 73.043 L 202.878 77.085 204.539 76.996 C 206.315 76.901,208.818 76.072,207.471 76.025 C 206.809 76.002,206.800 75.943,207.371 75.371 C 208.095 74.648,208.167 72.992,207.606 70.032 C 207.128 67.511,206.466 66.786,204.389 66.508 C 202.972 66.318,202.800 66.175,202.800 65.190 C 202.800 64.552,202.533 63.983,202.167 63.843 C 201.384 63.542,201.391 63.542,201.067 63.867 M377.569 77.969 C 377.285 79.078,376.975 79.909,376.881 79.814 C 376.787 79.720,376.930 78.724,377.200 77.600 C 377.470 76.476,377.779 75.646,377.888 75.755 C 377.997 75.864,377.853 76.860,377.569 77.969 M378.901 80.600 C 378.905 81.480,378.987 81.793,379.083 81.295 C 379.179 80.798,379.175 80.078,379.075 79.695 C 378.975 79.313,378.896 79.720,378.901 80.600 M378.800 97.019 C 378.800 97.360,378.324 98.080,377.742 98.619 C 376.645 99.636,376.889 99.963,378.073 99.063 C 378.734 98.560,379.521 96.400,379.043 96.400 C 378.910 96.400,378.800 96.679,378.800 97.019 M370.400 110.400 C 370.070 110.613,368.855 110.791,367.700 110.794 C 366.186 110.798,365.600 110.954,365.600 111.351 C 365.600 111.654,365.314 112.140,364.964 112.430 C 364.452 112.855,364.383 113.391,364.614 115.179 C 365.137 119.228,364.996 120.586,363.954 121.557 C 363.489 121.991,362.409 122.463,361.554 122.608 C 360.141 122.847,359.997 122.985,359.970 124.135 C 359.954 124.831,359.845 125.850,359.728 126.400 C 359.376 128.053,359.379 131.270,359.735 133.480 L 360.070 135.560 357.593 135.680 L 355.116 135.800 354.515 137.583 C 353.934 139.307,353.953 140.509,354.629 144.690 C 354.939 146.605,354.163 147.200,351.354 147.200 C 349.446 147.200,348.729 148.932,348.655 153.727 C 348.596 157.538,348.290 158.111,346.011 158.683 C 344.374 159.094,343.630 160.360,343.593 162.800 C 343.493 169.278,342.886 171.180,340.914 171.194 C 339.213 171.206,337.973 174.661,338.052 179.165 C 338.118 182.893,337.847 183.367,335.384 183.829 C 333.428 184.196,332.400 186.570,332.400 190.721 C 332.400 194.102,331.808 195.200,329.986 195.200 C 328.514 195.200,327.656 197.316,327.368 201.655 C 327.042 206.583,326.862 207.011,324.937 207.467 C 323.289 207.856,323.006 208.564,321.816 215.281 C 321.223 218.632,321.000 219.200,320.276 219.200 C 318.461 219.202,317.123 222.231,316.643 227.419 C 316.383 230.240,315.677 231.605,314.340 231.872 C 313.025 232.135,312.003 233.534,311.992 235.086 C 311.961 239.513,310.104 244.606,308.812 243.807 C 307.602 243.059,306.322 247.619,306.434 252.278 C 306.528 256.161,306.645 255.930,304.514 256.055 C 302.454 256.177,301.441 258.465,301.008 263.978 C 300.722 267.613,300.031 268.800,298.203 268.800 C 296.092 268.800,295.955 271.358,296.558 299.400 C 297.221 330.214,296.997 411.308,296.238 415.255 C 295.920 416.904,294.973 418.036,293.553 418.461 C 292.321 418.831,291.993 419.147,291.796 420.158 C 291.663 420.841,291.400 421.760,291.212 422.200 C 291.024 422.640,290.676 424.059,290.438 425.354 C 290.009 427.686,289.237 428.762,287.974 428.787 C 287.629 428.794,286.965 429.479,286.499 430.310 C 285.244 432.542,284.293 433.505,283.187 433.661 C 282.436 433.767,281.913 434.374,281.000 436.200 C 280.340 437.520,279.415 438.769,278.945 438.975 C 278.267 439.273,278.107 439.660,278.168 440.851 C 278.210 441.676,278.099 442.261,277.922 442.152 C 277.745 442.042,277.600 442.214,277.600 442.534 C 277.600 443.397,276.729 443.583,273.860 443.331 C 271.920 443.160,270.952 443.265,269.976 443.752 C 269.262 444.108,268.435 444.400,268.139 444.400 C 267.842 444.400,267.600 444.749,267.600 445.176 C 267.600 445.603,267.417 446.066,267.193 446.204 C 266.970 446.342,266.891 446.623,267.017 446.828 C 267.144 447.032,267.069 447.200,266.852 447.200 C 266.635 447.200,266.193 447.464,265.870 447.787 C 264.464 449.193,256.917 449.610,243.730 449.009 C 233.384 448.538,227.551 449.348,227.055 451.325 C 226.500 453.533,224.014 454.100,214.200 454.258 C 188.433 454.671,184.099 454.767,183.000 454.950 C 182.340 455.060,180.874 455.188,179.742 455.235 L 177.684 455.321 178.082 456.463 C 178.586 457.908,180.207 459.200,181.517 459.200 C 182.384 459.200,182.283 459.071,180.790 458.282 C 179.836 457.777,178.969 457.108,178.865 456.794 C 178.760 456.480,179.257 456.713,179.968 457.312 C 180.680 457.911,182.013 458.524,182.931 458.675 C 184.461 458.926,184.517 458.976,183.600 459.269 C 182.986 459.465,183.588 459.514,185.159 459.394 C 186.566 459.287,190.706 459.164,194.359 459.121 C 200.734 459.045,200.824 459.033,196.600 458.821 L 192.200 458.600 196.800 458.302 C 199.330 458.138,206.530 457.962,212.800 457.911 L 224.200 457.818 212.400 457.600 L 200.600 457.382 212.140 457.291 C 223.663 457.200,227.765 456.691,225.959 455.574 C 225.685 455.405,227.200 455.267,229.327 455.267 C 232.965 455.267,233.169 455.310,232.796 456.007 C 232.578 456.414,232.400 456.950,232.400 457.197 C 232.400 457.911,233.213 457.217,233.615 456.161 C 233.970 455.226,234.100 455.200,238.490 455.190 C 240.971 455.185,243.720 455.013,244.600 454.808 C 245.609 454.573,246.249 454.577,246.333 454.818 C 246.568 455.489,248.400 455.258,248.400 454.557 C 248.400 454.173,248.623 454.000,248.956 454.128 C 250.090 454.563,254.602 452.656,254.575 451.753 C 254.551 450.982,254.663 450.952,256.151 451.330 C 257.396 451.645,257.585 451.795,257.000 452.000 C 256.470 452.186,256.890 452.391,258.424 452.696 C 260.890 453.185,261.569 453.042,259.544 452.459 C 258.805 452.246,258.470 452.047,258.800 452.015 C 259.130 451.984,258.320 451.531,257.000 451.008 C 254.008 449.822,254.718 449.716,258.137 450.838 C 260.612 451.651,260.733 451.655,262.046 450.965 C 262.791 450.574,264.119 450.213,264.998 450.164 L 266.595 450.073 265.475 451.037 C 264.859 451.566,264.581 452.000,264.856 452.000 C 265.131 452.000,265.828 451.548,266.406 450.995 C 267.335 450.104,267.828 449.981,270.728 449.920 C 272.527 449.881,274.000 449.684,274.000 449.482 C 274.000 449.280,274.265 449.216,274.588 449.340 C 275.382 449.645,276.427 448.537,276.115 447.723 C 275.947 447.285,276.019 447.165,276.332 447.358 C 276.589 447.517,276.800 447.469,276.800 447.251 C 276.800 447.032,277.170 446.736,277.623 446.593 C 278.076 446.449,278.611 445.897,278.813 445.366 C 279.127 444.541,279.445 444.400,280.990 444.400 C 281.986 444.400,282.800 444.224,282.800 444.010 C 282.800 443.767,283.151 443.753,283.733 443.975 C 284.429 444.239,284.667 444.190,284.667 443.782 C 284.667 443.481,284.489 443.345,284.272 443.479 C 284.049 443.617,284.002 443.520,284.166 443.255 C 284.325 442.998,284.623 442.891,284.828 443.017 C 285.032 443.144,285.200 443.062,285.200 442.836 C 285.200 442.610,285.470 442.529,285.800 442.655 C 286.130 442.782,286.400 442.701,286.400 442.476 C 286.400 442.251,286.196 441.999,285.946 441.915 C 285.643 441.814,285.694 441.563,286.103 441.154 C 286.439 440.818,286.783 440.196,286.867 439.772 C 286.973 439.235,287.291 439.038,287.910 439.125 C 288.399 439.194,288.800 439.053,288.800 438.811 C 288.800 438.506,289.028 438.494,289.547 438.771 C 290.175 439.107,290.286 439.030,290.247 438.288 C 290.218 437.753,290.437 437.400,290.800 437.393 C 291.130 437.386,291.375 437.070,291.344 436.690 C 291.314 436.311,291.468 436.000,291.688 436.000 C 291.915 436.000,291.977 435.564,291.834 434.991 C 291.656 434.285,291.763 433.912,292.188 433.749 C 292.522 433.621,292.706 433.372,292.597 433.195 C 292.488 433.019,292.743 432.964,293.162 433.074 C 293.621 433.194,294.274 432.926,294.796 432.404 C 295.275 431.925,295.787 431.654,295.933 431.801 C 296.080 431.948,295.775 432.413,295.256 432.834 C 294.736 433.255,294.483 433.600,294.694 433.600 C 295.088 433.600,296.032 432.628,296.601 431.638 C 296.800 431.292,296.769 431.172,296.520 431.326 C 296.281 431.474,296.133 431.106,296.158 430.427 C 296.201 429.253,296.800 429.125,296.800 430.290 C 296.800 430.644,296.911 430.823,297.046 430.687 C 297.182 430.552,297.105 429.902,296.875 429.244 C 296.646 428.586,296.615 427.992,296.807 427.924 C 296.999 427.856,297.194 426.589,297.241 425.108 C 297.324 422.454,297.340 422.420,298.322 422.666 C 298.984 422.833,299.230 422.772,299.053 422.486 C 298.906 422.249,299.169 421.787,299.637 421.459 C 300.154 421.097,300.367 420.671,300.182 420.370 C 299.971 420.030,300.041 419.978,300.406 420.204 C 300.794 420.444,300.865 420.347,300.673 419.845 C 300.522 419.452,300.572 419.259,300.789 419.393 C 300.999 419.523,301.354 419.037,301.580 418.314 C 301.986 417.016,301.988 417.020,301.761 418.586 C 301.635 419.459,301.174 420.674,300.738 421.286 C 300.302 421.899,300.099 422.400,300.287 422.400 C 301.159 422.400,302.178 419.726,302.153 417.500 C 302.139 416.235,302.278 415.200,302.464 415.200 C 302.649 415.200,302.800 412.320,302.800 408.800 C 302.800 405.280,302.665 402.400,302.500 402.400 C 302.335 402.400,302.169 377.549,302.131 347.176 C 302.093 316.803,301.942 291.243,301.796 290.376 C 301.579 289.091,301.647 288.800,302.165 288.800 C 302.877 288.800,303.146 281.396,302.444 281.133 C 302.240 281.057,302.229 280.146,302.420 279.000 C 302.603 277.900,302.763 275.323,302.776 273.273 C 302.800 269.604,302.814 269.550,303.700 269.799 C 304.315 269.972,304.431 269.935,304.066 269.682 C 303.413 269.228,304.600 268.629,305.298 269.061 C 305.539 269.210,305.607 269.135,305.455 268.889 C 305.308 268.651,305.382 268.335,305.621 268.187 C 305.859 268.040,305.961 267.676,305.848 267.380 C 305.705 267.008,305.852 266.920,306.320 267.095 C 306.885 267.307,306.917 267.247,306.510 266.745 C 305.981 266.094,306.506 265.200,307.416 265.200 C 307.727 265.200,307.900 263.647,307.963 260.306 C 308.069 254.653,307.881 255.094,310.221 254.992 C 311.226 254.948,312.262 254.681,312.524 254.398 C 312.894 253.997,312.889 253.945,312.500 254.165 C 312.225 254.320,312.000 254.257,312.000 254.024 C 312.000 253.791,312.234 253.600,312.520 253.600 C 312.890 253.600,313.066 252.766,313.130 250.700 C 313.214 248.023,313.312 247.723,314.414 246.800 C 315.070 246.250,315.606 245.438,315.604 244.996 C 315.602 244.554,316.005 243.940,316.500 243.632 C 317.308 243.129,317.347 243.136,316.881 243.700 C 316.480 244.185,316.472 244.397,316.842 244.626 C 317.149 244.815,317.219 244.755,317.036 244.459 C 316.876 244.199,317.024 243.889,317.372 243.755 C 317.715 243.624,317.883 243.335,317.746 243.113 C 317.610 242.892,317.746 242.537,318.049 242.325 C 318.442 242.050,318.467 241.884,318.134 241.748 C 317.806 241.613,317.777 241.179,318.034 240.281 C 318.235 239.579,318.418 237.924,318.440 236.603 C 318.474 234.523,319.049 231.378,319.160 232.657 C 319.182 232.909,319.495 233.228,319.857 233.366 C 320.409 233.579,320.432 233.521,320.000 233.000 C 319.576 232.489,319.586 232.420,320.057 232.601 C 320.840 232.901,322.515 231.275,322.218 230.503 C 322.022 229.992,322.086 229.973,322.591 230.392 C 323.391 231.057,323.377 230.634,322.571 229.829 C 322.000 229.257,322.009 229.200,322.671 229.200 C 323.149 229.200,323.413 228.890,323.438 228.300 C 323.459 227.805,323.527 225.960,323.589 224.200 C 323.651 222.440,323.904 220.740,324.151 220.423 C 324.451 220.038,324.456 219.933,324.167 220.106 C 323.928 220.248,323.733 220.111,323.733 219.800 C 323.733 219.489,323.864 219.316,324.025 219.415 C 324.185 219.514,324.419 219.326,324.546 218.998 C 324.672 218.669,325.006 218.403,325.287 218.406 C 325.646 218.410,325.620 218.529,325.200 218.800 C 324.780 219.071,324.754 219.190,325.113 219.194 C 325.394 219.197,325.730 218.925,325.859 218.590 C 326.024 218.161,326.239 218.100,326.580 218.383 C 326.925 218.670,327.290 218.527,327.833 217.894 C 328.718 216.862,328.662 217.239,328.740 211.787 C 328.800 207.544,329.417 206.035,330.434 207.642 C 330.699 208.060,330.789 207.971,330.794 207.286 C 330.799 206.463,330.890 206.420,331.700 206.851 C 332.526 207.292,332.553 207.274,332.032 206.643 C 331.542 206.049,331.542 205.972,332.032 206.077 C 332.351 206.146,332.546 205.951,332.477 205.632 C 332.372 205.142,332.449 205.142,333.043 205.632 C 333.674 206.153,333.692 206.126,333.251 205.300 C 332.943 204.722,332.920 204.400,333.186 204.400 C 333.414 204.400,333.600 204.070,333.600 203.667 C 333.600 203.263,333.725 202.808,333.878 202.655 C 334.247 202.287,334.346 201.523,334.441 198.320 C 334.496 196.447,334.689 195.575,335.081 195.424 C 335.448 195.283,335.539 195.380,335.344 195.705 C 335.147 196.033,335.275 196.015,335.723 195.651 C 336.357 195.137,336.588 195.307,336.425 196.168 C 336.386 196.370,336.635 196.303,336.977 196.019 C 337.668 195.446,337.825 195.014,337.203 195.398 C 336.974 195.540,336.840 195.223,336.888 194.651 C 336.933 194.105,337.114 193.747,337.291 193.856 C 337.468 193.966,337.509 194.223,337.383 194.428 C 337.256 194.632,337.247 194.800,337.362 194.800 C 337.478 194.800,337.776 194.418,338.026 193.952 C 338.338 193.368,338.344 193.187,338.044 193.373 C 337.773 193.540,337.699 193.408,337.847 193.021 C 337.978 192.679,338.471 192.397,338.943 192.394 C 339.574 192.389,339.658 192.298,339.259 192.045 C 338.850 191.786,338.822 191.506,339.145 190.902 C 339.381 190.462,339.599 188.201,339.629 185.877 C 339.673 182.559,339.812 181.604,340.275 181.427 C 341.109 181.106,341.282 181.143,341.010 181.584 C 340.872 181.807,341.294 181.786,342.018 181.534 C 342.703 181.295,343.359 180.852,343.475 180.550 C 343.591 180.247,343.936 180.000,344.243 180.000 C 344.895 180.000,344.996 179.332,344.375 179.125 C 344.094 179.031,344.074 178.647,344.316 177.992 C 344.517 177.446,344.715 175.830,344.756 174.400 C 344.851 171.076,345.065 170.373,345.886 170.688 C 346.361 170.871,346.446 170.786,346.207 170.368 C 345.945 169.909,345.985 169.895,346.420 170.299 C 347.007 170.843,349.200 169.155,349.200 168.158 C 349.200 167.888,349.425 167.576,349.700 167.465 C 350.100 167.304,350.100 167.257,349.700 167.232 C 349.150 167.197,348.993 165.600,349.539 165.600 C 349.726 165.600,349.926 164.295,349.985 162.700 C 350.043 161.105,350.100 159.575,350.112 159.300 C 350.124 159.025,350.474 158.800,350.890 158.800 C 351.307 158.800,351.537 158.978,351.403 159.195 C 351.261 159.424,351.427 159.488,351.796 159.346 C 352.506 159.074,354.186 156.053,353.828 155.695 C 353.703 155.569,353.600 155.671,353.600 155.921 C 353.600 156.171,353.322 156.268,352.983 156.138 C 352.414 155.920,352.512 155.426,353.133 155.380 C 354.965 155.245,355.068 154.966,355.163 149.900 C 355.213 147.212,355.287 144.981,355.327 144.943 C 355.367 144.905,356.030 144.812,356.800 144.737 C 357.570 144.662,358.470 144.322,358.800 143.981 C 359.130 143.641,359.256 143.580,359.081 143.846 C 358.900 144.119,358.970 144.458,359.242 144.626 C 359.529 144.803,359.619 144.755,359.466 144.507 C 359.325 144.278,359.450 143.891,359.745 143.646 C 360.116 143.338,360.292 142.066,360.318 139.501 C 360.338 137.465,360.365 135.294,360.378 134.676 C 360.390 134.034,360.571 133.659,360.800 133.800 C 361.020 133.936,361.200 133.664,361.200 133.195 C 361.200 132.420,361.257 132.400,361.829 132.971 C 362.667 133.810,363.040 133.776,362.349 132.923 C 361.916 132.390,361.912 132.314,362.331 132.566 C 362.664 132.767,363.147 132.579,363.631 132.059 C 364.486 131.141,364.649 130.599,363.938 131.038 C 363.645 131.219,363.585 131.147,363.774 130.842 C 364.002 130.474,364.203 130.471,364.636 130.830 C 365.402 131.465,365.353 131.010,364.571 130.229 C 364.000 129.657,364.013 129.600,364.715 129.600 C 365.409 129.600,365.495 129.267,365.566 126.300 C 365.637 123.331,365.753 122.882,366.722 121.823 L 367.800 120.646 366.748 121.301 L 365.696 121.955 365.748 120.429 C 365.784 119.387,365.959 118.963,366.300 119.094 C 366.870 119.313,366.933 119.668,366.500 120.228 C 366.335 120.442,366.515 120.278,366.900 119.864 C 367.285 119.450,367.600 119.303,367.600 119.538 C 367.600 119.772,368.052 119.512,368.603 118.960 C 369.157 118.407,369.812 118.084,370.065 118.240 C 370.348 118.415,370.414 118.347,370.238 118.062 C 370.073 117.795,370.194 117.600,370.526 117.600 C 370.977 117.600,371.113 116.798,371.169 113.800 C 371.208 111.710,371.186 110.003,371.120 110.006 C 371.054 110.009,370.730 110.187,370.400 110.400 M368.255 118.678 C 367.823 119.111,366.800 119.171,366.800 118.765 C 366.800 118.564,367.190 118.400,367.667 118.400 C 368.143 118.400,368.408 118.525,368.255 118.678 M353.200 156.800 C 353.200 157.020,352.990 157.200,352.733 157.200 C 352.477 157.200,352.385 157.318,352.530 157.463 C 352.938 157.872,352.006 158.777,351.412 158.549 C 351.016 158.397,351.099 158.112,351.742 157.415 C 352.680 156.398,353.200 156.178,353.200 156.800 M56.000 161.200 C 56.000 161.420,56.191 161.600,56.424 161.600 C 56.657 161.600,56.736 161.780,56.600 162.000 C 56.464 162.220,56.554 162.400,56.800 162.400 C 57.046 162.400,57.136 162.580,57.000 162.800 C 56.864 163.020,56.943 163.200,57.176 163.200 C 57.409 163.200,57.600 163.391,57.600 163.624 C 57.600 163.857,57.375 163.912,57.100 163.747 C 56.760 163.543,56.776 163.663,57.149 164.123 C 57.853 164.991,57.891 164.979,57.827 163.900 C 57.728 162.236,56.000 159.683,56.000 161.200 M66.273 175.481 C 66.128 175.717,66.261 176.118,66.569 176.374 C 67.143 176.851,67.959 176.226,67.440 175.707 C 67.308 175.575,67.187 175.722,67.172 176.033 C 67.155 176.369,67.020 176.284,66.841 175.827 C 66.658 175.358,66.434 175.222,66.273 175.481 M66.400 178.000 C 66.400 178.220,66.591 178.400,66.824 178.400 C 67.057 178.400,67.136 178.580,67.000 178.800 C 66.864 179.020,67.078 179.203,67.476 179.206 C 68.025 179.211,68.071 179.294,67.666 179.550 C 67.109 179.904,68.163 180.629,68.963 180.442 C 69.163 180.396,69.475 180.592,69.657 180.879 C 69.839 181.165,69.991 181.209,69.994 180.975 C 69.997 180.742,69.460 180.151,68.800 179.663 C 68.140 179.175,67.600 178.511,67.600 178.188 C 67.600 177.865,67.330 177.600,67.000 177.600 C 66.670 177.600,66.400 177.780,66.400 178.000 M72.800 186.696 C 72.800 186.947,72.989 187.269,73.219 187.412 C 73.511 187.592,73.508 187.829,73.209 188.189 C 72.892 188.571,72.946 188.770,73.415 188.950 C 73.765 189.085,73.946 189.363,73.819 189.570 C 73.691 189.776,73.754 190.048,73.958 190.174 C 74.377 190.433,74.308 189.375,73.878 188.945 C 73.165 188.232,73.704 187.964,74.500 188.635 C 75.305 189.314,75.295 189.267,74.406 188.197 C 73.859 187.539,73.274 186.829,73.106 186.620 C 72.921 186.391,72.800 186.421,72.800 186.696 M74.985 190.378 C 75.032 190.696,75.284 190.998,75.545 191.048 C 75.904 191.118,75.905 191.086,75.549 190.916 C 75.259 190.778,75.443 190.498,76.032 190.183 L 76.984 189.673 75.942 189.737 C 75.284 189.777,74.932 190.013,74.985 190.378 M76.800 194.400 C 76.800 194.620,77.070 194.800,77.400 194.800 C 77.730 194.800,78.000 194.991,78.000 195.224 C 78.000 195.457,77.775 195.516,77.500 195.355 C 77.225 195.194,77.343 195.453,77.762 195.931 C 78.551 196.831,79.033 197.100,78.600 196.400 C 78.464 196.180,78.528 196.000,78.743 196.000 C 78.958 196.000,79.214 196.225,79.312 196.500 C 79.410 196.775,79.613 196.887,79.763 196.749 C 79.913 196.611,79.474 195.936,78.787 195.249 C 77.520 193.982,76.800 193.674,76.800 194.400 M83.841 203.036 C 83.552 203.791,83.859 204.402,84.524 204.394 C 84.863 204.390,84.852 204.294,84.486 204.062 C 84.203 203.882,84.088 203.436,84.229 203.068 C 84.370 202.701,84.396 202.400,84.286 202.400 C 84.176 202.400,83.976 202.686,83.841 203.036 M85.549 204.919 C 86.070 205.565,85.645 205.911,85.055 205.322 C 84.625 204.892,83.567 204.823,83.826 205.242 C 83.952 205.446,84.212 205.516,84.403 205.398 C 84.594 205.280,84.917 205.480,85.120 205.843 C 85.384 206.314,85.572 206.368,85.780 206.032 C 86.003 205.672,86.204 205.672,86.636 206.030 C 86.946 206.287,87.194 206.341,87.187 206.149 C 87.181 205.957,86.686 205.448,86.087 205.019 C 85.231 204.403,85.117 204.382,85.549 204.919 M93.043 219.033 C 92.715 219.886,92.734 220.000,93.200 220.000 C 93.420 220.000,93.614 219.685,93.632 219.300 C 93.650 218.882,93.744 218.801,93.865 219.100 C 93.976 219.375,94.254 219.600,94.482 219.600 C 94.733 219.600,94.701 219.362,94.400 219.000 C 93.761 218.230,93.347 218.240,93.043 219.033 M93.481 220.652 C 93.339 220.795,93.349 221.111,93.505 221.356 C 93.660 221.600,93.791 221.965,93.794 222.167 C 93.797 222.369,94.205 222.564,94.700 222.600 C 95.195 222.636,95.600 222.548,95.600 222.403 C 95.600 221.921,93.745 220.388,93.481 220.652 M99.801 229.150 C 100.023 229.890,99.966 230.027,99.543 229.767 C 99.163 229.534,99.194 229.728,99.647 230.415 C 100.003 230.954,100.633 231.397,101.047 231.398 C 101.461 231.399,101.761 231.608,101.713 231.862 C 101.665 232.116,101.856 232.413,102.138 232.521 C 103.072 232.879,102.688 230.476,101.700 229.785 C 101.205 229.438,100.794 229.300,100.787 229.477 C 100.780 229.655,100.492 229.440,100.146 229.000 C 99.532 228.219,99.524 228.222,99.801 229.150 M102.000 230.600 C 102.590 231.311,101.974 231.414,101.280 230.720 C 100.907 230.347,100.800 230.352,100.800 230.744 C 100.800 231.021,100.620 231.136,100.400 231.000 C 99.740 230.592,99.948 230.000,100.751 230.000 C 101.164 230.000,101.726 230.270,102.000 230.600 M103.687 237.623 C 104.065 237.844,104.556 238.335,104.777 238.713 C 105.117 239.293,105.169 239.241,105.109 238.381 C 105.055 237.594,104.806 237.345,104.019 237.291 C 103.159 237.231,103.107 237.283,103.687 237.623 M315.200 244.869 C 315.200 245.427,314.018 246.800,313.538 246.800 C 312.866 246.800,313.197 244.859,313.900 244.676 C 315.082 244.367,315.200 244.384,315.200 244.869 M108.400 246.000 C 108.400 246.220,108.670 246.400,109.000 246.400 C 109.330 246.400,109.600 246.220,109.600 246.000 C 109.600 245.780,109.330 245.600,109.000 245.600 C 108.670 245.600,108.400 245.780,108.400 246.000 M108.962 247.262 C 108.772 247.569,108.854 247.614,109.206 247.396 C 109.590 247.159,109.666 247.251,109.483 247.728 C 109.212 248.434,110.247 249.219,111.061 248.925 C 111.344 248.824,111.142 248.379,110.543 247.780 C 109.422 246.658,109.349 246.635,108.962 247.262 M114.400 253.200 C 114.933 253.545,114.933 253.589,114.400 253.600 C 113.880 253.611,113.878 253.661,114.381 253.980 C 114.700 254.182,115.114 254.253,115.300 254.138 C 115.720 253.879,114.868 252.798,114.251 252.806 C 114.003 252.809,114.070 252.987,114.400 253.200 M119.762 261.662 C 119.585 261.948,119.652 262.015,119.938 261.838 C 120.192 261.681,120.400 261.733,120.400 261.953 C 120.400 262.173,120.220 262.464,120.000 262.600 C 119.780 262.736,119.603 263.062,119.606 263.324 C 119.610 263.610,119.767 263.561,120.000 263.200 C 120.337 262.678,120.389 262.685,120.394 263.251 C 120.402 264.117,121.438 264.985,121.788 264.419 C 121.931 264.189,122.239 264.000,122.473 264.000 C 122.724 264.000,122.673 264.273,122.349 264.665 C 121.878 265.235,121.886 265.302,122.400 265.132 C 122.730 265.023,123.000 264.678,123.000 264.367 C 123.000 264.055,122.730 263.800,122.400 263.800 C 122.070 263.800,121.481 263.215,121.090 262.500 C 120.308 261.067,120.180 260.986,119.762 261.662 M135.450 290.319 C 135.300 290.562,135.532 290.949,135.965 291.181 C 136.544 291.491,136.828 291.470,137.040 291.101 C 137.198 290.825,137.182 290.732,137.004 290.894 C 136.825 291.055,136.464 290.893,136.201 290.533 C 135.879 290.093,135.633 290.023,135.450 290.319 M140.000 304.800 C 140.000 305.020,140.270 305.200,140.600 305.200 C 140.930 305.200,141.200 305.020,141.200 304.800 C 141.200 304.580,140.930 304.400,140.600 304.400 C 140.270 304.400,140.000 304.580,140.000 304.800 M301.476 325.900 C 301.375 326.285,301.293 325.970,301.293 325.200 C 301.293 324.430,301.375 324.115,301.476 324.500 C 301.576 324.885,301.576 325.515,301.476 325.900 M301.899 349.500 C 301.833 352.965,301.778 350.130,301.778 343.200 C 301.778 336.270,301.833 333.435,301.899 336.900 C 301.966 340.365,301.966 346.035,301.899 349.500 M301.498 372.300 C 301.426 374.445,301.367 372.690,301.367 368.400 C 301.367 364.110,301.426 362.355,301.498 364.500 C 301.570 366.645,301.570 370.155,301.498 372.300 M301.898 392.080 C 301.826 394.126,301.766 392.560,301.765 388.600 C 301.765 384.640,301.824 382.966,301.898 384.880 C 301.971 386.794,301.971 390.034,301.898 392.080 M277.289 445.400 C 276.460 446.509,276.216 446.387,276.556 445.033 C 276.724 444.365,277.005 444.104,277.394 444.253 C 277.893 444.445,277.878 444.613,277.289 445.400 M159.897 448.067 C 160.170 448.401,160.260 448.821,160.097 449.001 C 159.933 449.181,160.010 449.208,160.266 449.062 C 160.522 448.915,160.804 449.012,160.893 449.278 C 161.005 449.615,161.135 449.629,161.323 449.324 C 161.472 449.084,161.100 448.566,160.497 448.174 C 159.699 447.655,159.536 447.626,159.897 448.067 M263.101 451.163 C 262.496 451.551,262.121 451.988,262.267 452.134 C 262.414 452.280,262.203 452.400,261.800 452.400 C 261.397 452.400,261.165 452.499,261.286 452.619 C 261.407 452.740,261.994 452.716,262.591 452.567 C 263.388 452.367,263.533 452.204,263.138 451.953 C 262.842 451.766,262.791 451.609,263.024 451.606 C 263.256 451.603,263.796 451.336,264.224 451.013 C 265.310 450.191,264.434 450.309,263.101 451.163 M224.912 456.048 C 224.396 456.564,218.664 456.691,208.600 456.409 C 202.015 456.225,202.160 456.212,213.200 456.000 C 219.470 455.880,224.771 455.740,224.980 455.691 C 225.189 455.641,225.158 455.802,224.912 456.048 M226.400 456.619 C 225.410 457.146,224.849 457.583,225.153 457.589 C 225.703 457.600,228.400 456.087,228.400 455.767 C 228.400 455.547,228.468 455.518,226.400 456.619 M188.100 459.891 C 188.925 459.978,190.275 459.978,191.100 459.891 C 191.925 459.805,191.250 459.734,189.600 459.734 C 187.950 459.734,187.275 459.805,188.100 459.891 " stroke="none" fill="#848484" fill-rule="evenodd"></path></g></svg><a title="Expérimentations et tests
|
||
" href="/">YannStatic</a></div><!--<button class="button button--secondary button--circle search-button js-search-toggle"><i class="fas fa-search"></i></button>--><!-- <li><button class="button button--secondary button--circle search-button js-search-toggle"><i class="fas fa-search"></i></button></li> -->
|
||
<!-- Champ de recherche -->
|
||
<div id="searchbox" class="search search--dark" style="visibility: visible">
|
||
<div class="main">
|
||
<div class="search__header"></div>
|
||
<div class="search-bar">
|
||
<div class="search-box js-search-box">
|
||
<div class="search-box__icon-search"><i class="fas fa-search"></i></div>
|
||
<input id="search-input" type="text" />
|
||
<!-- <div class="search-box__icon-clear js-icon-clear">
|
||
<a><i class="fas fa-times"></i></a>
|
||
</div> -->
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
<!-- Script pointing to search-script.js -->
|
||
<script>/*!
|
||
* Simple-Jekyll-Search
|
||
* Copyright 2015-2020, Christian Fei
|
||
* Licensed under the MIT License.
|
||
*/
|
||
|
||
(function(){
|
||
'use strict'
|
||
|
||
var _$Templater_7 = {
|
||
compile: compile,
|
||
setOptions: setOptions
|
||
}
|
||
|
||
const options = {}
|
||
options.pattern = /\{(.*?)\}/g
|
||
options.template = ''
|
||
options.middleware = function () {}
|
||
|
||
function setOptions (_options) {
|
||
options.pattern = _options.pattern || options.pattern
|
||
options.template = _options.template || options.template
|
||
if (typeof _options.middleware === 'function') {
|
||
options.middleware = _options.middleware
|
||
}
|
||
}
|
||
|
||
function compile (data) {
|
||
return options.template.replace(options.pattern, function (match, prop) {
|
||
const value = options.middleware(prop, data[prop], options.template)
|
||
if (typeof value !== 'undefined') {
|
||
return value
|
||
}
|
||
return data[prop] || match
|
||
})
|
||
}
|
||
|
||
'use strict';
|
||
|
||
function fuzzysearch (needle, haystack) {
|
||
var tlen = haystack.length;
|
||
var qlen = needle.length;
|
||
if (qlen > tlen) {
|
||
return false;
|
||
}
|
||
if (qlen === tlen) {
|
||
return needle === haystack;
|
||
}
|
||
outer: for (var i = 0, j = 0; i < qlen; i++) {
|
||
var nch = needle.charCodeAt(i);
|
||
while (j < tlen) {
|
||
if (haystack.charCodeAt(j++) === nch) {
|
||
continue outer;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
var _$fuzzysearch_1 = fuzzysearch;
|
||
|
||
'use strict'
|
||
|
||
/* removed: const _$fuzzysearch_1 = require('fuzzysearch') */;
|
||
|
||
var _$FuzzySearchStrategy_5 = new FuzzySearchStrategy()
|
||
|
||
function FuzzySearchStrategy () {
|
||
this.matches = function (string, crit) {
|
||
return _$fuzzysearch_1(crit.toLowerCase(), string.toLowerCase())
|
||
}
|
||
}
|
||
|
||
'use strict'
|
||
|
||
var _$LiteralSearchStrategy_6 = new LiteralSearchStrategy()
|
||
|
||
function LiteralSearchStrategy () {
|
||
this.matches = function (str, crit) {
|
||
if (!str) return false
|
||
|
||
str = str.trim().toLowerCase()
|
||
crit = crit.trim().toLowerCase()
|
||
|
||
return crit.split(' ').filter(function (word) {
|
||
return str.indexOf(word) >= 0
|
||
}).length === crit.split(' ').length
|
||
}
|
||
}
|
||
|
||
'use strict'
|
||
|
||
var _$Repository_4 = {
|
||
put: put,
|
||
clear: clear,
|
||
search: search,
|
||
setOptions: __setOptions_4
|
||
}
|
||
|
||
/* removed: const _$FuzzySearchStrategy_5 = require('./SearchStrategies/FuzzySearchStrategy') */;
|
||
/* removed: const _$LiteralSearchStrategy_6 = require('./SearchStrategies/LiteralSearchStrategy') */;
|
||
|
||
function NoSort () {
|
||
return 0
|
||
}
|
||
|
||
const data = []
|
||
let opt = {}
|
||
|
||
opt.fuzzy = false
|
||
opt.limit = 10
|
||
opt.searchStrategy = opt.fuzzy ? _$FuzzySearchStrategy_5 : _$LiteralSearchStrategy_6
|
||
opt.sort = NoSort
|
||
opt.exclude = []
|
||
|
||
function put (data) {
|
||
if (isObject(data)) {
|
||
return addObject(data)
|
||
}
|
||
if (isArray(data)) {
|
||
return addArray(data)
|
||
}
|
||
return undefined
|
||
}
|
||
function clear () {
|
||
data.length = 0
|
||
return data
|
||
}
|
||
|
||
function isObject (obj) {
|
||
return Boolean(obj) && Object.prototype.toString.call(obj) === '[object Object]'
|
||
}
|
||
|
||
function isArray (obj) {
|
||
return Boolean(obj) && Object.prototype.toString.call(obj) === '[object Array]'
|
||
}
|
||
|
||
function addObject (_data) {
|
||
data.push(_data)
|
||
return data
|
||
}
|
||
|
||
function addArray (_data) {
|
||
const added = []
|
||
clear()
|
||
for (let i = 0, len = _data.length; i < len; i++) {
|
||
if (isObject(_data[i])) {
|
||
added.push(addObject(_data[i]))
|
||
}
|
||
}
|
||
return added
|
||
}
|
||
|
||
function search (crit) {
|
||
if (!crit) {
|
||
return []
|
||
}
|
||
return findMatches(data, crit, opt.searchStrategy, opt).sort(opt.sort)
|
||
}
|
||
|
||
function __setOptions_4 (_opt) {
|
||
opt = _opt || {}
|
||
|
||
opt.fuzzy = _opt.fuzzy || false
|
||
opt.limit = _opt.limit || 10
|
||
opt.searchStrategy = _opt.fuzzy ? _$FuzzySearchStrategy_5 : _$LiteralSearchStrategy_6
|
||
opt.sort = _opt.sort || NoSort
|
||
opt.exclude = _opt.exclude || []
|
||
}
|
||
|
||
function findMatches (data, crit, strategy, opt) {
|
||
const matches = []
|
||
for (let i = 0; i < data.length && matches.length < opt.limit; i++) {
|
||
const match = findMatchesInObject(data[i], crit, strategy, opt)
|
||
if (match) {
|
||
matches.push(match)
|
||
}
|
||
}
|
||
return matches
|
||
}
|
||
|
||
function findMatchesInObject (obj, crit, strategy, opt) {
|
||
for (const key in obj) {
|
||
if (!isExcluded(obj[key], opt.exclude) && strategy.matches(obj[key], crit)) {
|
||
return obj
|
||
}
|
||
}
|
||
}
|
||
|
||
function isExcluded (term, excludedTerms) {
|
||
for (let i = 0, len = excludedTerms.length; i < len; i++) {
|
||
const excludedTerm = excludedTerms[i]
|
||
if (new RegExp(excludedTerm).test(term)) {
|
||
return true
|
||
}
|
||
}
|
||
return false
|
||
}
|
||
|
||
/* globals ActiveXObject:false */
|
||
|
||
'use strict'
|
||
|
||
var _$JSONLoader_2 = {
|
||
load: load
|
||
}
|
||
|
||
function load (location, callback) {
|
||
const xhr = getXHR()
|
||
xhr.open('GET', location, true)
|
||
xhr.onreadystatechange = createStateChangeListener(xhr, callback)
|
||
xhr.send()
|
||
}
|
||
|
||
function createStateChangeListener (xhr, callback) {
|
||
return function () {
|
||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||
try {
|
||
callback(null, JSON.parse(xhr.responseText))
|
||
} catch (err) {
|
||
callback(err, null)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
function getXHR () {
|
||
return window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP')
|
||
}
|
||
|
||
'use strict'
|
||
|
||
var _$OptionsValidator_3 = function OptionsValidator (params) {
|
||
if (!validateParams(params)) {
|
||
throw new Error('-- OptionsValidator: required options missing')
|
||
}
|
||
|
||
if (!(this instanceof OptionsValidator)) {
|
||
return new OptionsValidator(params)
|
||
}
|
||
|
||
const requiredOptions = params.required
|
||
|
||
this.getRequiredOptions = function () {
|
||
return requiredOptions
|
||
}
|
||
|
||
this.validate = function (parameters) {
|
||
const errors = []
|
||
requiredOptions.forEach(function (requiredOptionName) {
|
||
if (typeof parameters[requiredOptionName] === 'undefined') {
|
||
errors.push(requiredOptionName)
|
||
}
|
||
})
|
||
return errors
|
||
}
|
||
|
||
function validateParams (params) {
|
||
if (!params) {
|
||
return false
|
||
}
|
||
return typeof params.required !== 'undefined' && params.required instanceof Array
|
||
}
|
||
}
|
||
|
||
'use strict'
|
||
|
||
var _$utils_9 = {
|
||
merge: merge,
|
||
isJSON: isJSON
|
||
}
|
||
|
||
function merge (defaultParams, mergeParams) {
|
||
const mergedOptions = {}
|
||
for (const option in defaultParams) {
|
||
mergedOptions[option] = defaultParams[option]
|
||
if (typeof mergeParams[option] !== 'undefined') {
|
||
mergedOptions[option] = mergeParams[option]
|
||
}
|
||
}
|
||
return mergedOptions
|
||
}
|
||
|
||
function isJSON (json) {
|
||
try {
|
||
if (json instanceof Object && JSON.parse(JSON.stringify(json))) {
|
||
return true
|
||
}
|
||
return false
|
||
} catch (err) {
|
||
return false
|
||
}
|
||
}
|
||
|
||
var _$src_8 = {};
|
||
(function (window) {
|
||
'use strict'
|
||
|
||
let options = {
|
||
searchInput: null,
|
||
resultsContainer: null,
|
||
json: [],
|
||
success: Function.prototype,
|
||
searchResultTemplate: '<li><a href="{url}" title="{desc}">{title}</a></li>',
|
||
templateMiddleware: Function.prototype,
|
||
sortMiddleware: function () {
|
||
return 0
|
||
},
|
||
noResultsText: 'No results found',
|
||
limit: 10,
|
||
fuzzy: false,
|
||
debounceTime: null,
|
||
exclude: []
|
||
}
|
||
|
||
let debounceTimerHandle
|
||
const debounce = function (func, delayMillis) {
|
||
if (delayMillis) {
|
||
clearTimeout(debounceTimerHandle)
|
||
debounceTimerHandle = setTimeout(func, delayMillis)
|
||
} else {
|
||
func.call()
|
||
}
|
||
}
|
||
|
||
const requiredOptions = ['searchInput', 'resultsContainer', 'json']
|
||
|
||
/* removed: const _$Templater_7 = require('./Templater') */;
|
||
/* removed: const _$Repository_4 = require('./Repository') */;
|
||
/* removed: const _$JSONLoader_2 = require('./JSONLoader') */;
|
||
const optionsValidator = _$OptionsValidator_3({
|
||
required: requiredOptions
|
||
})
|
||
/* removed: const _$utils_9 = require('./utils') */;
|
||
|
||
window.SimpleJekyllSearch = function (_options) {
|
||
const errors = optionsValidator.validate(_options)
|
||
if (errors.length > 0) {
|
||
throwError('You must specify the following required options: ' + requiredOptions)
|
||
}
|
||
|
||
options = _$utils_9.merge(options, _options)
|
||
|
||
_$Templater_7.setOptions({
|
||
template: options.searchResultTemplate,
|
||
middleware: options.templateMiddleware
|
||
})
|
||
|
||
_$Repository_4.setOptions({
|
||
fuzzy: options.fuzzy,
|
||
limit: options.limit,
|
||
sort: options.sortMiddleware,
|
||
exclude: options.exclude
|
||
})
|
||
|
||
if (_$utils_9.isJSON(options.json)) {
|
||
initWithJSON(options.json)
|
||
} else {
|
||
initWithURL(options.json)
|
||
}
|
||
|
||
const rv = {
|
||
search: search
|
||
}
|
||
|
||
typeof options.success === 'function' && options.success.call(rv)
|
||
return rv
|
||
}
|
||
|
||
function initWithJSON (json) {
|
||
_$Repository_4.put(json)
|
||
registerInput()
|
||
}
|
||
|
||
function initWithURL (url) {
|
||
_$JSONLoader_2.load(url, function (err, json) {
|
||
if (err) {
|
||
throwError('failed to get JSON (' + url + ')')
|
||
}
|
||
initWithJSON(json)
|
||
})
|
||
}
|
||
|
||
function emptyResultsContainer () {
|
||
options.resultsContainer.innerHTML = ''
|
||
}
|
||
|
||
function appendToResultsContainer (text) {
|
||
options.resultsContainer.innerHTML += text
|
||
}
|
||
|
||
function registerInput () {
|
||
options.searchInput.addEventListener('input', function (e) {
|
||
if (isWhitelistedKey(e.which)) {
|
||
emptyResultsContainer()
|
||
debounce(function () { search(e.target.value) }, options.debounceTime)
|
||
}
|
||
})
|
||
}
|
||
|
||
function search (query) {
|
||
if (isValidQuery(query)) {
|
||
emptyResultsContainer()
|
||
render(_$Repository_4.search(query), query)
|
||
}
|
||
}
|
||
|
||
function render (results, query) {
|
||
const len = results.length
|
||
if (len === 0) {
|
||
return appendToResultsContainer(options.noResultsText)
|
||
}
|
||
for (let i = 0; i < len; i++) {
|
||
results[i].query = query
|
||
appendToResultsContainer(_$Templater_7.compile(results[i]))
|
||
}
|
||
}
|
||
|
||
function isValidQuery (query) {
|
||
return query && query.length > 0
|
||
}
|
||
|
||
function isWhitelistedKey (key) {
|
||
return [13, 16, 20, 37, 38, 39, 40, 91].indexOf(key) === -1
|
||
}
|
||
|
||
function throwError (message) {
|
||
throw new Error('SimpleJekyllSearch --- ' + message)
|
||
}
|
||
})(window)
|
||
|
||
}());
|
||
</script>
|
||
|
||
<!-- Configuration -->
|
||
<script>
|
||
SimpleJekyllSearch({
|
||
searchInput: document.getElementById('search-input'),
|
||
resultsContainer: document.getElementById('results-container'),
|
||
json: '/search.json',
|
||
//searchResultTemplate: '<li><a href="https://static.rnmkcy.eu{url}">{date} {title}</a></li>'
|
||
searchResultTemplate: '<li><a href="{url}">{date} {title}</a></li>'
|
||
})
|
||
</script>
|
||
<!-- Fin déclaration champ de recherche --></div><nav class="navigation">
|
||
<ul><li class="navigation__item"><a href="/archive.html">Etiquettes</a></li><li class="navigation__item"><a href="/htmldoc.html">Documents</a></li><li class="navigation__item"><a href="/liens_ttrss.html">Liens</a></li><li class="navigation__item"><a href="/aide-jekyll-text-theme.html">Aide</a></li></ul>
|
||
</nav></div>
|
||
</header>
|
||
|
||
</div><div class="page__content"><div class ="main"><div class="grid grid--reverse">
|
||
<div class="col-main cell cell--auto"><!-- start custom main top snippet --><div id="results-container" class="search-result js-search-result"></div><!-- end custom main top snippet -->
|
||
<article itemscope itemtype="http://schema.org/Article"><div class="article__header"><header><h1 style="color:Tomato;">ngx_lua</h1></header></div><meta itemprop="headline" content="ngx_lua"><div class="article__info clearfix"><ul class="left-col menu"><li>
|
||
<a class="button button--secondary button--pill button--sm" style="color:#00FFFF" href="/archive.html?tag=lua">lua</a>
|
||
</li></ul><ul class="right-col menu"><li>
|
||
<i class="far fa-calendar-alt"></i> <span title="Création" style="color:#FF00FF">25 déc. 2019</span>
|
||
|
||
<span title="Modification" style="color:#00FF7F">23 nov. 2018</span></li></ul></div><meta itemprop="datePublished" content="2018-11-23T00:00:00+01:00">
|
||
<meta itemprop="keywords" content="lua"><div class="js-article-content">
|
||
<div class="layout--article"><!-- start custom article top snippet -->
|
||
<style>
|
||
#myBtn {
|
||
display: none;
|
||
position: fixed;
|
||
bottom: 10px;
|
||
right: 10px;
|
||
z-index: 99;
|
||
font-size: 12px;
|
||
font-weight: bold;
|
||
border: none;
|
||
outline: none;
|
||
background-color: white;
|
||
color: black;
|
||
cursor: pointer;
|
||
padding: 5px;
|
||
border-radius: 4px;
|
||
}
|
||
|
||
#myBtn:hover {
|
||
background-color: #555;
|
||
}
|
||
</style>
|
||
|
||
<button onclick="topFunction()" id="myBtn" title="Haut de page">⇧</button>
|
||
|
||
<script>
|
||
//Get the button
|
||
var mybutton = document.getElementById("myBtn");
|
||
|
||
// When the user scrolls down 20px from the top of the document, show the button
|
||
window.onscroll = function() {scrollFunction()};
|
||
|
||
function scrollFunction() {
|
||
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
|
||
mybutton.style.display = "block";
|
||
} else {
|
||
mybutton.style.display = "none";
|
||
}
|
||
}
|
||
|
||
// When the user clicks on the button, scroll to the top of the document
|
||
function topFunction() {
|
||
document.body.scrollTop = 0;
|
||
document.documentElement.scrollTop = 0;
|
||
}
|
||
</script>
|
||
|
||
|
||
<!-- end custom article top snippet -->
|
||
<div class="article__content" itemprop="articleBody"><details>
|
||
<summary><b>Afficher/cacher Sommaire</b></summary>
|
||
<!-- affichage sommaire -->
|
||
<div class="toc-aside js-toc-root"></div>
|
||
</details><h1 id="name">Name</h1>
|
||
|
||
<p>ngx_lua - Embed the power of Lua into Nginx</p>
|
||
|
||
<p><em>This module is not distributed with the Nginx source.</em> See <a href="#installation">the installation instructions</a>.</p>
|
||
|
||
<h1 id="table-of-contents">Table of Contents</h1>
|
||
|
||
<ul>
|
||
<li><a href="#name">Name</a></li>
|
||
<li><a href="#status">Status</a></li>
|
||
<li><a href="#version">Version</a></li>
|
||
<li><a href="#synopsis">Synopsis</a></li>
|
||
<li><a href="#description">Description</a></li>
|
||
<li><a href="#typical-uses">Typical Uses</a></li>
|
||
<li><a href="#nginx-compatibility">Nginx Compatibility</a></li>
|
||
<li><a href="#installation">Installation</a>
|
||
<ul>
|
||
<li><a href="#c-macro-configurations">C Macro Configurations</a></li>
|
||
<li><a href="#installation-on-ubuntu-1110">Installation on Ubuntu 11.10</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a href="#community">Community</a>
|
||
<ul>
|
||
<li><a href="#english-mailing-list">English Mailing List</a></li>
|
||
<li><a href="#chinese-mailing-list">Chinese Mailing List</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a href="#code-repository">Code Repository</a></li>
|
||
<li><a href="#bugs-and-patches">Bugs and Patches</a></li>
|
||
<li><a href="#lualuajit-bytecode-support">Lua/LuaJIT bytecode support</a></li>
|
||
<li><a href="#system-environment-variable-support">System Environment Variable Support</a></li>
|
||
<li><a href="#http-10-support">HTTP 1.0 support</a></li>
|
||
<li><a href="#statically-linking-pure-lua-modules">Statically Linking Pure Lua Modules</a></li>
|
||
<li><a href="#data-sharing-within-an-nginx-worker">Data Sharing within an Nginx Worker</a></li>
|
||
<li><a href="#known-issues">Known Issues</a>
|
||
<ul>
|
||
<li><a href="#tcp-socket-connect-operation-issues">TCP socket connect operation issues</a></li>
|
||
<li><a href="#lua-coroutine-yieldingresuming">Lua Coroutine Yielding/Resuming</a></li>
|
||
<li><a href="#lua-variable-scope">Lua Variable Scope</a></li>
|
||
<li><a href="#locations-configured-by-subrequest-directives-of-other-modules">Locations Configured by Subrequest Directives of Other Modules</a></li>
|
||
<li><a href="#cosockets-not-available-everywhere">Cosockets Not Available Everywhere</a></li>
|
||
<li><a href="#special-escaping-sequences">Special Escaping Sequences</a></li>
|
||
<li><a href="#mixing-with-ssi-not-supported">Mixing with SSI Not Supported</a></li>
|
||
<li><a href="#spdy-mode-not-fully-supported">SPDY Mode Not Fully Supported</a></li>
|
||
<li><a href="#missing-data-on-short-circuited-requests">Missing data on short circuited requests</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a href="#todo">TODO</a></li>
|
||
<li><a href="#changes">Changes</a></li>
|
||
<li><a href="#test-suite">Test Suite</a></li>
|
||
<li><a href="#copyright-and-license">Copyright and License</a></li>
|
||
<li><a href="#see-also">See Also</a></li>
|
||
<li><a href="#directives">Directives</a></li>
|
||
<li><a href="#nginx-api-for-lua">Nginx API for Lua</a></li>
|
||
<li><a href="#obsolete-sections">Obsolete Sections</a>
|
||
<ul>
|
||
<li><a href="#special-pcre-sequences">Special PCRE Sequences</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h1 id="status">Status</h1>
|
||
|
||
<p>Production ready.</p>
|
||
|
||
<h1 id="version">Version</h1>
|
||
|
||
<p>This document describes ngx_lua <a href="https://github.com/openresty/lua-nginx-module/tags">v0.9.16</a> released on 22 June 2015.</p>
|
||
|
||
<h1 id="synopsis">Synopsis</h1>
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="c1"># set search paths for pure Lua external libraries (';;' is the default path):</span>
|
||
<span class="k">lua_package_path</span> <span class="s">'/foo/bar/?.lua</span><span class="p">;</span><span class="k">/blah/?.lua</span><span class="p">;</span>;<span class="k">'</span><span class="p">;</span>
|
||
|
||
<span class="c1"># set search paths for Lua external libraries written in C (can also use ';;'):</span>
|
||
<span class="k">lua_package_cpath</span> <span class="s">'/bar/baz/?.so</span><span class="p">;</span><span class="k">/blah/blah/?.so</span><span class="p">;</span>;<span class="k">'</span><span class="p">;</span>
|
||
|
||
<span class="k">server</span> <span class="p">{</span>
|
||
<span class="kn">location</span> <span class="n">/inline_concat</span> <span class="p">{</span>
|
||
<span class="c1"># MIME type determined by default_type:</span>
|
||
<span class="kn">default_type</span> <span class="s">'text/plain'</span><span class="p">;</span>
|
||
|
||
<span class="kn">set</span> <span class="nv">$a</span> <span class="s">"hello"</span><span class="p">;</span>
|
||
<span class="kn">set</span> <span class="nv">$b</span> <span class="s">"world"</span><span class="p">;</span>
|
||
<span class="c1"># inline Lua script</span>
|
||
<span class="kn">set_by_lua</span> <span class="nv">$res</span> <span class="s">"return</span> <span class="s">ngx.arg[1]..ngx.arg[2]"</span> <span class="nv">$a</span> <span class="nv">$b</span><span class="p">;</span>
|
||
<span class="kn">echo</span> <span class="nv">$res</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="kn">location</span> <span class="n">/rel_file_concat</span> <span class="p">{</span>
|
||
<span class="kn">set</span> <span class="nv">$a</span> <span class="s">"foo"</span><span class="p">;</span>
|
||
<span class="kn">set</span> <span class="nv">$b</span> <span class="s">"bar"</span><span class="p">;</span>
|
||
<span class="c1"># script path relative to nginx prefix</span>
|
||
<span class="c1"># $ngx_prefix/conf/concat.lua contents:</span>
|
||
<span class="c1">#</span>
|
||
<span class="c1"># return ngx.arg[1]..ngx.arg[2]</span>
|
||
<span class="c1">#</span>
|
||
<span class="kn">set_by_lua_file</span> <span class="nv">$res</span> <span class="nc">conf/concat</span><span class="s">.lua</span> <span class="nv">$a</span> <span class="nv">$b</span><span class="p">;</span>
|
||
<span class="kn">echo</span> <span class="nv">$res</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="kn">location</span> <span class="n">/abs_file_concat</span> <span class="p">{</span>
|
||
<span class="kn">set</span> <span class="nv">$a</span> <span class="s">"fee"</span><span class="p">;</span>
|
||
<span class="kn">set</span> <span class="nv">$b</span> <span class="s">"baz"</span><span class="p">;</span>
|
||
<span class="c1"># absolute script path not modified</span>
|
||
<span class="kn">set_by_lua_file</span> <span class="nv">$res</span> <span class="n">/usr/nginx/conf/concat.lua</span> <span class="nv">$a</span> <span class="nv">$b</span><span class="p">;</span>
|
||
<span class="kn">echo</span> <span class="nv">$res</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="kn">location</span> <span class="n">/lua_content</span> <span class="p">{</span>
|
||
<span class="c1"># MIME type determined by default_type:</span>
|
||
<span class="kn">default_type</span> <span class="s">'text/plain'</span><span class="p">;</span>
|
||
|
||
<span class="kn">content_by_lua</span> <span class="s">"ngx.say('Hello,world!')"</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="kn">location</span> <span class="n">/nginx_var</span> <span class="p">{</span>
|
||
<span class="c1"># MIME type determined by default_type:</span>
|
||
<span class="kn">default_type</span> <span class="s">'text/plain'</span><span class="p">;</span>
|
||
|
||
<span class="c1"># try access /nginx_var?a=hello,world</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">"ngx.print(ngx.var['arg_a'],</span> <span class="s">'</span><span class="err">\\</span><span class="s">n')"</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="kn">location</span> <span class="n">/request_body</span> <span class="p">{</span>
|
||
<span class="c1"># force reading request body (default off)</span>
|
||
<span class="kn">lua_need_request_body</span> <span class="no">on</span><span class="p">;</span>
|
||
<span class="kn">client_max_body_size</span> <span class="mi">50k</span><span class="p">;</span>
|
||
<span class="kn">client_body_buffer_size</span> <span class="mi">50k</span><span class="p">;</span>
|
||
|
||
<span class="kn">content_by_lua</span> <span class="s">'ngx.print(ngx.var.request_body)'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="c1"># transparent non-blocking I/O in Lua via subrequests</span>
|
||
<span class="kn">location</span> <span class="n">/lua</span> <span class="p">{</span>
|
||
<span class="c1"># MIME type determined by default_type:</span>
|
||
<span class="kn">default_type</span> <span class="s">'text/plain'</span><span class="p">;</span>
|
||
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">res</span> <span class="p">=</span> <span class="s">ngx.location.capture("/some_other_location")</span>
|
||
<span class="s">if</span> <span class="s">res.status</span> <span class="p">==</span> <span class="mi">200</span> <span class="s">then</span>
|
||
<span class="s">ngx.print(res.body)</span>
|
||
<span class="s">end'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="c1"># GET /recur?num=5</span>
|
||
<span class="kn">location</span> <span class="n">/recur</span> <span class="p">{</span>
|
||
<span class="c1"># MIME type determined by default_type:</span>
|
||
<span class="kn">default_type</span> <span class="s">'text/plain'</span><span class="p">;</span>
|
||
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">num</span> <span class="p">=</span> <span class="s">tonumber(ngx.var.arg_num)</span> <span class="s">or</span> <span class="mi">0</span>
|
||
|
||
<span class="s">if</span> <span class="s">num</span> <span class="s">></span> <span class="mi">50</span> <span class="s">then</span>
|
||
<span class="s">ngx.say("num</span> <span class="s">too</span> <span class="s">big")</span>
|
||
<span class="s">return</span>
|
||
<span class="s">end</span>
|
||
|
||
<span class="s">ngx.say("num</span> <span class="s">is:</span> <span class="s">",</span> <span class="s">num)</span>
|
||
|
||
<span class="s">if</span> <span class="s">num</span> <span class="s">></span> <span class="mi">0</span> <span class="s">then</span>
|
||
<span class="s">res</span> <span class="p">=</span> <span class="s">ngx.location.capture("/recur?num="</span> <span class="s">..</span> <span class="s">tostring(num</span> <span class="s">-</span> <span class="mi">1</span><span class="s">))</span>
|
||
<span class="s">ngx.print("status=",</span> <span class="s">res.status,</span> <span class="s">"</span> <span class="s">")</span>
|
||
<span class="s">ngx.print("body=",</span> <span class="s">res.body)</span>
|
||
<span class="s">else</span>
|
||
<span class="s">ngx.say("end")</span>
|
||
<span class="s">end</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="kn">location</span> <span class="n">/foo</span> <span class="p">{</span>
|
||
<span class="kn">rewrite_by_lua</span> <span class="s">'</span>
|
||
<span class="s">res</span> <span class="p">=</span> <span class="s">ngx.location.capture("/memc",</span>
|
||
<span class="p">{</span> <span class="kn">args</span> <span class="p">=</span> <span class="p">{</span> <span class="kn">cmd</span> <span class="p">=</span> <span class="s">"incr",</span> <span class="s">key</span> <span class="p">=</span> <span class="s">ngx.var.uri</span> <span class="err">}</span> <span class="err">}</span>
|
||
<span class="s">)</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
|
||
<span class="kn">proxy_pass</span> <span class="s">http://blah.blah.com</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="kn">location</span> <span class="n">/blah</span> <span class="p">{</span>
|
||
<span class="kn">access_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">res</span> <span class="p">=</span> <span class="s">ngx.location.capture("/auth")</span>
|
||
|
||
<span class="s">if</span> <span class="s">res.status</span> <span class="p">==</span> <span class="s">ngx.HTTP_OK</span> <span class="s">then</span>
|
||
<span class="s">return</span>
|
||
<span class="s">end</span>
|
||
|
||
<span class="s">if</span> <span class="s">res.status</span> <span class="p">==</span> <span class="s">ngx.HTTP_FORBIDDEN</span> <span class="s">then</span>
|
||
<span class="s">ngx.exit(res.status)</span>
|
||
<span class="s">end</span>
|
||
|
||
<span class="s">ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
|
||
<span class="c1"># proxy_pass/fastcgi_pass/postgres_pass/...</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="kn">location</span> <span class="n">/mixed</span> <span class="p">{</span>
|
||
<span class="kn">rewrite_by_lua_file</span> <span class="n">/path/to/rewrite.lua</span><span class="p">;</span>
|
||
<span class="kn">access_by_lua_file</span> <span class="n">/path/to/access.lua</span><span class="p">;</span>
|
||
<span class="kn">content_by_lua_file</span> <span class="n">/path/to/content.lua</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="c1"># use nginx var in code path</span>
|
||
<span class="c1"># WARNING: contents in nginx var must be carefully filtered,</span>
|
||
<span class="c1"># otherwise there'll be great security risk!</span>
|
||
<span class="kn">location</span> <span class="p">~</span> <span class="sr">^/app/([-_a-zA-Z0-9/]+)</span> <span class="p">{</span>
|
||
<span class="kn">set</span> <span class="nv">$path</span> <span class="nv">$1</span><span class="p">;</span>
|
||
<span class="kn">content_by_lua_file</span> <span class="n">/path/to/lua/app/root/</span><span class="nv">$path</span><span class="s">.lua</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="kn">location</span> <span class="n">/</span> <span class="p">{</span>
|
||
<span class="kn">lua_need_request_body</span> <span class="no">on</span><span class="p">;</span>
|
||
|
||
<span class="kn">client_max_body_size</span> <span class="mi">100k</span><span class="p">;</span>
|
||
<span class="kn">client_body_buffer_size</span> <span class="mi">100k</span><span class="p">;</span>
|
||
|
||
<span class="kn">access_by_lua</span> <span class="s">'</span>
|
||
<span class="s">--</span> <span class="s">check</span> <span class="s">the</span> <span class="s">client</span> <span class="s">IP</span> <span class="s">address</span> <span class="s">is</span> <span class="s">in</span> <span class="s">our</span> <span class="s">black</span> <span class="s">list</span>
|
||
<span class="s">if</span> <span class="s">ngx.var.remote_addr</span> <span class="p">==</span> <span class="s">"132.5.72.3"</span> <span class="s">then</span>
|
||
<span class="s">ngx.exit(ngx.HTTP_FORBIDDEN)</span>
|
||
<span class="s">end</span>
|
||
|
||
<span class="s">--</span> <span class="s">check</span> <span class="s">if</span> <span class="s">the</span> <span class="s">request</span> <span class="s">body</span> <span class="s">contains</span> <span class="s">bad</span> <span class="s">words</span>
|
||
<span class="s">if</span> <span class="s">ngx.var.request_body</span> <span class="s">and</span>
|
||
<span class="s">string.match(ngx.var.request_body,</span> <span class="s">"fsck")</span>
|
||
<span class="s">then</span>
|
||
<span class="s">return</span> <span class="s">ngx.redirect("/terms_of_use.html")</span>
|
||
<span class="s">end</span>
|
||
|
||
<span class="s">--</span> <span class="s">tests</span> <span class="s">passed</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
|
||
<span class="c1"># proxy_pass/fastcgi_pass/etc settings</span>
|
||
<span class="p">}</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="description">Description</h1>
|
||
|
||
<p>This module embeds Lua, via the standard Lua 5.1 interpreter or <a href="http://luajit.org/luajit.html">LuaJIT 2.0/2.1</a>, into Nginx and by leveraging Nginx’s subrequests, allows the integration of the powerful Lua threads (Lua coroutines) into the Nginx event model.</p>
|
||
|
||
<p>Unlike <a href="https://httpd.apache.org/docs/trunk/mod/mod_lua.html">Apache’s mod_lua</a> and <a href="http://redmine.lighttpd.net/wiki/1/Docs:ModMagnet">Lighttpd’s mod_magnet</a>, Lua code executed using this module can be <em>100% non-blocking</em> on network traffic as long as the <a href="#nginx-api-for-lua">Nginx API for Lua</a> provided by this module is used to handle
|
||
requests to upstream services such as MySQL, PostgreSQL, Memcached, Redis, or upstream HTTP web services.</p>
|
||
|
||
<p>At least the following Lua libraries and Nginx modules can be used with this ngx_lua module:</p>
|
||
|
||
<ul>
|
||
<li><a href="https://github.com/openresty/lua-resty-memcached">lua-resty-memcached</a></li>
|
||
<li><a href="https://github.com/openresty/lua-resty-mysql">lua-resty-mysql</a></li>
|
||
<li><a href="https://github.com/openresty/lua-resty-redis">lua-resty-redis</a></li>
|
||
<li><a href="https://github.com/openresty/lua-resty-dns">lua-resty-dns</a></li>
|
||
<li><a href="https://github.com/openresty/lua-resty-upload">lua-resty-upload</a></li>
|
||
<li><a href="https://github.com/openresty/lua-resty-websocket">lua-resty-websocket</a></li>
|
||
<li><a href="https://github.com/openresty/lua-resty-lock">lua-resty-lock</a></li>
|
||
<li><a href="https://github.com/cloudflare/lua-resty-logger-socket">lua-resty-logger-socket</a></li>
|
||
<li><a href="https://github.com/openresty/lua-resty-lrucache">lua-resty-lrucache</a></li>
|
||
<li><a href="https://github.com/openresty/lua-resty-string">lua-resty-string</a></li>
|
||
<li><a href="http://github.com/openresty/memc-nginx-module">ngx_memc</a></li>
|
||
<li><a href="https://github.com/FRiCKLE/ngx_postgres">ngx_postgres</a></li>
|
||
<li><a href="http://github.com/openresty/redis2-nginx-module">ngx_redis2</a></li>
|
||
<li><a href="http://wiki.nginx.org/HttpRedisModule">ngx_redis</a></li>
|
||
<li><a href="http://nginx.org/en/docs/http/ngx_http_proxy_module.html">ngx_proxy</a></li>
|
||
<li><a href="http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html">ngx_fastcgi</a></li>
|
||
</ul>
|
||
|
||
<p>Almost all the Nginx modules can be used with this ngx_lua module by means of <a href="#ngxlocationcapture">ngx.location.capture</a> or <a href="#ngxlocationcapture_multi">ngx.location.capture_multi</a> but it is recommended to use those <code class="language-plaintext highlighter-rouge">lua-resty-*</code> libraries instead of creating subrequests to access the Nginx upstream modules because the former is usually much more flexible and memory-efficient.</p>
|
||
|
||
<p>The Lua interpreter or LuaJIT instance is shared across all the requests in a single nginx worker process but request contexts are segregated using lightweight Lua coroutines.</p>
|
||
|
||
<p>Loaded Lua modules persist in the nginx worker process level resulting in a small memory footprint in Lua even when under heavy loads.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="typical-uses">Typical Uses</h1>
|
||
|
||
<p>Just to name a few:</p>
|
||
|
||
<ul>
|
||
<li>Mashup’ing and processing outputs of various nginx upstream outputs (proxy, drizzle, postgres, redis, memcached, and etc) in Lua,</li>
|
||
<li>doing arbitrarily complex access control and security checks in Lua before requests actually reach the upstream backends,</li>
|
||
<li>manipulating response headers in an arbitrary way (by Lua)</li>
|
||
<li>fetching backend information from external storage backends (like redis, memcached, mysql, postgresql) and use that information to choose which upstream backend to access on-the-fly,</li>
|
||
<li>coding up arbitrarily complex web applications in a content handler using synchronous but still non-blocking access to the database backends and other storage,</li>
|
||
<li>doing very complex URL dispatch in Lua at rewrite phase,</li>
|
||
<li>using Lua to implement advanced caching mechanism for Nginx’s subrequests and arbitrary locations.</li>
|
||
</ul>
|
||
|
||
<p>The possibilities are unlimited as the module allows bringing together various elements within Nginx as well as exposing the power of the Lua language to the user. The module provides the full flexibility of scripting while offering performance levels comparable with native C language programs both in terms of CPU time as well as memory footprint. This is particularly the case when LuaJIT 2.x is enabled.</p>
|
||
|
||
<p>Other scripting language implementations typically struggle to match this performance level.</p>
|
||
|
||
<p>The Lua state (Lua VM instance) is shared across all the requests handled by a single nginx worker process to minimize memory use.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="nginx-compatibility">Nginx Compatibility</h1>
|
||
<p>The latest module is compatible with the following versions of Nginx:</p>
|
||
|
||
<ul>
|
||
<li>1.7.x (last tested: 1.7.10)</li>
|
||
<li>1.6.x</li>
|
||
<li>1.5.x (last tested: 1.5.12)</li>
|
||
<li>1.4.x (last tested: 1.4.4)</li>
|
||
<li>1.3.x (last tested: 1.3.11)</li>
|
||
<li>1.2.x (last tested: 1.2.9)</li>
|
||
<li>1.1.x (last tested: 1.1.5)</li>
|
||
<li>1.0.x (last tested: 1.0.15)</li>
|
||
<li>0.9.x (last tested: 0.9.4)</li>
|
||
<li>0.8.x >= 0.8.54 (last tested: 0.8.54)</li>
|
||
</ul>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="installation">Installation</h1>
|
||
|
||
<p>It is highly recommended to use the <a href="http://openresty.org">ngx_openresty bundle</a> that bundles Nginx, ngx_lua, LuaJIT 2.0/2.1 (or the optional standard Lua 5.1 interpreter), as well as a package of powerful companion Nginx modules. The basic installation step is a simple command: <code class="language-plaintext highlighter-rouge">./configure --with-luajit && make && make install</code>.</p>
|
||
|
||
<p>Alternatively, ngx_lua can be manually compiled into Nginx:</p>
|
||
|
||
<ol>
|
||
<li>Install LuaJIT 2.0 or 2.1 (recommended) or Lua 5.1 (Lua 5.2 is <em>not</em> supported yet). LuaJIT can be downloaded from the <a href="http://luajit.org/download.html">the LuaJIT project website</a> and Lua 5.1, from the <a href="http://www.lua.org/">Lua project website</a>. Some distribution package managers also distribute LuajIT and/or Lua.</li>
|
||
<li>Download the latest version of the ngx_devel_kit (NDK) module <a href="https://github.com/simpl/ngx_devel_kit/tags">HERE</a>.</li>
|
||
<li>Download the latest version of ngx_lua <a href="https://github.com/openresty/lua-nginx-module/tags">HERE</a>.</li>
|
||
<li>Download the latest version of Nginx <a href="http://nginx.org/">HERE</a> (See <a href="#nginx-compatibility">Nginx Compatibility</a>)</li>
|
||
</ol>
|
||
|
||
<p>Build the source with this module:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
wget <span class="s1">'http://nginx.org/download/nginx-1.7.10.tar.gz'</span>
|
||
<span class="nb">tar</span> <span class="nt">-xzvf</span> nginx-1.7.10.tar.gz
|
||
<span class="nb">cd </span>nginx-1.7.10/
|
||
|
||
<span class="c"># tell nginx's build system where to find LuaJIT 2.0:</span>
|
||
<span class="nb">export </span><span class="nv">LUAJIT_LIB</span><span class="o">=</span>/path/to/luajit/lib
|
||
<span class="nb">export </span><span class="nv">LUAJIT_INC</span><span class="o">=</span>/path/to/luajit/include/luajit-2.0
|
||
|
||
<span class="c"># tell nginx's build system where to find LuaJIT 2.1:</span>
|
||
<span class="nb">export </span><span class="nv">LUAJIT_LIB</span><span class="o">=</span>/path/to/luajit/lib
|
||
<span class="nb">export </span><span class="nv">LUAJIT_INC</span><span class="o">=</span>/path/to/luajit/include/luajit-2.1
|
||
|
||
<span class="c"># or tell where to find Lua if using Lua instead:</span>
|
||
<span class="c">#export LUA_LIB=/path/to/lua/lib</span>
|
||
<span class="c">#export LUA_INC=/path/to/lua/include</span>
|
||
|
||
<span class="c"># Here we assume Nginx is to be installed under /opt/nginx/.</span>
|
||
./configure <span class="nt">--prefix</span><span class="o">=</span>/opt/nginx <span class="se">\</span>
|
||
<span class="nt">--with-ld-opt</span><span class="o">=</span><span class="s2">"-Wl,-rpath,/path/to/luajit-or-lua/lib"</span> <span class="se">\</span>
|
||
<span class="nt">--add-module</span><span class="o">=</span>/path/to/ngx_devel_kit <span class="se">\</span>
|
||
<span class="nt">--add-module</span><span class="o">=</span>/path/to/lua-nginx-module
|
||
|
||
make <span class="nt">-j2</span>
|
||
make <span class="nb">install</span>
|
||
</code></pre></div></div>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h2 id="c-macro-configurations">C Macro Configurations</h2>
|
||
|
||
<p>While building this module either via OpenResty or with the NGINX core, you can define the following C macros via the C compiler options:</p>
|
||
|
||
<ul>
|
||
<li><code class="language-plaintext highlighter-rouge">NGX_LUA_USE_ASSERT</code>
|
||
When defined, will enable assertions in the ngx_lua C code base. Recommended for debugging or testing builds. It can introduce some (small) runtime overhead when enabled. This macro was first introduced in the <code class="language-plaintext highlighter-rouge">v0.9.10</code> release.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">NGX_LUA_ABORT_AT_PANIC</code>
|
||
When the Lua/LuaJIT VM panics, ngx_lua will instruct the current nginx worker process to quit gracefully by default. By specifying this C macro, ngx_lua will abort the current nginx worker process (which usually result in a core dump file) immediately. This option is useful for debugging VM panics. This option was first introduced in the <code class="language-plaintext highlighter-rouge">v0.9.8</code> release.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">NGX_LUA_NO_FFI_API</code>
|
||
Excludes pure C API functions for FFI-based Lua API for NGINX (as required by <a href="https://github.com/openresty/lua-resty-core#readme">lua-resty-core</a>, for example). Enabling this macro can make the resulting binary code size smaller.</li>
|
||
</ul>
|
||
|
||
<p>To enable one or more of these macros, just pass extra C compiler options to the <code class="language-plaintext highlighter-rouge">./configure</code> script of either NGINX or OpenResty. For instance,</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>./configure --with-cc-opt="-DNGX_LUA_USE_ASSERT -DNGX_LUA_ABORT_AT_PANIC"
|
||
</code></pre></div></div>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h2 id="installation-on-ubuntu-1110">Installation on Ubuntu 11.10</h2>
|
||
|
||
<p>Note that it is recommended to use LuaJIT 2.0 or LuaJIT 2.1 instead of the standard Lua 5.1 interpreter wherever possible.</p>
|
||
|
||
<p>If the standard Lua 5.1 interpreter is required however, run the following command to install it from the Ubuntu repository:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
apt-get <span class="nb">install</span> <span class="nt">-y</span> lua5.1 liblua5.1-0 liblua5.1-0-dev
|
||
</code></pre></div></div>
|
||
|
||
<p>Everything should be installed correctly, except for one small tweak.</p>
|
||
|
||
<p>Library name <code class="language-plaintext highlighter-rouge">liblua.so</code> has been changed in liblua5.1 package, it only comes with <code class="language-plaintext highlighter-rouge">liblua5.1.so</code>, which needs to be symlinked to <code class="language-plaintext highlighter-rouge">/usr/lib</code> so it could be found during the configuration process.</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="nb">ln</span> <span class="nt">-s</span> /usr/lib/x86_64-linux-gnu/liblua5.1.so /usr/lib/liblua.so
|
||
</code></pre></div></div>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="community">Community</h1>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h2 id="english-mailing-list">English Mailing List</h2>
|
||
|
||
<p>The <a href="https://groups.google.com/group/openresty-en">openresty-en</a> mailing list is for English speakers.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h2 id="chinese-mailing-list">Chinese Mailing List</h2>
|
||
|
||
<p>The <a href="https://groups.google.com/group/openresty">openresty</a> mailing list is for Chinese speakers.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="code-repository">Code Repository</h1>
|
||
|
||
<p>The code repository of this project is hosted on github at <a href="https://github.com/openresty/lua-nginx-module">openresty/lua-nginx-module</a>.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="bugs-and-patches">Bugs and Patches</h1>
|
||
|
||
<p>Please submit bug reports, wishlists, or patches by</p>
|
||
|
||
<ol>
|
||
<li>creating a ticket on the <a href="https://github.com/openresty/lua-nginx-module/issues">GitHub Issue Tracker</a>,</li>
|
||
<li>or posting to the <a href="#community">OpenResty community</a>.</li>
|
||
</ol>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="lualuajit-bytecode-support">Lua/LuaJIT bytecode support</h1>
|
||
|
||
<p>As from the <code class="language-plaintext highlighter-rouge">v0.5.0rc32</code> release, all <code class="language-plaintext highlighter-rouge">*_by_lua_file</code> configure directives (such as <a href="#content_by_lua_file">content_by_lua_file</a>) support loading Lua 5.1 and LuaJIT 2.0/2.1 raw bytecode files directly.</p>
|
||
|
||
<p>Please note that the bytecode format used by LuaJIT 2.0/2.1 is not compatible with that used by the standard Lua 5.1 interpreter. So if using LuaJIT 2.0/2.1 with ngx_lua, LuaJIT compatible bytecode files must be generated as shown:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
/path/to/luajit/bin/luajit <span class="nt">-b</span> /path/to/input_file.lua /path/to/output_file.luac
|
||
</code></pre></div></div>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">-bg</code> option can be used to include debug information in the LuaJIT bytecode file:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
/path/to/luajit/bin/luajit <span class="nt">-bg</span> /path/to/input_file.lua /path/to/output_file.luac
|
||
</code></pre></div></div>
|
||
|
||
<p>Please refer to the official LuaJIT documentation on the <code class="language-plaintext highlighter-rouge">-b</code> option for more details:</p>
|
||
|
||
<p><a href="http://luajit.org/running.html#opt_b">http://luajit.org/running.html#opt_b</a></p>
|
||
|
||
<p>Also, the bytecode files generated by LuaJIT 2.1 is <em>not</em> compatible with LuaJIT 2.0, and vice versa. The support for LuaJIT 2.1 bytecode was first added in ngx_lua v0.9.3.</p>
|
||
|
||
<p>Similarly, if using the standard Lua 5.1 interpreter with ngx_lua, Lua compatible bytecode files must be generated using the <code class="language-plaintext highlighter-rouge">luac</code> commandline utility as shown:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
luac <span class="nt">-o</span> /path/to/output_file.luac /path/to/input_file.lua
|
||
</code></pre></div></div>
|
||
|
||
<p>Unlike as with LuaJIT, debug information is included in standard Lua 5.1 bytecode files by default. This can be striped out by specifying the <code class="language-plaintext highlighter-rouge">-s</code> option as shown:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
luac <span class="nt">-s</span> <span class="nt">-o</span> /path/to/output_file.luac /path/to/input_file.lua
|
||
</code></pre></div></div>
|
||
|
||
<p>Attempts to load standard Lua 5.1 bytecode files into ngx_lua instances linked to LuaJIT 2.0/2.1 or vice versa, will result in an error message, such as that below, being logged into the Nginx <code class="language-plaintext highlighter-rouge">error.log</code> file:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>[error] 13909#0: *1 failed to load Lua inlined code: bad byte-code header in /path/to/test_file.luac
|
||
</code></pre></div></div>
|
||
|
||
<p>Loading bytecode files via the Lua primitives like <code class="language-plaintext highlighter-rouge">require</code> and <code class="language-plaintext highlighter-rouge">dofile</code> should always work as expected.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="system-environment-variable-support">System Environment Variable Support</h1>
|
||
|
||
<p>If you want to access the system environment variable, say, <code class="language-plaintext highlighter-rouge">foo</code>, in Lua via the standard Lua API <a href="http://www.lua.org/manual/5.1/manual.html#pdf-os.getenv">os.getenv</a>, then you should also list this environment variable name in your <code class="language-plaintext highlighter-rouge">nginx.conf</code> file via the <a href="http://nginx.org/en/docs/ngx_core_module.html#env">env directive</a>. For example,</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">env</span> <span class="s">foo</span><span class="p">;</span>
|
||
</code></pre></div></div>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="http-10-support">HTTP 1.0 support</h1>
|
||
|
||
<p>The HTTP 1.0 protocol does not support chunked output and requires an explicit <code class="language-plaintext highlighter-rouge">Content-Length</code> header when the response body is not empty in order to support the HTTP 1.0 keep-alive.
|
||
So when a HTTP 1.0 request is made and the <a href="#lua_http10_buffering">lua_http10_buffering</a> directive is turned <code class="language-plaintext highlighter-rouge">on</code>, ngx_lua will buffer the
|
||
output of <a href="#ngxsay">ngx.say</a> and <a href="#ngxprint">ngx.print</a> calls and also postpone sending response headers until all the response body output is received.
|
||
At that time ngx_lua can calculate the total length of the body and construct a proper <code class="language-plaintext highlighter-rouge">Content-Length</code> header to return to the HTTP 1.0 client.
|
||
If the <code class="language-plaintext highlighter-rouge">Content-Length</code> response header is set in the running Lua code, however, this buffering will be disabled even if the <a href="#lua_http10_buffering">lua_http10_buffering</a> directive is turned <code class="language-plaintext highlighter-rouge">on</code>.</p>
|
||
|
||
<p>For large streaming output responses, it is important to disable the <a href="#lua_http10_buffering">lua_http10_buffering</a> directive to minimise memory usage.</p>
|
||
|
||
<p>Note that common HTTP benchmark tools such as <code class="language-plaintext highlighter-rouge">ab</code> and <code class="language-plaintext highlighter-rouge">http_load</code> issue HTTP 1.0 requests by default.
|
||
To force <code class="language-plaintext highlighter-rouge">curl</code> to send HTTP 1.0 requests, use the <code class="language-plaintext highlighter-rouge">-0</code> option.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="statically-linking-pure-lua-modules">Statically Linking Pure Lua Modules</h1>
|
||
|
||
<p>When LuaJIT 2.x is used, it is possible to statically link the bytecode of pure Lua modules into the Nginx executable.</p>
|
||
|
||
<p>Basically you use the <code class="language-plaintext highlighter-rouge">luajit</code> executable to compile <code class="language-plaintext highlighter-rouge">.lua</code> Lua module files to <code class="language-plaintext highlighter-rouge">.o</code> object files containing the exported bytecode data, and then link the <code class="language-plaintext highlighter-rouge">.o</code> files directly in your Nginx build.</p>
|
||
|
||
<p>Below is a trivial example to demonstrate this. Consider that we have the following <code class="language-plaintext highlighter-rouge">.lua</code> file named <code class="language-plaintext highlighter-rouge">foo.lua</code>:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="c1">-- foo.lua</span>
|
||
<span class="kd">local</span> <span class="n">_M</span> <span class="o">=</span> <span class="p">{}</span>
|
||
|
||
<span class="k">function</span> <span class="nc">_M</span><span class="p">.</span><span class="nf">go</span><span class="p">()</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="s2">"Hello from foo"</span><span class="p">)</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="k">return</span> <span class="n">_M</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>And then we compile this <code class="language-plaintext highlighter-rouge">.lua</code> file to <code class="language-plaintext highlighter-rouge">foo.o</code> file:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/path/to/luajit/bin/luajit -bg foo.lua foo.o
|
||
</code></pre></div></div>
|
||
|
||
<p>What matters here is the name of the <code class="language-plaintext highlighter-rouge">.lua</code> file, which determines how you use this module later on the Lua land. The file name <code class="language-plaintext highlighter-rouge">foo.o</code> does not matter at all except the <code class="language-plaintext highlighter-rouge">.o</code> file extension (which tells <code class="language-plaintext highlighter-rouge">luajit</code> what output format is used). If you want to strip the Lua debug information from the resulting bytecode, you can just specify the <code class="language-plaintext highlighter-rouge">-b</code> option above instead of <code class="language-plaintext highlighter-rouge">-bg</code>.</p>
|
||
|
||
<p>Then when building Nginx or OpenResty, pass the <code class="language-plaintext highlighter-rouge">--with-ld-opt="foo.o"</code> option to the <code class="language-plaintext highlighter-rouge">./configure</code> script:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
./configure <span class="nt">--with-ld-opt</span><span class="o">=</span><span class="s2">"/path/to/foo.o"</span> ...
|
||
</code></pre></div></div>
|
||
|
||
<p>Finally, you can just do the following in any Lua code run by ngx_lua:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">foo</span> <span class="o">=</span> <span class="nb">require</span> <span class="s2">"foo"</span>
|
||
<span class="n">foo</span><span class="p">.</span><span class="n">go</span><span class="p">()</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>And this piece of code no longer depends on the external <code class="language-plaintext highlighter-rouge">foo.lua</code> file any more because it has already been compiled into the <code class="language-plaintext highlighter-rouge">nginx</code> executable.</p>
|
||
|
||
<p>If you want to use dot in the Lua module name when calling <code class="language-plaintext highlighter-rouge">require</code>, as in</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">foo</span> <span class="o">=</span> <span class="nb">require</span> <span class="s2">"resty.foo"</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>then you need to rename the <code class="language-plaintext highlighter-rouge">foo.lua</code> file to <code class="language-plaintext highlighter-rouge">resty_foo.lua</code> before compiling it down to a <code class="language-plaintext highlighter-rouge">.o</code> file with the <code class="language-plaintext highlighter-rouge">luajit</code> command-line utility.</p>
|
||
|
||
<p>It is important to use exactly the same version of LuaJIT when compiling <code class="language-plaintext highlighter-rouge">.lua</code> files to <code class="language-plaintext highlighter-rouge">.o</code> files as building nginx + ngx_lua. This is because the LuaJIT bytecode format may be incompatible between different LuaJIT versions. When the bytecode format is incompatible, you will see a Lua runtime error saying that the Lua module is not found.</p>
|
||
|
||
<p>When you have multiple <code class="language-plaintext highlighter-rouge">.lua</code> files to compile and link, then just specify their <code class="language-plaintext highlighter-rouge">.o</code> files at the same time in the value of the <code class="language-plaintext highlighter-rouge">--with-ld-opt</code> option. For instance,</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
./configure <span class="nt">--with-ld-opt</span><span class="o">=</span><span class="s2">"/path/to/foo.o /path/to/bar.o"</span> ...
|
||
</code></pre></div></div>
|
||
|
||
<p>If you have just too many <code class="language-plaintext highlighter-rouge">.o</code> files, then it might not be feasible to name them all in a single command. In this case, you can build a static library (or archive) for your <code class="language-plaintext highlighter-rouge">.o</code> files, as in</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
ar rcus libmyluafiles.a <span class="k">*</span>.o
|
||
</code></pre></div></div>
|
||
|
||
<p>then you can link the <code class="language-plaintext highlighter-rouge">myluafiles</code> archive as a whole to your nginx executable:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
./configure <span class="se">\</span>
|
||
<span class="nt">--with-ld-opt</span><span class="o">=</span><span class="s2">"-L/path/to/lib -Wl,--whole-archive -lmyluafiles -Wl,--no-whole-archive"</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>where <code class="language-plaintext highlighter-rouge">/path/to/lib</code> is the path of the directory containing the <code class="language-plaintext highlighter-rouge">libmyluafiles.a</code> file. It should be noted that the linker option <code class="language-plaintext highlighter-rouge">--whole-archive</code> is required here because otherwise our archive will be skipped because no symbols in our archive are mentioned in the main parts of the nginx executable.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="data-sharing-within-an-nginx-worker">Data Sharing within an Nginx Worker</h1>
|
||
|
||
<p>To globally share data among all the requests handled by the same nginx worker process, encapsulate the shared data into a Lua module, use the Lua <code class="language-plaintext highlighter-rouge">require</code> builtin to import the module, and then manipulate the shared data in Lua. This works because required Lua modules are loaded only once and all coroutines will share the same copy of the module (both its code and data). Note however that Lua global variables (note, not module-level variables) WILL NOT persist between requests because of the one-coroutine-per-request isolation design.</p>
|
||
|
||
<p>Here is a complete small example:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="c1">-- mydata.lua</span>
|
||
<span class="kd">local</span> <span class="n">_M</span> <span class="o">=</span> <span class="p">{}</span>
|
||
|
||
<span class="kd">local</span> <span class="n">data</span> <span class="o">=</span> <span class="p">{</span>
|
||
<span class="n">dog</span> <span class="o">=</span> <span class="mi">3</span><span class="p">,</span>
|
||
<span class="n">cat</span> <span class="o">=</span> <span class="mi">4</span><span class="p">,</span>
|
||
<span class="n">pig</span> <span class="o">=</span> <span class="mi">5</span><span class="p">,</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="k">function</span> <span class="nc">_M</span><span class="p">.</span><span class="nf">get_age</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
|
||
<span class="k">return</span> <span class="n">data</span><span class="p">[</span><span class="n">name</span><span class="p">]</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="k">return</span> <span class="n">_M</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>and then accessing it from <code class="language-plaintext highlighter-rouge">nginx.conf</code>:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/lua</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">mydata</span> <span class="p">=</span> <span class="s">require</span> <span class="s">"mydata"</span>
|
||
<span class="s">ngx.say(mydata.get_age("dog"))</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">mydata</code> module in this example will only be loaded and run on the first request to the location <code class="language-plaintext highlighter-rouge">/lua</code>,
|
||
and all subsequent requests to the same nginx worker process will use the reloaded instance of the
|
||
module as well as the same copy of the data in it, until a <code class="language-plaintext highlighter-rouge">HUP</code> signal is sent to the Nginx master process to force a reload.
|
||
This data sharing technique is essential for high performance Lua applications based on this module.</p>
|
||
|
||
<p>Note that this data sharing is on a <em>per-worker</em> basis and not on a <em>per-server</em> basis. That is, when there are multiple nginx worker processes under an Nginx master, data sharing cannot cross the process boundary between these workers.</p>
|
||
|
||
<p>It is usually recommended to share read-only data this way. You can also share changeable data among all the concurrent requests of each nginx worker process as
|
||
long as there is <em>no</em> nonblocking I/O operations (including <a href="#ngxsleep">ngx.sleep</a>)
|
||
in the middle of your calculations. As long as you do not give the
|
||
control back to the nginx event loop and ngx_lua’s light thread
|
||
scheduler (even implicitly), there can never be any race conditions in
|
||
between. For this reason, always be very careful when you want to share changeable data on the
|
||
worker level. Buggy optimizations can easily lead to hard-to-debug
|
||
race conditions under load.</p>
|
||
|
||
<p>If server-wide data sharing is required, then use one or more of the following approaches:</p>
|
||
|
||
<ol>
|
||
<li>Use the <a href="#ngxshareddict">ngx.shared.DICT</a> API provided by this module.</li>
|
||
<li>Use only a single nginx worker and a single server (this is however not recommended when there is a multi core CPU or multiple CPUs in a single machine).</li>
|
||
<li>Use data storage mechanisms such as <code class="language-plaintext highlighter-rouge">memcached</code>, <code class="language-plaintext highlighter-rouge">redis</code>, <code class="language-plaintext highlighter-rouge">MySQL</code> or <code class="language-plaintext highlighter-rouge">PostgreSQL</code>. <a href="http://openresty.org">The ngx_openresty bundle</a> associated with this module comes with a set of companion Nginx modules and Lua libraries that provide interfaces with these data storage mechanisms.</li>
|
||
</ol>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="known-issues">Known Issues</h1>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h2 id="tcp-socket-connect-operation-issues">TCP socket connect operation issues</h2>
|
||
<p>The <a href="#tcpsockconnect">tcpsock:connect</a> method may indicate <code class="language-plaintext highlighter-rouge">success</code> despite connection failures such as with <code class="language-plaintext highlighter-rouge">Connection Refused</code> errors.</p>
|
||
|
||
<p>However, later attempts to manipulate the cosocket object will fail and return the actual error status message generated by the failed connect operation.</p>
|
||
|
||
<p>This issue is due to limitations in the Nginx event model and only appears to affect Mac OS X.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h2 id="lua-coroutine-yieldingresuming">Lua Coroutine Yielding/Resuming</h2>
|
||
<ul>
|
||
<li>Because Lua’s <code class="language-plaintext highlighter-rouge">dofile</code> and <code class="language-plaintext highlighter-rouge">require</code> builtins are currently implemented as C functions in both Lua 5.1 and LuaJIT 2.0/2.1, if the Lua file being loaded by <code class="language-plaintext highlighter-rouge">dofile</code> or <code class="language-plaintext highlighter-rouge">require</code> invokes [ngx.location.capture<em>](#ngxlocationcapture), <a href="#ngxexec">ngx.exec</a>, <a href="#ngxexit">ngx.exit</a>, or other API functions requiring yielding in the *top-level</em> scope of the Lua file, then the Lua error “attempt to yield across C-call boundary” will be raised. To avoid this, put these calls requiring yielding into your own Lua functions in the Lua file instead of the top-level scope of the file.</li>
|
||
<li>As the standard Lua 5.1 interpreter’s VM is not fully resumable, the methods <a href="#ngxlocationcapture">ngx.location.capture</a>, <a href="#ngxlocationcapture_multi">ngx.location.capture_multi</a>, <a href="#ngxredirect">ngx.redirect</a>, <a href="#ngxexec">ngx.exec</a>, and <a href="#ngxexit">ngx.exit</a> cannot be used within the context of a Lua <a href="http://www.lua.org/manual/5.1/manual.html#pdf-pcall">pcall()</a> or <a href="http://www.lua.org/manual/5.1/manual.html#pdf-xpcall">xpcall()</a> or even the first line of the <code class="language-plaintext highlighter-rouge">for ... in ...</code> statement when the standard Lua 5.1 interpreter is used and the <code class="language-plaintext highlighter-rouge">attempt to yield across metamethod/C-call boundary</code> error will be produced. Please use LuaJIT 2.x, which supports a fully resumable VM, to avoid this.</li>
|
||
</ul>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h2 id="lua-variable-scope">Lua Variable Scope</h2>
|
||
<p>Care must be taken when importing modules and this form should be used:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">xxx</span> <span class="o">=</span> <span class="nb">require</span><span class="p">(</span><span class="s1">'xxx'</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>instead of the old deprecated form:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="nb">require</span><span class="p">(</span><span class="s1">'xxx'</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Here is the reason: by design, the global environment has exactly the same lifetime as the Nginx request handler associated with it. Each request handler has its own set of Lua global variables and that is the idea of request isolation. The Lua module is actually loaded by the first Nginx request handler and is cached by the <code class="language-plaintext highlighter-rouge">require()</code> built-in in the <code class="language-plaintext highlighter-rouge">package.loaded</code> table for later reference, and the <code class="language-plaintext highlighter-rouge">module()</code> builtin used by some Lua modules has the side effect of setting a global variable to the loaded module table. But this global variable will be cleared at the end of the request handler, and every subsequent request handler all has its own (clean) global environment. So one will get Lua exception for accessing the <code class="language-plaintext highlighter-rouge">nil</code> value.</p>
|
||
|
||
<p>Generally, use of Lua global variables is a really really bad idea in the context of ngx_lua because</p>
|
||
|
||
<ol>
|
||
<li>misuse of Lua globals has very bad side effects for concurrent requests when these variables are actually supposed to be local only,</li>
|
||
<li>Lua global variables require Lua table look-up in the global environment (which is just a Lua table), which is kinda expensive, and</li>
|
||
<li>some Lua global variable references are just typos, which are hard to debug.</li>
|
||
</ol>
|
||
|
||
<p>It’s <em>highly</em> recommended to always declare them via “local” in the scope that is reasonable.</p>
|
||
|
||
<p>To find out all the uses of Lua global variables in your Lua code, you can run the <a href="https://github.com/openresty/nginx-devel-utils/blob/master/lua-releng">lua-releng tool</a> across all your .lua source files:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ lua-releng
|
||
Checking use of Lua global variables in file lib/foo/bar.lua ...
|
||
1 [1489] SETGLOBAL 7 -1 ; contains
|
||
55 [1506] GETGLOBAL 7 -3 ; setvar
|
||
3 [1545] GETGLOBAL 3 -4 ; varexpand
|
||
</code></pre></div></div>
|
||
|
||
<p>The output says that the line 1489 of file <code class="language-plaintext highlighter-rouge">lib/foo/bar.lua</code> writes to a global variable named <code class="language-plaintext highlighter-rouge">contains</code>, the line 1506 reads from the global variable <code class="language-plaintext highlighter-rouge">setvar</code>, and line 1545 reads the global <code class="language-plaintext highlighter-rouge">varexpand</code>.</p>
|
||
|
||
<p>This tool will guarantee that local variables in the Lua module functions are all declared with the <code class="language-plaintext highlighter-rouge">local</code> keyword, otherwise a runtime exception will be thrown. It prevents undesirable race conditions while accessing such variables. See <a href="#data-sharing-within-an-nginx-worker">Data Sharing within an Nginx Worker</a> for the reasons behind this.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h2 id="locations-configured-by-subrequest-directives-of-other-modules">Locations Configured by Subrequest Directives of Other Modules</h2>
|
||
<p>The <a href="#ngxlocationcapture">ngx.location.capture</a> and <a href="#ngxlocationcapture_multi">ngx.location.capture_multi</a> directives cannot capture locations that include the <a href="http://nginx.org/en/docs/http/ngx_http_addition_module.html#add_before_body">add_before_body</a>, <a href="http://nginx.org/en/docs/http/ngx_http_addition_module.html#add_after_body">add_after_body</a>, <a href="http://nginx.org/en/docs/http/ngx_http_auth_request_module.html#auth_request">auth_request</a>, <a href="http://github.com/openresty/echo-nginx-module#echo_location">echo_location</a>, <a href="http://github.com/openresty/echo-nginx-module#echo_location_async">echo_location_async</a>, <a href="http://github.com/openresty/echo-nginx-module#echo_subrequest">echo_subrequest</a>, or <a href="http://github.com/openresty/echo-nginx-module#echo_subrequest_async">echo_subrequest_async</a> directives.</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/foo</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">res</span> <span class="p">=</span> <span class="s">ngx.location.capture("/bar")</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="k">location</span> <span class="n">/bar</span> <span class="p">{</span>
|
||
<span class="kn">echo_location</span> <span class="n">/blah</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="k">location</span> <span class="n">/blah</span> <span class="p">{</span>
|
||
<span class="kn">echo</span> <span class="s">"Success!"</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
$ <span class="k">curl</span> <span class="s">-i</span> <span class="s">http://example.com/foo</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>will not work as expected.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h2 id="cosockets-not-available-everywhere">Cosockets Not Available Everywhere</h2>
|
||
|
||
<p>Due the internal limitations in the nginx core, the cosocket API are disabled in the following contexts: <a href="#log_by_lua">set_by_lua<em>](#set_by_lua), [log_by_lua</em></a>, <a href="#header_filter_by_lua">header_filter_by_lua*</a>, and <a href="#body_filter_by_lua">body_filter_by_lua</a>.</p>
|
||
|
||
<p>The cosockets are currently also disabled in the <a href="#init_worker_by_lua">init_by_lua<em>](#init_by_lua) and [init_worker_by_lua</em></a> directive contexts but we may add support for these contexts in the future because there is no limitation in the nginx core (or the limitation might be worked around).</p>
|
||
|
||
<p>There exists a work-around, however, when the original context does <em>not</em> need to wait for the cosocket results. That is, creating a 0-delay timer via the <a href="#ngxtimerat">ngx.timer.at</a> API and do the cosocket results in the timer handler, which runs asynchronously as to the original context creating the timer.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h2 id="special-escaping-sequences">Special Escaping Sequences</h2>
|
||
<p>PCRE sequences such as <code class="language-plaintext highlighter-rouge">\d</code>, <code class="language-plaintext highlighter-rouge">\s</code>, or <code class="language-plaintext highlighter-rouge">\w</code>, require special attention because in string literals, the backslash character, <code class="language-plaintext highlighter-rouge">\</code>, is stripped out by both the Lua language parser and by the Nginx config file parser before processing. So the following snippet will not work as expected:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="c1"># nginx.conf</span>
|
||
<span class="k">?</span> <span class="s">location</span> <span class="n">/test</span> <span class="p">{</span>
|
||
<span class="kn">?</span> <span class="s">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">?</span> <span class="s">local</span> <span class="s">regex</span> <span class="p">=</span> <span class="s">"</span><span class="err">\</span><span class="s">d+"</span> <span class="s">--</span> <span class="s">THIS</span> <span class="s">IS</span> <span class="s">WRONG!!</span>
|
||
<span class="s">?</span> <span class="s">local</span> <span class="s">m</span> <span class="p">=</span> <span class="s">ngx.re.match("hello,</span> <span class="mi">1234</span><span class="s">",</span> <span class="s">regex)</span>
|
||
<span class="s">?</span> <span class="s">if</span> <span class="s">m</span> <span class="s">then</span> <span class="s">ngx.say(m[0])</span> <span class="s">else</span> <span class="s">ngx.say("not</span> <span class="s">matched!")</span> <span class="s">end</span>
|
||
<span class="s">?</span> <span class="s">'</span><span class="p">;</span>
|
||
<span class="kn">?</span> <span class="err">}</span>
|
||
<span class="c1"># evaluates to "not matched!"</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>To avoid this, <em>double</em> escape the backslash:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="c1"># nginx.conf</span>
|
||
<span class="k">location</span> <span class="n">/test</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">regex</span> <span class="p">=</span> <span class="s">"</span><span class="err">\\\\</span><span class="s">d+"</span>
|
||
<span class="s">local</span> <span class="s">m</span> <span class="p">=</span> <span class="s">ngx.re.match("hello,</span> <span class="mi">1234</span><span class="s">",</span> <span class="s">regex)</span>
|
||
<span class="s">if</span> <span class="s">m</span> <span class="s">then</span> <span class="s">ngx.say(m[0])</span> <span class="s">else</span> <span class="s">ngx.say("not</span> <span class="s">matched!")</span> <span class="s">end</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="c1"># evaluates to "1234"</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Here, <code class="language-plaintext highlighter-rouge">\\\\d+</code> is stripped down to <code class="language-plaintext highlighter-rouge">\\d+</code> by the Nginx config file parser and this is further stripped down to <code class="language-plaintext highlighter-rouge">\d+</code> by the Lua language parser before running.</p>
|
||
|
||
<p>Alternatively, the regex pattern can be presented as a long-bracketed Lua string literal by encasing it in “long brackets”, <code class="language-plaintext highlighter-rouge">[[...]]</code>, in which case backslashes have to only be escaped once for the Nginx config file parser.</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="c1"># nginx.conf</span>
|
||
<span class="k">location</span> <span class="n">/test</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">regex</span> <span class="p">=</span> <span class="s">[[</span><span class="err">\\</span><span class="s">d+]]</span>
|
||
<span class="s">local</span> <span class="s">m</span> <span class="p">=</span> <span class="s">ngx.re.match("hello,</span> <span class="mi">1234</span><span class="s">",</span> <span class="s">regex)</span>
|
||
<span class="s">if</span> <span class="s">m</span> <span class="s">then</span> <span class="s">ngx.say(m[0])</span> <span class="s">else</span> <span class="s">ngx.say("not</span> <span class="s">matched!")</span> <span class="s">end</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="c1"># evaluates to "1234"</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Here, <code class="language-plaintext highlighter-rouge">[[\\d+]]</code> is stripped down to <code class="language-plaintext highlighter-rouge">[[\d+]]</code> by the Nginx config file parser and this is processed correctly.</p>
|
||
|
||
<p>Note that a longer from of the long bracket, <code class="language-plaintext highlighter-rouge">[=[...]=]</code>, may be required if the regex pattern contains <code class="language-plaintext highlighter-rouge">[...]</code> sequences.
|
||
The <code class="language-plaintext highlighter-rouge">[=[...]=]</code> form may be used as the default form if desired.</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="c1"># nginx.conf</span>
|
||
<span class="k">location</span> <span class="n">/test</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">regex</span> <span class="p">=</span> <span class="s">[=[[0-9]+]=]</span>
|
||
<span class="s">local</span> <span class="s">m</span> <span class="p">=</span> <span class="s">ngx.re.match("hello,</span> <span class="mi">1234</span><span class="s">",</span> <span class="s">regex)</span>
|
||
<span class="s">if</span> <span class="s">m</span> <span class="s">then</span> <span class="s">ngx.say(m[0])</span> <span class="s">else</span> <span class="s">ngx.say("not</span> <span class="s">matched!")</span> <span class="s">end</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="c1"># evaluates to "1234"</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>An alternative approach to escaping PCRE sequences is to ensure that Lua code is placed in external script files and executed using the various <code class="language-plaintext highlighter-rouge">*_by_lua_file</code> directives.
|
||
With this approach, the backslashes are only stripped by the Lua language parser and therefore only need to be escaped once each.</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="c1">-- test.lua</span>
|
||
<span class="kd">local</span> <span class="n">regex</span> <span class="o">=</span> <span class="s2">"</span><span class="se">\\</span><span class="s2">d+"</span>
|
||
<span class="kd">local</span> <span class="n">m</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="n">match</span><span class="p">(</span><span class="s2">"hello, 1234"</span><span class="p">,</span> <span class="n">regex</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="n">m</span> <span class="k">then</span> <span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="k">else</span> <span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"not matched!"</span><span class="p">)</span> <span class="k">end</span>
|
||
<span class="c1">-- evaluates to "1234"</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Within external script files, PCRE sequences presented as long-bracketed Lua string literals do not require modification.</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="c1">-- test.lua</span>
|
||
<span class="kd">local</span> <span class="n">regex</span> <span class="o">=</span> <span class="s">[[\d+]]</span>
|
||
<span class="kd">local</span> <span class="n">m</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="n">match</span><span class="p">(</span><span class="s2">"hello, 1234"</span><span class="p">,</span> <span class="n">regex</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="n">m</span> <span class="k">then</span> <span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="k">else</span> <span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"not matched!"</span><span class="p">)</span> <span class="k">end</span>
|
||
<span class="c1">-- evaluates to "1234"</span>
|
||
</code></pre></div></div>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h2 id="mixing-with-ssi-not-supported">Mixing with SSI Not Supported</h2>
|
||
|
||
<p>Mixing SSI with ngx_lua in the same Nginx request is not supported at all. Just use ngx_lua exclusively. Everything you can do with SSI can be done atop ngx_lua anyway and it can be more efficient when using ngx_lua.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h2 id="spdy-mode-not-fully-supported">SPDY Mode Not Fully Supported</h2>
|
||
|
||
<p>Certain Lua APIs provided by ngx_lua do not work in Nginx’s SPDY mode yet: <a href="#ngxlocationcapture">ngx.location.capture</a>, <a href="#ngxlocationcapture_multi">ngx.location.capture_multi</a>, and <a href="#ngxreqsocket">ngx.req.socket</a>.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h2 id="missing-data-on-short-circuited-requests">Missing data on short circuited requests</h2>
|
||
|
||
<p>Nginx may terminate a request early with (at least):</p>
|
||
|
||
<ul>
|
||
<li>400 (Bad Request)</li>
|
||
<li>405 (Not Allowed)</li>
|
||
<li>408 (Request Timeout)</li>
|
||
<li>414 (Request URI Too Large)</li>
|
||
<li>494 (Request Headers Too Large)</li>
|
||
<li>499 (Client Closed Request)</li>
|
||
<li>500 (Internal Server Error)</li>
|
||
<li>501 (Not Implemented)</li>
|
||
</ul>
|
||
|
||
<p>This means that phases that normally run are skipped, such as the rewrite or
|
||
access phase. This also means that later phases that are run regardless, e.g.
|
||
<a href="#log_by_lua">log_by_lua</a>, will not have access to information that is normally set in those
|
||
phases.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="todo">TODO</h1>
|
||
|
||
<ul>
|
||
<li>add <code class="language-plaintext highlighter-rouge">*_by_lua_block</code> directives for existing <code class="language-plaintext highlighter-rouge">*_by_lua</code> directives so that we put literal Lua code directly in curly braces instead of an nginx literal string. For example,
|
||
```nginx</li>
|
||
</ul>
|
||
|
||
<p>content_by_lua_block {
|
||
ngx.say(“hello, world\r\n”)
|
||
}</p>
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> which is equivalent to
|
||
```nginx
|
||
|
||
content_by_lua '
|
||
ngx.say("hello, world\\r\\n")
|
||
';
|
||
</code></pre></div></div>
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>but the former is much cleaner and nicer. * cosocket: implement LuaSocket's unconnected UDP API. * add support for implementing general TCP servers instead of HTTP servers in Lua. For example, ```lua
|
||
</code></pre></div></div>
|
||
|
||
<p>tcp {
|
||
server {
|
||
listen 11212;
|
||
handler_by_lua ‘
|
||
– custom Lua code implementing the special TCP server…
|
||
‘;
|
||
}
|
||
}</p>
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>* add support for implementing general UDP servers instead of HTTP servers in Lua. For example,
|
||
```lua
|
||
|
||
udp {
|
||
server {
|
||
listen 1953;
|
||
handler_by_lua '
|
||
-- custom Lua code implementing the special UDP server...
|
||
';
|
||
}
|
||
}
|
||
</code></pre></div></div>
|
||
<ul>
|
||
<li>ssl: implement directives <code class="language-plaintext highlighter-rouge">ssl_certificate_by_lua</code> and <code class="language-plaintext highlighter-rouge">ssl_certificate_by_lua_file</code> to allow using Lua to dynamically serve SSL certificates and keys for downstream SSL handshake. (already done in CloudFlare’s private branch and powering CloudFlare’s SSL gateway of its global network. expected to be opensourced in March 2015.)</li>
|
||
<li>shm: implement a “shared queue API” to complement the existing <a href="#lua_shared_dict">shared dict</a> API.</li>
|
||
<li>cosocket: add support in the context of <a href="#init_by_lua">init_by_lua*</a>.</li>
|
||
<li>cosocket: implement the <code class="language-plaintext highlighter-rouge">bind()</code> method for stream-typed cosockets.</li>
|
||
<li>cosocket: pool-based backend concurrency level control: implement automatic <code class="language-plaintext highlighter-rouge">connect</code> queueing when the backend concurrency exceeds its connection pool limit.</li>
|
||
<li>cosocket: review and merge aviramc’s <a href="https://github.com/openresty/lua-nginx-module/pull/290">patch</a> for adding the <code class="language-plaintext highlighter-rouge">bsdrecv</code> method.</li>
|
||
<li>add new API function <code class="language-plaintext highlighter-rouge">ngx.resp.add_header</code> to emulate the standard <code class="language-plaintext highlighter-rouge">add_header</code> config directive.</li>
|
||
<li><a href="#ngxrematch">ngx.re</a> API: use <code class="language-plaintext highlighter-rouge">false</code> instead of <code class="language-plaintext highlighter-rouge">nil</code> in the resulting match table to indicate non-existent submatch captures, such that we can avoid “holes” in the array table.</li>
|
||
<li>review and apply Jader H. Silva’s patch for <code class="language-plaintext highlighter-rouge">ngx.re.split()</code>.</li>
|
||
<li>review and apply vadim-pavlov’s patch for <a href="#ngxlocationcapture">ngx.location.capture</a>’s <code class="language-plaintext highlighter-rouge">extra_headers</code> option</li>
|
||
<li>use <code class="language-plaintext highlighter-rouge">ngx_hash_t</code> to optimize the built-in header look-up process for <a href="#ngxreqset_header">ngx.req.set_header</a>, <a href="#ngxheaderheader">ngx.header.HEADER</a>, and etc.</li>
|
||
<li>add configure options for different strategies of handling the cosocket connection exceeding in the pools.</li>
|
||
<li>add directives to run Lua codes when nginx stops.</li>
|
||
<li>add <code class="language-plaintext highlighter-rouge">ignore_resp_headers</code>, <code class="language-plaintext highlighter-rouge">ignore_resp_body</code>, and <code class="language-plaintext highlighter-rouge">ignore_resp</code> options to <a href="#ngxlocationcapture">ngx.location.capture</a> and <a href="#ngxlocationcapture_multi">ngx.location.capture_multi</a> methods, to allow micro performance tuning on the user side.</li>
|
||
<li>add automatic Lua code time slicing support by yielding and resuming the Lua VM actively via Lua’s debug hooks.</li>
|
||
<li>add <code class="language-plaintext highlighter-rouge">stat</code> mode similar to <a href="https://httpd.apache.org/docs/trunk/mod/mod_lua.html">mod_lua</a>.</li>
|
||
</ul>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="changes">Changes</h1>
|
||
|
||
<p>The changes of every release of this module can be obtained from the ngx_openresty bundle’s change logs:</p>
|
||
|
||
<p><a href="http://openresty.org/#Changes">http://openresty.org/#Changes</a></p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="test-suite">Test Suite</h1>
|
||
|
||
<p>The following dependencies are required to run the test suite:</p>
|
||
|
||
<ul>
|
||
<li>
|
||
<p>Nginx version >= 1.4.2</p>
|
||
</li>
|
||
<li>Perl modules:
|
||
<ul>
|
||
<li>Test::Nginx: <a href="https://github.com/openresty/test-nginx">https://github.com/openresty/test-nginx</a></li>
|
||
</ul>
|
||
</li>
|
||
<li>Nginx modules:
|
||
<ul>
|
||
<li><a href="https://github.com/simpl/ngx_devel_kit">ngx_devel_kit</a></li>
|
||
<li><a href="https://github.com/openresty/set-misc-nginx-module">ngx_set_misc</a></li>
|
||
<li><a href="http://mdounin.ru/files/ngx_http_auth_request_module-0.2.tar.gz">ngx_auth_request</a> (this is not needed if you’re using Nginx 1.5.4+.</li>
|
||
<li><a href="https://github.com/openresty/echo-nginx-module">ngx_echo</a></li>
|
||
<li><a href="https://github.com/openresty/memc-nginx-module">ngx_memc</a></li>
|
||
<li><a href="https://github.com/openresty/srcache-nginx-module">ngx_srcache</a></li>
|
||
<li>ngx_lua (i.e., this module)</li>
|
||
<li><a href="https://github.com/openresty/lua-upstream-nginx-module">ngx_lua_upstream</a></li>
|
||
<li><a href="https://github.com/openresty/headers-more-nginx-module">ngx_headers_more</a></li>
|
||
<li><a href="https://github.com/openresty/drizzle-nginx-module">ngx_drizzle</a></li>
|
||
<li><a href="https://github.com/openresty/rds-json-nginx-module">ngx_rds_json</a></li>
|
||
<li><a href="https://github.com/FRiCKLE/ngx_coolkit">ngx_coolkit</a></li>
|
||
<li><a href="https://github.com/openresty/redis2-nginx-module">ngx_redis2</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<p>The order in which these modules are added during configuration is important because the position of any filter module in the
|
||
filtering chain determines the final output, for example. The correct adding order is shown above.</p>
|
||
|
||
<ul>
|
||
<li>3rd-party Lua libraries:
|
||
<ul>
|
||
<li><a href="http://www.kyne.com.au/~mark/software/lua-cjson.php">lua-cjson</a></li>
|
||
</ul>
|
||
</li>
|
||
<li>Applications:
|
||
<ul>
|
||
<li>mysql: create database ‘ngx_test’, grant all privileges to user ‘ngx_test’, password is ‘ngx_test’</li>
|
||
<li>memcached: listening on the default port, 11211.</li>
|
||
<li>redis: listening on the default port, 6379.</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<p>See also the <a href="https://github.com/openresty/lua-nginx-module/blob/master/util/build2.sh">developer build script</a> for more details on setting up the testing environment.</p>
|
||
|
||
<p>To run the whole test suite in the default testing mode:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cd /path/to/lua-nginx-module
|
||
export PATH=/path/to/your/nginx/sbin:$PATH
|
||
prove -I/path/to/test-nginx/lib -r t
|
||
</code></pre></div></div>
|
||
|
||
<p>To run specific test files:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cd /path/to/lua-nginx-module
|
||
export PATH=/path/to/your/nginx/sbin:$PATH
|
||
prove -I/path/to/test-nginx/lib t/002-content.t t/003-errors.t
|
||
</code></pre></div></div>
|
||
|
||
<p>To run a specific test block in a particular test file, add the line <code class="language-plaintext highlighter-rouge">--- ONLY</code> to the test block you want to run, and then use the <code class="language-plaintext highlighter-rouge">prove</code> utility to run that <code class="language-plaintext highlighter-rouge">.t</code> file.</p>
|
||
|
||
<p>There are also various testing modes based on mockeagain, valgrind, and etc. Refer to the <a href="http://search.cpan.org/perldoc?Test::Nginx">Test::Nginx documentation</a> for more details for various advanced testing modes. See also the test reports for the Nginx test cluster running on Amazon EC2: <a href="http://qa.openresty.org.">http://qa.openresty.org.</a></p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="copyright-and-license">Copyright and License</h1>
|
||
|
||
<p>This module is licensed under the BSD license.</p>
|
||
|
||
<p>Copyright (C) 2009-2015, by Xiaozhe Wang (chaoslawful) <a href="mailto:chaoslawful@gmail.com">chaoslawful@gmail.com</a>.</p>
|
||
|
||
<p>Copyright (C) 2009-2015, by Yichun “agentzh” Zhang (章亦春) <a href="mailto:agentzh@gmail.com">agentzh@gmail.com</a>, CloudFlare Inc.</p>
|
||
|
||
<p>All rights reserved.</p>
|
||
|
||
<p>Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:</p>
|
||
|
||
<ul>
|
||
<li>
|
||
<p>Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.</p>
|
||
</li>
|
||
<li>
|
||
<p>Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.</p>
|
||
</li>
|
||
</ul>
|
||
|
||
<p>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="see-also">See Also</h1>
|
||
|
||
<ul>
|
||
<li><a href="https://github.com/openresty/lua-resty-memcached">lua-resty-memcached</a> library based on ngx_lua cosocket.</li>
|
||
<li><a href="https://github.com/openresty/lua-resty-redis">lua-resty-redis</a> library based on ngx_lua cosocket.</li>
|
||
<li><a href="https://github.com/openresty/lua-resty-mysql">lua-resty-mysql</a> library based on ngx_lua cosocket.</li>
|
||
<li><a href="https://github.com/openresty/lua-resty-upload">lua-resty-upload</a> library based on ngx_lua cosocket.</li>
|
||
<li><a href="https://github.com/openresty/lua-resty-dns">lua-resty-dns</a> library based on ngx_lua cosocket.</li>
|
||
<li><a href="https://github.com/openresty/lua-resty-websocket">lua-resty-websocket</a> library for both WebSocket server and client, based on ngx_lua cosocket.</li>
|
||
<li><a href="https://github.com/openresty/lua-resty-string">lua-resty-string</a> library based on <a href="http://luajit.org/ext_ffi.html">LuaJIT FFI</a>.</li>
|
||
<li><a href="https://github.com/openresty/lua-resty-lock">lua-resty-lock</a> library for a nonblocking simple lock API.</li>
|
||
<li><a href="https://github.com/cloudflare/lua-resty-cookie">lua-resty-cookie</a> library for HTTP cookie manipulation.</li>
|
||
<li><a href="http://openresty.org/#RoutingMySQLQueriesBasedOnURIArgs">Routing requests to different MySQL queries based on URI arguments</a></li>
|
||
<li><a href="http://openresty.org/#DynamicRoutingBasedOnRedis">Dynamic Routing Based on Redis and Lua</a></li>
|
||
<li><a href="http://openresty.org/#UsingLuaRocks">Using LuaRocks with ngx_lua</a></li>
|
||
<li><a href="https://github.com/openresty/lua-nginx-module/wiki/Introduction">Introduction to ngx_lua</a></li>
|
||
<li><a href="https://github.com/simpl/ngx_devel_kit">ngx_devel_kit</a></li>
|
||
<li><a href="http://github.com/openresty/echo-nginx-module">echo-nginx-module</a></li>
|
||
<li><a href="http://github.com/openresty/drizzle-nginx-module">drizzle-nginx-module</a></li>
|
||
<li><a href="https://github.com/FRiCKLE/ngx_postgres">postgres-nginx-module</a></li>
|
||
<li><a href="http://github.com/openresty/memc-nginx-module">memc-nginx-module</a></li>
|
||
<li><a href="http://openresty.org">The ngx_openresty bundle</a></li>
|
||
<li><a href="https://github.com/openresty/nginx-systemtap-toolkit">Nginx Systemtap Toolkit</a></li>
|
||
</ul>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h1 id="directives">Directives</h1>
|
||
|
||
<ul>
|
||
<li><a href="#lua_use_default_type">lua_use_default_type</a></li>
|
||
<li><a href="#lua_code_cache">lua_code_cache</a></li>
|
||
<li><a href="#lua_regex_cache_max_entries">lua_regex_cache_max_entries</a></li>
|
||
<li><a href="#lua_regex_match_limit">lua_regex_match_limit</a></li>
|
||
<li><a href="#lua_package_path">lua_package_path</a></li>
|
||
<li><a href="#lua_package_cpath">lua_package_cpath</a></li>
|
||
<li><a href="#init_by_lua">init_by_lua</a></li>
|
||
<li><a href="#init_by_lua_file">init_by_lua_file</a></li>
|
||
<li><a href="#init_worker_by_lua">init_worker_by_lua</a></li>
|
||
<li><a href="#init_worker_by_lua_file">init_worker_by_lua_file</a></li>
|
||
<li><a href="#set_by_lua">set_by_lua</a></li>
|
||
<li><a href="#set_by_lua_file">set_by_lua_file</a></li>
|
||
<li><a href="#content_by_lua">content_by_lua</a></li>
|
||
<li><a href="#content_by_lua_file">content_by_lua_file</a></li>
|
||
<li><a href="#rewrite_by_lua">rewrite_by_lua</a></li>
|
||
<li><a href="#rewrite_by_lua_file">rewrite_by_lua_file</a></li>
|
||
<li><a href="#access_by_lua">access_by_lua</a></li>
|
||
<li><a href="#access_by_lua_file">access_by_lua_file</a></li>
|
||
<li><a href="#header_filter_by_lua">header_filter_by_lua</a></li>
|
||
<li><a href="#header_filter_by_lua_file">header_filter_by_lua_file</a></li>
|
||
<li><a href="#body_filter_by_lua">body_filter_by_lua</a></li>
|
||
<li><a href="#body_filter_by_lua_file">body_filter_by_lua_file</a></li>
|
||
<li><a href="#log_by_lua">log_by_lua</a></li>
|
||
<li><a href="#log_by_lua_file">log_by_lua_file</a></li>
|
||
<li><a href="#lua_need_request_body">lua_need_request_body</a></li>
|
||
<li><a href="#lua_shared_dict">lua_shared_dict</a></li>
|
||
<li><a href="#lua_socket_connect_timeout">lua_socket_connect_timeout</a></li>
|
||
<li><a href="#lua_socket_send_timeout">lua_socket_send_timeout</a></li>
|
||
<li><a href="#lua_socket_send_lowat">lua_socket_send_lowat</a></li>
|
||
<li><a href="#lua_socket_read_timeout">lua_socket_read_timeout</a></li>
|
||
<li><a href="#lua_socket_buffer_size">lua_socket_buffer_size</a></li>
|
||
<li><a href="#lua_socket_pool_size">lua_socket_pool_size</a></li>
|
||
<li><a href="#lua_socket_keepalive_timeout">lua_socket_keepalive_timeout</a></li>
|
||
<li><a href="#lua_socket_log_errors">lua_socket_log_errors</a></li>
|
||
<li><a href="#lua_ssl_ciphers">lua_ssl_ciphers</a></li>
|
||
<li><a href="#lua_ssl_crl">lua_ssl_crl</a></li>
|
||
<li><a href="#lua_ssl_protocols">lua_ssl_protocols</a></li>
|
||
<li><a href="#lua_ssl_trusted_certificate">lua_ssl_trusted_certificate</a></li>
|
||
<li><a href="#lua_ssl_verify_depth">lua_ssl_verify_depth</a></li>
|
||
<li><a href="#lua_http10_buffering">lua_http10_buffering</a></li>
|
||
<li><a href="#rewrite_by_lua_no_postpone">rewrite_by_lua_no_postpone</a></li>
|
||
<li><a href="#lua_transform_underscores_in_response_headers">lua_transform_underscores_in_response_headers</a></li>
|
||
<li><a href="#lua_check_client_abort">lua_check_client_abort</a></li>
|
||
<li><a href="#lua_max_pending_timers">lua_max_pending_timers</a></li>
|
||
<li><a href="#lua_max_running_timers">lua_max_running_timers</a></li>
|
||
</ul>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_use_default_type">lua_use_default_type</h2>
|
||
<p><strong>syntax:</strong> <em>lua_use_default_type on | off</em></p>
|
||
|
||
<p><strong>default:</strong> <em>lua_use_default_type on</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location, location if</em></p>
|
||
|
||
<p>Specifies whether to use the MIME type specified by the <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#default_type">default_type</a> directive for the default value of the <code class="language-plaintext highlighter-rouge">Content-Type</code> response header. If you do not want a default <code class="language-plaintext highlighter-rouge">Content-Type</code> response header for your Lua request handlers, then turn this directive off.</p>
|
||
|
||
<p>This directive is turned on by default.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.9.1</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_code_cache">lua_code_cache</h2>
|
||
<p><strong>syntax:</strong> <em>lua_code_cache on | off</em></p>
|
||
|
||
<p><strong>default:</strong> <em>lua_code_cache on</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location, location if</em></p>
|
||
|
||
<p>Enables or disables the Lua code cache for Lua code in <code class="language-plaintext highlighter-rouge">*_by_lua_file</code> directives (like <a href="#set_by_lua_file">set_by_lua_file</a> and
|
||
<a href="#content_by_lua_file">content_by_lua_file</a>) and Lua modules.</p>
|
||
|
||
<p>When turning off, every request served by ngx_lua will run in a separate Lua VM instance, starting from the <code class="language-plaintext highlighter-rouge">0.9.3</code> release. So the Lua files referenced in <a href="#set_by_lua_file">set_by_lua_file</a>,
|
||
<a href="#content_by_lua_file">content_by_lua_file</a>, <a href="#access_by_lua_file">access_by_lua_file</a>,
|
||
and etc will not be cached
|
||
and all Lua modules used will be loaded from scratch. With this in place, developers can adopt an edit-and-refresh approach.</p>
|
||
|
||
<p>Please note however, that Lua code written inlined within nginx.conf
|
||
such as those specified by <a href="#set_by_lua">set_by_lua</a>, <a href="#content_by_lua">content_by_lua</a>,
|
||
<a href="#access_by_lua">access_by_lua</a>, and <a href="#rewrite_by_lua">rewrite_by_lua</a> will not be updated when you edit the inlined Lua code in your <code class="language-plaintext highlighter-rouge">nginx.conf</code> file because only the Nginx config file parser can correctly parse the <code class="language-plaintext highlighter-rouge">nginx.conf</code>
|
||
file and the only way is to reload the config file
|
||
by sending a <code class="language-plaintext highlighter-rouge">HUP</code> signal or just to restart Nginx.</p>
|
||
|
||
<p>Even when the code cache is enabled, Lua files which are loaded by <code class="language-plaintext highlighter-rouge">dofile</code> or <code class="language-plaintext highlighter-rouge">loadfile</code>
|
||
in *_by_lua_file cannot be cached (unless you cache the results yourself). Usually you can either use the <a href="#init_by_lua">init_by_lua</a>
|
||
or <a href="#init-by_lua_file">init_by_lua_file</a> directives to load all such files or just make these Lua files true Lua modules
|
||
and load them via <code class="language-plaintext highlighter-rouge">require</code>.</p>
|
||
|
||
<p>The ngx_lua module does not support the <code class="language-plaintext highlighter-rouge">stat</code> mode available with the
|
||
Apache <code class="language-plaintext highlighter-rouge">mod_lua</code> module (yet).</p>
|
||
|
||
<p>Disabling the Lua code cache is strongly
|
||
discouraged for production use and should only be used during
|
||
development as it has a significant negative impact on overall performance. For example, the performance a “hello world” Lua example can drop by an order of magnitude after disabling the Lua code cache.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_regex_cache_max_entries">lua_regex_cache_max_entries</h2>
|
||
<p><strong>syntax:</strong> <em>lua_regex_cache_max_entries <num></em></p>
|
||
|
||
<p><strong>default:</strong> <em>lua_regex_cache_max_entries 1024</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http</em></p>
|
||
|
||
<p>Specifies the maximum number of entries allowed in the worker process level compiled regex cache.</p>
|
||
|
||
<p>The regular expressions used in <a href="#ngxrematch">ngx.re.match</a>, <a href="#ngxregmatch">ngx.re.gmatch</a>, <a href="#ngxresub">ngx.re.sub</a>, and <a href="#ngxregsub">ngx.re.gsub</a> will be cached within this cache if the regex option <code class="language-plaintext highlighter-rouge">o</code> (i.e., compile-once flag) is specified.</p>
|
||
|
||
<p>The default number of entries allowed is 1024 and when this limit is reached, new regular expressions will not be cached (as if the <code class="language-plaintext highlighter-rouge">o</code> option was not specified) and there will be one, and only one, warning in the <code class="language-plaintext highlighter-rouge">error.log</code> file:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>2011/08/27 23:18:26 [warn] 31997#0: *1 lua exceeding regex cache max entries (1024), ...
|
||
</code></pre></div></div>
|
||
|
||
<p>Do not activate the <code class="language-plaintext highlighter-rouge">o</code> option for regular expressions (and/or <code class="language-plaintext highlighter-rouge">replace</code> string arguments for <a href="#ngxresub">ngx.re.sub</a> and <a href="#ngxregsub">ngx.re.gsub</a>) that are generated <em>on the fly</em> and give rise to infinite variations to avoid hitting the specified limit.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_regex_match_limit">lua_regex_match_limit</h2>
|
||
<p><strong>syntax:</strong> <em>lua_regex_match_limit <num></em></p>
|
||
|
||
<p><strong>default:</strong> <em>lua_regex_match_limit 0</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http</em></p>
|
||
|
||
<p>Specifies the “match limit” used by the PCRE library when executing the <a href="#ngxrematch">ngx.re API</a>. To quote the PCRE manpage, “the limit … has the effect of limiting the amount of backtracking that can take place.”</p>
|
||
|
||
<p>When the limit is hit, the error string “pcre_exec() failed: -8” will be returned by the <a href="#ngxrematch">ngx.re API</a> functions on the Lua land.</p>
|
||
|
||
<p>When setting the limit to 0, the default “match limit” when compiling the PCRE library is used. And this is the default value of this directive.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.8.5</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_package_path">lua_package_path</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_package_path <lua-style-path-str></em></p>
|
||
|
||
<p><strong>default:</strong> <em>The content of LUA_PATH environ variable or Lua’s compiled-in defaults.</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http</em></p>
|
||
|
||
<p>Sets the Lua module search path used by scripts specified by <a href="#set_by_lua">set_by_lua</a>,
|
||
<a href="#content_by_lua">content_by_lua</a> and others. The path string is in standard Lua path form, and <code class="language-plaintext highlighter-rouge">;;</code>
|
||
can be used to stand for the original search paths.</p>
|
||
|
||
<p>As from the <code class="language-plaintext highlighter-rouge">v0.5.0rc29</code> release, the special notation <code class="language-plaintext highlighter-rouge">$prefix</code> or <code class="language-plaintext highlighter-rouge">${prefix}</code> can be used in the search path string to indicate the path of the <code class="language-plaintext highlighter-rouge">server prefix</code> usually determined by the <code class="language-plaintext highlighter-rouge">-p PATH</code> command-line option while starting the Nginx server.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_package_cpath">lua_package_cpath</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_package_cpath <lua-style-cpath-str></em></p>
|
||
|
||
<p><strong>default:</strong> <em>The content of LUA_CPATH environment variable or Lua’s compiled-in defaults.</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http</em></p>
|
||
|
||
<p>Sets the Lua C-module search path used by scripts specified by <a href="#set_by_lua">set_by_lua</a>,
|
||
<a href="#content_by_lua">content_by_lua</a> and others. The cpath string is in standard Lua cpath form, and <code class="language-plaintext highlighter-rouge">;;</code>
|
||
can be used to stand for the original cpath.</p>
|
||
|
||
<p>As from the <code class="language-plaintext highlighter-rouge">v0.5.0rc29</code> release, the special notation <code class="language-plaintext highlighter-rouge">$prefix</code> or <code class="language-plaintext highlighter-rouge">${prefix}</code> can be used in the search path string to indicate the path of the <code class="language-plaintext highlighter-rouge">server prefix</code> usually determined by the <code class="language-plaintext highlighter-rouge">-p PATH</code> command-line option while starting the Nginx server.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="init_by_lua">init_by_lua</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>init_by_lua <lua-script-str></em></p>
|
||
|
||
<p><strong>context:</strong> <em>http</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>loading-config</em></p>
|
||
|
||
<p>Runs the Lua code specified by the argument <code class="language-plaintext highlighter-rouge"><lua-script-str></code> on the global Lua VM level when the Nginx master process (if any) is loading the Nginx config file.</p>
|
||
|
||
<p>When Nginx receives the <code class="language-plaintext highlighter-rouge">HUP</code> signal and starts reloading the config file, the Lua VM will also be re-created and <code class="language-plaintext highlighter-rouge">init_by_lua</code> will run again on the new Lua VM. In case that the <a href="#lua_code_cache">lua_code_cache</a> directive is turned off (default on), the <code class="language-plaintext highlighter-rouge">init_by_lua</code> handler will run upon every request because in this special mode a standalone Lua VM is always created for each request.</p>
|
||
|
||
<p>Usually you can register (true) Lua global variables or pre-load Lua modules at server start-up by means of this hook. Here is an example for pre-loading Lua modules:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">init_by_lua</span> <span class="s">'cjson</span> <span class="p">=</span> <span class="s">require</span> <span class="s">"cjson"'</span><span class="p">;</span>
|
||
|
||
<span class="k">server</span> <span class="p">{</span>
|
||
<span class="kn">location</span> <span class="p">=</span> <span class="n">/api</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">ngx.say(cjson.encode(</span><span class="p">{</span><span class="kn">dog</span> <span class="p">=</span> <span class="mi">5</span><span class="s">,</span> <span class="s">cat</span> <span class="p">=</span> <span class="mi">6</span><span class="err">}</span><span class="s">))</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>You can also initialize the <a href="#lua_shared_dict">lua_shared_dict</a> shm storage at this phase. Here is an example for this:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">lua_shared_dict</span> <span class="s">dogs</span> <span class="mi">1m</span><span class="p">;</span>
|
||
|
||
<span class="k">init_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">dogs</span> <span class="p">=</span> <span class="s">ngx.shared.dogs</span><span class="p">;</span>
|
||
<span class="k">dogs:set</span><span class="s">("Tom",</span> <span class="mi">56</span><span class="s">)</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
|
||
<span class="k">server</span> <span class="p">{</span>
|
||
<span class="kn">location</span> <span class="p">=</span> <span class="n">/api</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">dogs</span> <span class="p">=</span> <span class="s">ngx.shared.dogs</span><span class="p">;</span>
|
||
<span class="kn">ngx.say</span><span class="s">(dogs:get("Tom"))</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>But note that, the <a href="#lua_shared_dict">lua_shared_dict</a>’s shm storage will not be cleared through a config reload (via the <code class="language-plaintext highlighter-rouge">HUP</code> signal, for example). So if you do <em>not</em> want to re-initialize the shm storage in your <code class="language-plaintext highlighter-rouge">init_by_lua</code> code in this case, then you just need to set a custom flag in the shm storage and always check the flag in your <code class="language-plaintext highlighter-rouge">init_by_lua</code> code.</p>
|
||
|
||
<p>Because the Lua code in this context runs before Nginx forks its worker processes (if any), data or code loaded here will enjoy the <a href="http://en.wikipedia.org/wiki/Copy-on-write">Copy-on-write (COW)</a> feature provided by many operating systems among all the worker processes, thus saving a lot of memory.</p>
|
||
|
||
<p>Do <em>not</em> initialize your own Lua global variables in this context because use of Lua global variables have performance penalties and can lead to global namespace pollution (see the <a href="#lua-variable-scope">Lua Variable Scope</a> section for more details). The recommended way is to use proper <a href="http://www.lua.org/manual/5.1/manual.html#5.3">Lua module</a> files (but do not use the standard Lua function <a href="http://www.lua.org/manual/5.1/manual.html#pdf-module">module()</a> to define Lua modules because it pollutes the global namespace as well) and call <a href="http://www.lua.org/manual/5.1/manual.html#pdf-require">require()</a> to load your own module files in <code class="language-plaintext highlighter-rouge">init_by_lua</code> or other contexts (<a href="http://www.lua.org/manual/5.1/manual.html#pdf-require">require()</a> does cache the loaded Lua modules in the global <code class="language-plaintext highlighter-rouge">package.loaded</code> table in the Lua registry so your modules will only loaded once for the whole Lua VM instance).</p>
|
||
|
||
<p>Only a small set of the <a href="#nginx-api-for-lua">Nginx API for Lua</a> is supported in this context:</p>
|
||
|
||
<ul>
|
||
<li>Logging APIs: <a href="#ngxlog">ngx.log</a> and <a href="#print">print</a>,</li>
|
||
<li>Shared Dictionary API: <a href="#ngxshareddict">ngx.shared.DICT</a>.</li>
|
||
</ul>
|
||
|
||
<p>More Nginx APIs for Lua may be supported in this context upon future user requests.</p>
|
||
|
||
<p>Basically you can safely use Lua libraries that do blocking I/O in this very context because blocking the master process during server start-up is completely okay. Even the Nginx core does blocking I/O (at least on resolving upstream’s host names) at the configure-loading phase.</p>
|
||
|
||
<p>You should be very careful about potential security vulnerabilities in your Lua code registered in this context because the Nginx master process is often run under the <code class="language-plaintext highlighter-rouge">root</code> account.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.5</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="init_by_lua_file">init_by_lua_file</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>init_by_lua_file <path-to-lua-script-file></em></p>
|
||
|
||
<p><strong>context:</strong> <em>http</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>loading-config</em></p>
|
||
|
||
<p>Equivalent to <a href="#init_by_lua">init_by_lua</a>, except that the file specified by <code class="language-plaintext highlighter-rouge"><path-to-lua-script-file></code> contains the Lua code or <a href="#lualuajit-bytecode-support">Lua/LuaJIT bytecode</a> to be executed.</p>
|
||
|
||
<p>When a relative path like <code class="language-plaintext highlighter-rouge">foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code class="language-plaintext highlighter-rouge">server prefix</code> path determined by the <code class="language-plaintext highlighter-rouge">-p PATH</code> command-line option while starting the Nginx server.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.5</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="init_worker_by_lua">init_worker_by_lua</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>init_worker_by_lua <lua-script-str></em></p>
|
||
|
||
<p><strong>context:</strong> <em>http</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>starting-worker</em></p>
|
||
|
||
<p>Runs the specified Lua code upon every Nginx worker process’s startup when the master process is enabled. When the master process is disabled, this hook will just run after <a href="#init_by_lua">init_by_lua*</a>.</p>
|
||
|
||
<p>This hook is often used to create per-worker reoccurring timers (via the <a href="#ngxtimerat">ngx.timer.at</a> Lua API), either for backend healthcheck or other timed routine work. Below is an example,</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">init_worker_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">delay</span> <span class="p">=</span> <span class="mi">3</span> <span class="s">--</span> <span class="s">in</span> <span class="s">seconds</span>
|
||
<span class="s">local</span> <span class="s">new_timer</span> <span class="p">=</span> <span class="s">ngx.timer.at</span>
|
||
<span class="s">local</span> <span class="s">log</span> <span class="p">=</span> <span class="s">ngx.log</span>
|
||
<span class="s">local</span> <span class="s">ERR</span> <span class="p">=</span> <span class="s">ngx.ERR</span>
|
||
<span class="s">local</span> <span class="s">check</span>
|
||
|
||
<span class="s">check</span> <span class="p">=</span> <span class="s">function(premature)</span>
|
||
<span class="s">if</span> <span class="s">not</span> <span class="s">premature</span> <span class="s">then</span>
|
||
<span class="s">--</span> <span class="s">do</span> <span class="s">the</span> <span class="s">health</span> <span class="s">check</span> <span class="s">or</span> <span class="s">other</span> <span class="s">routine</span> <span class="s">work</span>
|
||
<span class="s">local</span> <span class="s">ok,</span> <span class="s">err</span> <span class="p">=</span> <span class="s">new_timer(delay,</span> <span class="s">check)</span>
|
||
<span class="s">if</span> <span class="s">not</span> <span class="s">ok</span> <span class="s">then</span>
|
||
<span class="s">log(ERR,</span> <span class="s">"failed</span> <span class="s">to</span> <span class="s">create</span> <span class="s">timer:</span> <span class="s">",</span> <span class="s">err)</span>
|
||
<span class="s">return</span>
|
||
<span class="s">end</span>
|
||
<span class="s">end</span>
|
||
<span class="s">end</span>
|
||
|
||
<span class="s">local</span> <span class="s">ok,</span> <span class="s">err</span> <span class="p">=</span> <span class="s">new_timer(delay,</span> <span class="s">check)</span>
|
||
<span class="s">if</span> <span class="s">not</span> <span class="s">ok</span> <span class="s">then</span>
|
||
<span class="s">log(ERR,</span> <span class="s">"failed</span> <span class="s">to</span> <span class="s">create</span> <span class="s">timer:</span> <span class="s">",</span> <span class="s">err)</span>
|
||
<span class="s">return</span>
|
||
<span class="s">end</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.9.5</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="init_worker_by_lua_file">init_worker_by_lua_file</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>init_worker_by_lua_file <lua-file-path></em></p>
|
||
|
||
<p><strong>context:</strong> <em>http</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>starting-worker</em></p>
|
||
|
||
<p>Similar to <a href="#init_worker_by_lua">init_worker_by_lua</a>, but accepts the file path to a Lua source file or Lua bytecode file.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.9.5</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="set_by_lua">set_by_lua</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>set_by_lua $res <lua-script-str> [$arg1 $arg2 …]</em></p>
|
||
|
||
<p><strong>context:</strong> <em>server, server if, location, location if</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>rewrite</em></p>
|
||
|
||
<p>Executes code specified in <code class="language-plaintext highlighter-rouge"><lua-script-str></code> with optional input arguments <code class="language-plaintext highlighter-rouge">$arg1 $arg2 ...</code>, and returns string output to <code class="language-plaintext highlighter-rouge">$res</code>.
|
||
The code in <code class="language-plaintext highlighter-rouge"><lua-script-str></code> can make <a href="#nginx-api-for-lua">API calls</a> and can retrieve input arguments from the <code class="language-plaintext highlighter-rouge">ngx.arg</code> table (index starts from <code class="language-plaintext highlighter-rouge">1</code> and increases sequentially).</p>
|
||
|
||
<p>This directive is designed to execute short, fast running code blocks as the Nginx event loop is blocked during code execution. Time consuming code sequences should therefore be avoided.</p>
|
||
|
||
<p>This directive is implemented by injecting custom commands into the standard <a href="http://nginx.org/en/docs/http/ngx_http_rewrite_module.html">ngx_http_rewrite_module</a>’s command list. Because <a href="http://nginx.org/en/docs/http/ngx_http_rewrite_module.html">ngx_http_rewrite_module</a> does not support nonblocking I/O in its commands, Lua APIs requiring yielding the current Lua “light thread” cannot work in this directive.</p>
|
||
|
||
<p>At least the following API functions are currently disabled within the context of <code class="language-plaintext highlighter-rouge">set_by_lua</code>:</p>
|
||
|
||
<ul>
|
||
<li>Output API functions (e.g., <a href="#ngxsay">ngx.say</a> and <a href="#ngxsend_headers">ngx.send_headers</a>)</li>
|
||
<li>Control API functions (e.g., <a href="#ngxexit">ngx.exit</a>)</li>
|
||
<li>Subrequest API functions (e.g., <a href="#ngxlocationcapture">ngx.location.capture</a> and <a href="#ngxlocationcapture_multi">ngx.location.capture_multi</a>)</li>
|
||
<li>Cosocket API functions (e.g., <a href="#ngxsockettcp">ngx.socket.tcp</a> and <a href="#ngxreqsocket">ngx.req.socket</a>).</li>
|
||
<li>Sleeping API function <a href="#ngxsleep">ngx.sleep</a>.</li>
|
||
</ul>
|
||
|
||
<p>In addition, note that this directive can only write out a value to a single Nginx variable at
|
||
a time. However, a workaround is possible using the <a href="#ngxvarvariable">ngx.var.VARIABLE</a> interface.</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/foo</span> <span class="p">{</span>
|
||
<span class="kn">set</span> <span class="nv">$diff</span> <span class="s">''</span><span class="p">;</span> <span class="c1"># we have to predefine the $diff variable here</span>
|
||
|
||
<span class="kn">set_by_lua</span> <span class="nv">$sum</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">a</span> <span class="p">=</span> <span class="mi">32</span>
|
||
<span class="s">local</span> <span class="s">b</span> <span class="p">=</span> <span class="mi">56</span>
|
||
|
||
<span class="s">ngx.var.diff</span> <span class="p">=</span> <span class="s">a</span> <span class="s">-</span> <span class="s">b</span><span class="p">;</span> <span class="kn">--</span> <span class="s">write</span> <span class="s">to</span> <span class="nv">$diff</span> <span class="s">directly</span>
|
||
<span class="s">return</span> <span class="s">a</span> <span class="s">+</span> <span class="s">b</span><span class="p">;</span> <span class="kn">--</span> <span class="s">return</span> <span class="s">the</span> <span class="nv">$sum</span> <span class="s">value</span> <span class="s">normally</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
|
||
<span class="kn">echo</span> <span class="s">"sum</span> <span class="p">=</span> <span class="nv">$sum</span><span class="s">,</span> <span class="s">diff</span> <span class="p">=</span> <span class="nv">$diff</span><span class="s">"</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This directive can be freely mixed with all directives of the <a href="http://nginx.org/en/docs/http/ngx_http_rewrite_module.html">ngx_http_rewrite_module</a>, <a href="http://github.com/openresty/set-misc-nginx-module">set-misc-nginx-module</a>, and <a href="http://github.com/openresty/array-var-nginx-module">array-var-nginx-module</a> modules. All of these directives will run in the same order as they appear in the config file.</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">set</span> <span class="nv">$foo</span> <span class="mi">32</span><span class="p">;</span>
|
||
<span class="k">set_by_lua</span> <span class="nv">$bar</span> <span class="s">'tonumber(ngx.var.foo)</span> <span class="s">+</span> <span class="mi">1</span><span class="s">'</span><span class="p">;</span>
|
||
<span class="k">set</span> <span class="nv">$baz</span> <span class="s">"bar:</span> <span class="nv">$bar</span><span class="s">"</span><span class="p">;</span> <span class="c1"># $baz == "bar: 33"</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>As from the <code class="language-plaintext highlighter-rouge">v0.5.0rc29</code> release, Nginx variable interpolation is disabled in the <code class="language-plaintext highlighter-rouge"><lua-script-str></code> argument of this directive and therefore, the dollar sign character (<code class="language-plaintext highlighter-rouge">$</code>) can be used directly.</p>
|
||
|
||
<p>This directive requires the <a href="https://github.com/simpl/ngx_devel_kit">ngx_devel_kit</a> module.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="set_by_lua_file">set_by_lua_file</h2>
|
||
<p><strong>syntax:</strong> <em>set_by_lua_file $res <path-to-lua-script-file> [$arg1 $arg2 …]</em></p>
|
||
|
||
<p><strong>context:</strong> <em>server, server if, location, location if</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>rewrite</em></p>
|
||
|
||
<p>Equivalent to <a href="#set_by_lua">set_by_lua</a>, except that the file specified by <code class="language-plaintext highlighter-rouge"><path-to-lua-script-file></code> contains the Lua code, or, as from the <code class="language-plaintext highlighter-rouge">v0.5.0rc32</code> release, the <a href="#lualuajit-bytecode-support">Lua/LuaJIT bytecode</a> to be executed.</p>
|
||
|
||
<p>Nginx variable interpolation is supported in the <code class="language-plaintext highlighter-rouge"><path-to-lua-script-file></code> argument string of this directive. But special care must be taken for injection attacks.</p>
|
||
|
||
<p>When a relative path like <code class="language-plaintext highlighter-rouge">foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code class="language-plaintext highlighter-rouge">server prefix</code> path determined by the <code class="language-plaintext highlighter-rouge">-p PATH</code> command-line option while starting the Nginx server.</p>
|
||
|
||
<p>When the Lua code cache is turned on (by default), the user code is loaded once at the first request and cached
|
||
and the Nginx config must be reloaded each time the Lua source file is modified.
|
||
The Lua code cache can be temporarily disabled during development by
|
||
switching <a href="#lua_code_cache">lua_code_cache</a> <code class="language-plaintext highlighter-rouge">off</code> in <code class="language-plaintext highlighter-rouge">nginx.conf</code> to avoid reloading Nginx.</p>
|
||
|
||
<p>This directive requires the <a href="https://github.com/simpl/ngx_devel_kit">ngx_devel_kit</a> module.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="content_by_lua">content_by_lua</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>content_by_lua <lua-script-str></em></p>
|
||
|
||
<p><strong>context:</strong> <em>location, location if</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>content</em></p>
|
||
|
||
<p>Acts as a “content handler” and executes Lua code string specified in <code class="language-plaintext highlighter-rouge"><lua-script-str></code> for every request.
|
||
The Lua code may make <a href="#nginx-api-for-lua">API calls</a> and is executed as a new spawned coroutine in an independent global environment (i.e. a sandbox).</p>
|
||
|
||
<p>Do not use this directive and other content handler directives in the same location. For example, this directive and the <a href="http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass">proxy_pass</a> directive should not be used in the same location.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="content_by_lua_file">content_by_lua_file</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>content_by_lua_file <path-to-lua-script-file></em></p>
|
||
|
||
<p><strong>context:</strong> <em>location, location if</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>content</em></p>
|
||
|
||
<p>Equivalent to <a href="#content_by_lua">content_by_lua</a>, except that the file specified by <code class="language-plaintext highlighter-rouge"><path-to-lua-script-file></code> contains the Lua code, or, as from the <code class="language-plaintext highlighter-rouge">v0.5.0rc32</code> release, the <a href="#lualuajit-bytecode-support">Lua/LuaJIT bytecode</a> to be executed.</p>
|
||
|
||
<p>Nginx variables can be used in the <code class="language-plaintext highlighter-rouge"><path-to-lua-script-file></code> string to provide flexibility. This however carries some risks and is not ordinarily recommended.</p>
|
||
|
||
<p>When a relative path like <code class="language-plaintext highlighter-rouge">foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code class="language-plaintext highlighter-rouge">server prefix</code> path determined by the <code class="language-plaintext highlighter-rouge">-p PATH</code> command-line option while starting the Nginx server.</p>
|
||
|
||
<p>When the Lua code cache is turned on (by default), the user code is loaded once at the first request and cached
|
||
and the Nginx config must be reloaded each time the Lua source file is modified.
|
||
The Lua code cache can be temporarily disabled during development by
|
||
switching <a href="#lua_code_cache">lua_code_cache</a> <code class="language-plaintext highlighter-rouge">off</code> in <code class="language-plaintext highlighter-rouge">nginx.conf</code> to avoid reloading Nginx.</p>
|
||
|
||
<p>Nginx variables are supported in the file path for dynamic dispatch, for example:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="c1"># WARNING: contents in nginx var must be carefully filtered,</span>
|
||
<span class="c1"># otherwise there'll be great security risk!</span>
|
||
<span class="k">location</span> <span class="p">~</span> <span class="sr">^/app/([-_a-zA-Z0-9/]+)</span> <span class="p">{</span>
|
||
<span class="kn">set</span> <span class="nv">$path</span> <span class="nv">$1</span><span class="p">;</span>
|
||
<span class="kn">content_by_lua_file</span> <span class="n">/path/to/lua/app/root/</span><span class="nv">$path</span><span class="s">.lua</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>But be very careful about malicious user inputs and always carefully validate or filter out the user-supplied path components.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="rewrite_by_lua">rewrite_by_lua</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>rewrite_by_lua <lua-script-str></em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location, location if</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>rewrite tail</em></p>
|
||
|
||
<p>Acts as a rewrite phase handler and executes Lua code string specified in <code class="language-plaintext highlighter-rouge"><lua-script-str></code> for every request.
|
||
The Lua code may make <a href="#nginx-api-for-lua">API calls</a> and is executed as a new spawned coroutine in an independent global environment (i.e. a sandbox).</p>
|
||
|
||
<p>Note that this handler always runs <em>after</em> the standard <a href="http://nginx.org/en/docs/http/ngx_http_rewrite_module.html">ngx_http_rewrite_module</a>. So the following will work as expected:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/foo</span> <span class="p">{</span>
|
||
<span class="kn">set</span> <span class="nv">$a</span> <span class="mi">12</span><span class="p">;</span> <span class="c1"># create and initialize $a</span>
|
||
<span class="kn">set</span> <span class="nv">$b</span> <span class="s">""</span><span class="p">;</span> <span class="c1"># create and initialize $b</span>
|
||
<span class="kn">rewrite_by_lua</span> <span class="s">'ngx.var.b</span> <span class="p">=</span> <span class="s">tonumber(ngx.var.a)</span> <span class="s">+</span> <span class="mi">1</span><span class="s">'</span><span class="p">;</span>
|
||
<span class="kn">echo</span> <span class="s">"res</span> <span class="p">=</span> <span class="nv">$b</span><span class="s">"</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>because <code class="language-plaintext highlighter-rouge">set $a 12</code> and <code class="language-plaintext highlighter-rouge">set $b ""</code> run <em>before</em> <a href="#rewrite_by_lua">rewrite_by_lua</a>.</p>
|
||
|
||
<p>On the other hand, the following will not work as expected:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">?</span> <span class="s">location</span> <span class="n">/foo</span> <span class="p">{</span>
|
||
<span class="kn">?</span> <span class="s">set</span> <span class="nv">$a</span> <span class="mi">12</span><span class="p">;</span> <span class="c1"># create and initialize $a</span>
|
||
<span class="kn">?</span> <span class="s">set</span> <span class="nv">$b</span> <span class="s">''</span><span class="p">;</span> <span class="c1"># create and initialize $b</span>
|
||
<span class="kn">?</span> <span class="s">rewrite_by_lua</span> <span class="s">'ngx.var.b</span> <span class="p">=</span> <span class="s">tonumber(ngx.var.a)</span> <span class="s">+</span> <span class="mi">1</span><span class="s">'</span><span class="p">;</span>
|
||
<span class="kn">?</span> <span class="s">if</span> <span class="s">(</span><span class="nv">$b</span> <span class="p">=</span> <span class="s">'13')</span> <span class="p">{</span>
|
||
<span class="kn">?</span> <span class="s">rewrite</span> <span class="s">^</span> <span class="n">/bar</span> <span class="s">redirect</span><span class="p">;</span>
|
||
<span class="kn">?</span> <span class="s">break</span><span class="p">;</span>
|
||
<span class="kn">?</span> <span class="err">}</span>
|
||
<span class="s">?</span>
|
||
<span class="s">?</span> <span class="s">echo</span> <span class="s">"res</span> <span class="p">=</span> <span class="nv">$b</span><span class="s">"</span><span class="p">;</span>
|
||
<span class="kn">?</span> <span class="err">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>because <code class="language-plaintext highlighter-rouge">if</code> runs <em>before</em> <a href="#rewrite_by_lua">rewrite_by_lua</a> even if it is placed after <a href="#rewrite_by_lua">rewrite_by_lua</a> in the config.</p>
|
||
|
||
<p>The right way of doing this is as follows:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/foo</span> <span class="p">{</span>
|
||
<span class="kn">set</span> <span class="nv">$a</span> <span class="mi">12</span><span class="p">;</span> <span class="c1"># create and initialize $a</span>
|
||
<span class="kn">set</span> <span class="nv">$b</span> <span class="s">''</span><span class="p">;</span> <span class="c1"># create and initialize $b</span>
|
||
<span class="kn">rewrite_by_lua</span> <span class="s">'</span>
|
||
<span class="s">ngx.var.b</span> <span class="p">=</span> <span class="s">tonumber(ngx.var.a)</span> <span class="s">+</span> <span class="mi">1</span>
|
||
<span class="s">if</span> <span class="s">tonumber(ngx.var.b)</span> <span class="p">==</span> <span class="mi">13</span> <span class="s">then</span>
|
||
<span class="s">return</span> <span class="s">ngx.redirect("/bar")</span><span class="p">;</span>
|
||
<span class="kn">end</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
|
||
<span class="kn">echo</span> <span class="s">"res</span> <span class="p">=</span> <span class="nv">$b</span><span class="s">"</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Note that the <a href="http://www.grid.net.ru/nginx/eval.en.html">ngx_eval</a> module can be approximated by using <a href="#rewrite_by_lua">rewrite_by_lua</a>. For example,</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/</span> <span class="p">{</span>
|
||
<span class="kn">eval</span> <span class="nv">$res</span> <span class="p">{</span>
|
||
<span class="kn">proxy_pass</span> <span class="s">http://foo.com/check-spam</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="kn">if</span> <span class="s">(</span><span class="nv">$res</span> <span class="p">=</span> <span class="s">'spam')</span> <span class="p">{</span>
|
||
<span class="kn">rewrite</span> <span class="s">^</span> <span class="n">/terms-of-use.html</span> <span class="s">redirect</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="kn">fastcgi_pass</span> <span class="s">...</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>can be implemented in ngx_lua as:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="p">=</span> <span class="n">/check-spam</span> <span class="p">{</span>
|
||
<span class="kn">internal</span><span class="p">;</span>
|
||
<span class="kn">proxy_pass</span> <span class="s">http://foo.com/check-spam</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="k">location</span> <span class="n">/</span> <span class="p">{</span>
|
||
<span class="kn">rewrite_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">res</span> <span class="p">=</span> <span class="s">ngx.location.capture("/check-spam")</span>
|
||
<span class="s">if</span> <span class="s">res.body</span> <span class="p">==</span> <span class="s">"spam"</span> <span class="s">then</span>
|
||
<span class="s">return</span> <span class="s">ngx.redirect("/terms-of-use.html")</span>
|
||
<span class="s">end</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
|
||
<span class="kn">fastcgi_pass</span> <span class="s">...</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Just as any other rewrite phase handlers, <a href="#rewrite_by_lua">rewrite_by_lua</a> also runs in subrequests.</p>
|
||
|
||
<p>Note that when calling <code class="language-plaintext highlighter-rouge">ngx.exit(ngx.OK)</code> within a <a href="#rewrite_by_lua">rewrite_by_lua</a> handler, the nginx request processing control flow will still continue to the content handler. To terminate the current request from within a <a href="#rewrite_by_lua">rewrite_by_lua</a> handler, calling <a href="#ngxexit">ngx.exit</a> with status >= 200 (<code class="language-plaintext highlighter-rouge">ngx.HTTP_OK</code>) and status < 300 (<code class="language-plaintext highlighter-rouge">ngx.HTTP_SPECIAL_RESPONSE</code>) for successful quits and <code class="language-plaintext highlighter-rouge">ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)</code> (or its friends) for failures.</p>
|
||
|
||
<p>If the <a href="http://nginx.org/en/docs/http/ngx_http_rewrite_module.html">ngx_http_rewrite_module</a>’s <a href="http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite">rewrite</a> directive is used to change the URI and initiate location re-lookups (internal redirections), then any <a href="#rewrite_by_lua">rewrite_by_lua</a> or <a href="#rewrite_by_lua_file">rewrite_by_lua_file</a> code sequences within the current location will not be executed. For example,</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/foo</span> <span class="p">{</span>
|
||
<span class="kn">rewrite</span> <span class="s">^</span> <span class="n">/bar</span><span class="p">;</span>
|
||
<span class="kn">rewrite_by_lua</span> <span class="s">'ngx.exit(503)'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="k">location</span> <span class="n">/bar</span> <span class="p">{</span>
|
||
<span class="kn">...</span>
|
||
<span class="err">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Here the Lua code <code class="language-plaintext highlighter-rouge">ngx.exit(503)</code> will never run. This will be the case if <code class="language-plaintext highlighter-rouge">rewrite ^ /bar last</code> is used as this will similarly initiate an internal redirection. If the <code class="language-plaintext highlighter-rouge">break</code> modifier is used instead, there will be no internal redirection and the <code class="language-plaintext highlighter-rouge">rewrite_by_lua</code> code will be executed.</p>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">rewrite_by_lua</code> code will always run at the end of the <code class="language-plaintext highlighter-rouge">rewrite</code> request-processing phase unless <a href="#rewrite_by_lua_no_postpone">rewrite_by_lua_no_postpone</a> is turned on.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="rewrite_by_lua_file">rewrite_by_lua_file</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>rewrite_by_lua_file <path-to-lua-script-file></em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location, location if</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>rewrite tail</em></p>
|
||
|
||
<p>Equivalent to <a href="#rewrite_by_lua">rewrite_by_lua</a>, except that the file specified by <code class="language-plaintext highlighter-rouge"><path-to-lua-script-file></code> contains the Lua code, or, as from the <code class="language-plaintext highlighter-rouge">v0.5.0rc32</code> release, the <a href="#lualuajit-bytecode-support">Lua/LuaJIT bytecode</a> to be executed.</p>
|
||
|
||
<p>Nginx variables can be used in the <code class="language-plaintext highlighter-rouge"><path-to-lua-script-file></code> string to provide flexibility. This however carries some risks and is not ordinarily recommended.</p>
|
||
|
||
<p>When a relative path like <code class="language-plaintext highlighter-rouge">foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code class="language-plaintext highlighter-rouge">server prefix</code> path determined by the <code class="language-plaintext highlighter-rouge">-p PATH</code> command-line option while starting the Nginx server.</p>
|
||
|
||
<p>When the Lua code cache is turned on (by default), the user code is loaded once at the first request and cached and the Nginx config must be reloaded each time the Lua source file is modified. The Lua code cache can be temporarily disabled during development by switching <a href="#lua_code_cache">lua_code_cache</a> <code class="language-plaintext highlighter-rouge">off</code> in <code class="language-plaintext highlighter-rouge">nginx.conf</code> to avoid reloading Nginx.</p>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">rewrite_by_lua_file</code> code will always run at the end of the <code class="language-plaintext highlighter-rouge">rewrite</code> request-processing phase unless <a href="#rewrite_by_lua_no_postpone">rewrite_by_lua_no_postpone</a> is turned on.</p>
|
||
|
||
<p>Nginx variables are supported in the file path for dynamic dispatch just as in <a href="#content_by_lua_file">content_by_lua_file</a>.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="access_by_lua">access_by_lua</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>access_by_lua <lua-script-str></em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location, location if</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>access tail</em></p>
|
||
|
||
<p>Acts as an access phase handler and executes Lua code string specified in <code class="language-plaintext highlighter-rouge"><lua-script-str></code> for every request.
|
||
The Lua code may make <a href="#nginx-api-for-lua">API calls</a> and is executed as a new spawned coroutine in an independent global environment (i.e. a sandbox).</p>
|
||
|
||
<p>Note that this handler always runs <em>after</em> the standard <a href="http://nginx.org/en/docs/http/ngx_http_access_module.html">ngx_http_access_module</a>. So the following will work as expected:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/</span> <span class="p">{</span>
|
||
<span class="kn">deny</span> <span class="mf">192.168</span><span class="s">.1.1</span><span class="p">;</span>
|
||
<span class="kn">allow</span> <span class="mf">192.168</span><span class="s">.1.0/24</span><span class="p">;</span>
|
||
<span class="kn">allow</span> <span class="mf">10.1</span><span class="s">.1.0/16</span><span class="p">;</span>
|
||
<span class="kn">deny</span> <span class="s">all</span><span class="p">;</span>
|
||
|
||
<span class="kn">access_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">res</span> <span class="p">=</span> <span class="s">ngx.location.capture("/mysql",</span> <span class="p">{</span> <span class="kn">...</span> <span class="err">}</span><span class="s">)</span>
|
||
<span class="s">...</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
|
||
<span class="c1"># proxy_pass/fastcgi_pass/...</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>That is, if a client IP address is in the blacklist, it will be denied before the MySQL query for more complex authentication is executed by <a href="#access_by_lua">access_by_lua</a>.</p>
|
||
|
||
<p>Note that the <a href="http://mdounin.ru/hg/ngx_http_auth_request_module/">ngx_auth_request</a> module can be approximated by using <a href="#access_by_lua">access_by_lua</a>:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/</span> <span class="p">{</span>
|
||
<span class="kn">auth_request</span> <span class="n">/auth</span><span class="p">;</span>
|
||
|
||
<span class="c1"># proxy_pass/fastcgi_pass/postgres_pass/...</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>can be implemented in ngx_lua as:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/</span> <span class="p">{</span>
|
||
<span class="kn">access_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">res</span> <span class="p">=</span> <span class="s">ngx.location.capture("/auth")</span>
|
||
|
||
<span class="s">if</span> <span class="s">res.status</span> <span class="p">==</span> <span class="s">ngx.HTTP_OK</span> <span class="s">then</span>
|
||
<span class="s">return</span>
|
||
<span class="s">end</span>
|
||
|
||
<span class="s">if</span> <span class="s">res.status</span> <span class="p">==</span> <span class="s">ngx.HTTP_FORBIDDEN</span> <span class="s">then</span>
|
||
<span class="s">ngx.exit(res.status)</span>
|
||
<span class="s">end</span>
|
||
|
||
<span class="s">ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
|
||
<span class="c1"># proxy_pass/fastcgi_pass/postgres_pass/...</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>As with other access phase handlers, <a href="#access_by_lua">access_by_lua</a> will <em>not</em> run in subrequests.</p>
|
||
|
||
<p>Note that when calling <code class="language-plaintext highlighter-rouge">ngx.exit(ngx.OK)</code> within a <a href="#access_by_lua">access_by_lua</a> handler, the nginx request processing control flow will still continue to the content handler. To terminate the current request from within a <a href="#access_by_lua">access_by_lua</a> handler, calling <a href="#ngxexit">ngx.exit</a> with status >= 200 (<code class="language-plaintext highlighter-rouge">ngx.HTTP_OK</code>) and status < 300 (<code class="language-plaintext highlighter-rouge">ngx.HTTP_SPECIAL_RESPONSE</code>) for successful quits and <code class="language-plaintext highlighter-rouge">ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)</code> (or its friends) for failures.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="access_by_lua_file">access_by_lua_file</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>access_by_lua_file <path-to-lua-script-file></em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location, location if</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>access tail</em></p>
|
||
|
||
<p>Equivalent to <a href="#access_by_lua">access_by_lua</a>, except that the file specified by <code class="language-plaintext highlighter-rouge"><path-to-lua-script-file></code> contains the Lua code, or, as from the <code class="language-plaintext highlighter-rouge">v0.5.0rc32</code> release, the <a href="#lualuajit-bytecode-support">Lua/LuaJIT bytecode</a> to be executed.</p>
|
||
|
||
<p>Nginx variables can be used in the <code class="language-plaintext highlighter-rouge"><path-to-lua-script-file></code> string to provide flexibility. This however carries some risks and is not ordinarily recommended.</p>
|
||
|
||
<p>When a relative path like <code class="language-plaintext highlighter-rouge">foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code class="language-plaintext highlighter-rouge">server prefix</code> path determined by the <code class="language-plaintext highlighter-rouge">-p PATH</code> command-line option while starting the Nginx server.</p>
|
||
|
||
<p>When the Lua code cache is turned on (by default), the user code is loaded once at the first request and cached
|
||
and the Nginx config must be reloaded each time the Lua source file is modified.
|
||
The Lua code cache can be temporarily disabled during development by switching <a href="#lua_code_cache">lua_code_cache</a> <code class="language-plaintext highlighter-rouge">off</code> in <code class="language-plaintext highlighter-rouge">nginx.conf</code> to avoid repeatedly reloading Nginx.</p>
|
||
|
||
<p>Nginx variables are supported in the file path for dynamic dispatch just as in <a href="#content_by_lua_file">content_by_lua_file</a>.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="header_filter_by_lua">header_filter_by_lua</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>header_filter_by_lua <lua-script-str></em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location, location if</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>output-header-filter</em></p>
|
||
|
||
<p>Uses Lua code specified in <code class="language-plaintext highlighter-rouge"><lua-script-str></code> to define an output header filter.</p>
|
||
|
||
<p>Note that the following API functions are currently disabled within this context:</p>
|
||
|
||
<ul>
|
||
<li>Output API functions (e.g., <a href="#ngxsay">ngx.say</a> and <a href="#ngxsend_headers">ngx.send_headers</a>)</li>
|
||
<li>Control API functions (e.g., <a href="#ngxredirect">ngx.redirect</a> and <a href="#ngxexec">ngx.exec</a>)</li>
|
||
<li>Subrequest API functions (e.g., <a href="#ngxlocationcapture">ngx.location.capture</a> and <a href="#ngxlocationcapture_multi">ngx.location.capture_multi</a>)</li>
|
||
<li>Cosocket API functions (e.g., <a href="#ngxsockettcp">ngx.socket.tcp</a> and <a href="#ngxreqsocket">ngx.req.socket</a>).</li>
|
||
</ul>
|
||
|
||
<p>Here is an example of overriding a response header (or adding one if absent) in our Lua header filter:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/</span> <span class="p">{</span>
|
||
<span class="kn">proxy_pass</span> <span class="s">http://mybackend</span><span class="p">;</span>
|
||
<span class="kn">header_filter_by_lua</span> <span class="s">'ngx.header.Foo</span> <span class="p">=</span> <span class="s">"blah"'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.2.1rc20</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="header_filter_by_lua_file">header_filter_by_lua_file</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>header_filter_by_lua_file <path-to-lua-script-file></em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location, location if</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>output-header-filter</em></p>
|
||
|
||
<p>Equivalent to <a href="#header_filter_by_lua">header_filter_by_lua</a>, except that the file specified by <code class="language-plaintext highlighter-rouge"><path-to-lua-script-file></code> contains the Lua code, or as from the <code class="language-plaintext highlighter-rouge">v0.5.0rc32</code> release, the <a href="#lualuajit-bytecode-support">Lua/LuaJIT bytecode</a> to be executed.</p>
|
||
|
||
<p>When a relative path like <code class="language-plaintext highlighter-rouge">foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code class="language-plaintext highlighter-rouge">server prefix</code> path determined by the <code class="language-plaintext highlighter-rouge">-p PATH</code> command-line option while starting the Nginx server.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.2.1rc20</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="body_filter_by_lua">body_filter_by_lua</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>body_filter_by_lua <lua-script-str></em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location, location if</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>output-body-filter</em></p>
|
||
|
||
<p>Uses Lua code specified in <code class="language-plaintext highlighter-rouge"><lua-script-str></code> to define an output body filter.</p>
|
||
|
||
<p>The input data chunk is passed via <a href="#ngxarg">ngx.arg</a>[1] (as a Lua string value) and the “eof” flag indicating the end of the response body data stream is passed via <a href="#ngxarg">ngx.arg</a>[2] (as a Lua boolean value).</p>
|
||
|
||
<p>Behind the scene, the “eof” flag is just the <code class="language-plaintext highlighter-rouge">last_buf</code> (for main requests) or <code class="language-plaintext highlighter-rouge">last_in_chain</code> (for subrequests) flag of the Nginx chain link buffers. (Before the <code class="language-plaintext highlighter-rouge">v0.7.14</code> release, the “eof” flag does not work at all in subrequests.)</p>
|
||
|
||
<p>The output data stream can be aborted immediately by running the following Lua statement:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">return</span> <span class="n">ngx</span><span class="p">.</span><span class="n">ERROR</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This will truncate the response body and usually result in incomplete and also invalid responses.</p>
|
||
|
||
<p>The Lua code can pass its own modified version of the input data chunk to the downstream Nginx output body filters by overriding <a href="#ngxarg">ngx.arg</a>[1] with a Lua string or a Lua table of strings. For example, to transform all the lowercase letters in the response body, we can just write:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/</span> <span class="p">{</span>
|
||
<span class="kn">proxy_pass</span> <span class="s">http://mybackend</span><span class="p">;</span>
|
||
<span class="kn">body_filter_by_lua</span> <span class="s">'ngx.arg[1]</span> <span class="p">=</span> <span class="s">string.upper(ngx.arg[1])'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>When setting <code class="language-plaintext highlighter-rouge">nil</code> or an empty Lua string value to <code class="language-plaintext highlighter-rouge">ngx.arg[1]</code>, no data chunk will be passed to the downstream Nginx output filters at all.</p>
|
||
|
||
<p>Likewise, new “eof” flag can also be specified by setting a boolean value to <a href="#ngxarg">ngx.arg</a>[2]. For example,</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/t</span> <span class="p">{</span>
|
||
<span class="kn">echo</span> <span class="s">hello</span> <span class="s">world</span><span class="p">;</span>
|
||
<span class="kn">echo</span> <span class="s">hiya</span> <span class="s">globe</span><span class="p">;</span>
|
||
|
||
<span class="kn">body_filter_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">chunk</span> <span class="p">=</span> <span class="s">ngx.arg[1]</span>
|
||
<span class="s">if</span> <span class="s">string.match(chunk,</span> <span class="s">"hello")</span> <span class="s">then</span>
|
||
<span class="s">ngx.arg[2]</span> <span class="p">=</span> <span class="s">true</span> <span class="s">--</span> <span class="s">new</span> <span class="s">eof</span>
|
||
<span class="s">return</span>
|
||
<span class="s">end</span>
|
||
|
||
<span class="s">--</span> <span class="s">just</span> <span class="s">throw</span> <span class="s">away</span> <span class="s">any</span> <span class="s">remaining</span> <span class="s">chunk</span> <span class="s">data</span>
|
||
<span class="s">ngx.arg[1]</span> <span class="p">=</span> <span class="s">nil</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Then <code class="language-plaintext highlighter-rouge">GET /t</code> will just return the output</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>hello world
|
||
</code></pre></div></div>
|
||
|
||
<p>That is, when the body filter sees a chunk containing the word “hello”, then it will set the “eof” flag to true immediately, resulting in truncated but still valid responses.</p>
|
||
|
||
<p>When the Lua code may change the length of the response body, then it is required to always clear out the <code class="language-plaintext highlighter-rouge">Content-Length</code> response header (if any) in a header filter to enforce streaming output, as in</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/foo</span> <span class="p">{</span>
|
||
<span class="c1"># fastcgi_pass/proxy_pass/...</span>
|
||
|
||
<span class="kn">header_filter_by_lua</span> <span class="s">'ngx.header.content_length</span> <span class="p">=</span> <span class="s">nil'</span><span class="p">;</span>
|
||
<span class="kn">body_filter_by_lua</span> <span class="s">'ngx.arg[1]</span> <span class="p">=</span> <span class="s">string.len(ngx.arg[1])</span> <span class="s">..</span> <span class="s">"</span><span class="err">\\</span><span class="s">n"'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Note that the following API functions are currently disabled within this context due to the limitations in NGINX output filter’s current implementation:</p>
|
||
|
||
<ul>
|
||
<li>Output API functions (e.g., <a href="#ngxsay">ngx.say</a> and <a href="#ngxsend_headers">ngx.send_headers</a>)</li>
|
||
<li>Control API functions (e.g., <a href="#ngxexit">ngx.exit</a> and <a href="#ngxexec">ngx.exec</a>)</li>
|
||
<li>Subrequest API functions (e.g., <a href="#ngxlocationcapture">ngx.location.capture</a> and <a href="#ngxlocationcapture_multi">ngx.location.capture_multi</a>)</li>
|
||
<li>Cosocket API functions (e.g., <a href="#ngxsockettcp">ngx.socket.tcp</a> and <a href="#ngxreqsocket">ngx.req.socket</a>).</li>
|
||
</ul>
|
||
|
||
<p>Nginx output filters may be called multiple times for a single request because response body may be delivered in chunks. Thus, the Lua code specified by in this directive may also run multiple times in the lifetime of a single HTTP request.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc32</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="body_filter_by_lua_file">body_filter_by_lua_file</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>body_filter_by_lua_file <path-to-lua-script-file></em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location, location if</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>output-body-filter</em></p>
|
||
|
||
<p>Equivalent to <a href="#body_filter_by_lua">body_filter_by_lua</a>, except that the file specified by <code class="language-plaintext highlighter-rouge"><path-to-lua-script-file></code> contains the Lua code, or, as from the <code class="language-plaintext highlighter-rouge">v0.5.0rc32</code> release, the <a href="#lualuajit-bytecode-support">Lua/LuaJIT bytecode</a> to be executed.</p>
|
||
|
||
<p>When a relative path like <code class="language-plaintext highlighter-rouge">foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code class="language-plaintext highlighter-rouge">server prefix</code> path determined by the <code class="language-plaintext highlighter-rouge">-p PATH</code> command-line option while starting the Nginx server.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc32</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="log_by_lua">log_by_lua</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>log_by_lua <lua-script-str></em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location, location if</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>log</em></p>
|
||
|
||
<p>Run the Lua source code inlined as the <code class="language-plaintext highlighter-rouge"><lua-script-str></code> at the <code class="language-plaintext highlighter-rouge">log</code> request processing phase. This does not replace the current access logs, but runs after.</p>
|
||
|
||
<p>Note that the following API functions are currently disabled within this context:</p>
|
||
|
||
<ul>
|
||
<li>Output API functions (e.g., <a href="#ngxsay">ngx.say</a> and <a href="#ngxsend_headers">ngx.send_headers</a>)</li>
|
||
<li>Control API functions (e.g., <a href="#ngxexit">ngx.exit</a>)</li>
|
||
<li>Subrequest API functions (e.g., <a href="#ngxlocationcapture">ngx.location.capture</a> and <a href="#ngxlocationcapture_multi">ngx.location.capture_multi</a>)</li>
|
||
<li>Cosocket API functions (e.g., <a href="#ngxsockettcp">ngx.socket.tcp</a> and <a href="#ngxreqsocket">ngx.req.socket</a>).</li>
|
||
</ul>
|
||
|
||
<p>Here is an example of gathering average data for <a href="http://nginx.org/en/docs/http/ngx_http_upstream_module.html#var_upstream_response_time">$upstream_response_time</a>:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">lua_shared_dict</span> <span class="s">log_dict</span> <span class="mi">5M</span><span class="p">;</span>
|
||
|
||
<span class="k">server</span> <span class="p">{</span>
|
||
<span class="kn">location</span> <span class="n">/</span> <span class="p">{</span>
|
||
<span class="kn">proxy_pass</span> <span class="s">http://mybackend</span><span class="p">;</span>
|
||
|
||
<span class="kn">log_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">log_dict</span> <span class="p">=</span> <span class="s">ngx.shared.log_dict</span>
|
||
<span class="s">local</span> <span class="s">upstream_time</span> <span class="p">=</span> <span class="s">tonumber(ngx.var.upstream_response_time)</span>
|
||
|
||
<span class="s">local</span> <span class="s">sum</span> <span class="p">=</span> <span class="s">log_dict:get("upstream_time-sum")</span> <span class="s">or</span> <span class="mi">0</span>
|
||
<span class="s">sum</span> <span class="p">=</span> <span class="s">sum</span> <span class="s">+</span> <span class="s">upstream_time</span>
|
||
<span class="s">log_dict:set("upstream_time-sum",</span> <span class="s">sum)</span>
|
||
|
||
<span class="s">local</span> <span class="s">newval,</span> <span class="s">err</span> <span class="p">=</span> <span class="s">log_dict:incr("upstream_time-nb",</span> <span class="mi">1</span><span class="s">)</span>
|
||
<span class="s">if</span> <span class="s">not</span> <span class="s">newval</span> <span class="s">and</span> <span class="s">err</span> <span class="p">==</span> <span class="s">"not</span> <span class="s">found"</span> <span class="s">then</span>
|
||
<span class="s">log_dict:add("upstream_time-nb",</span> <span class="mi">0</span><span class="s">)</span>
|
||
<span class="s">log_dict:incr("upstream_time-nb",</span> <span class="mi">1</span><span class="s">)</span>
|
||
<span class="s">end</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="kn">location</span> <span class="p">=</span> <span class="n">/status</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">log_dict</span> <span class="p">=</span> <span class="s">ngx.shared.log_dict</span>
|
||
<span class="s">local</span> <span class="s">sum</span> <span class="p">=</span> <span class="s">log_dict:get("upstream_time-sum")</span>
|
||
<span class="s">local</span> <span class="s">nb</span> <span class="p">=</span> <span class="s">log_dict:get("upstream_time-nb")</span>
|
||
|
||
<span class="s">if</span> <span class="s">nb</span> <span class="s">and</span> <span class="s">sum</span> <span class="s">then</span>
|
||
<span class="s">ngx.say("average</span> <span class="s">upstream</span> <span class="s">response</span> <span class="s">time:</span> <span class="s">",</span> <span class="s">sum</span> <span class="n">/</span> <span class="s">nb,</span>
|
||
<span class="s">"</span> <span class="s">(",</span> <span class="s">nb,</span> <span class="s">"</span> <span class="s">reqs)")</span>
|
||
<span class="s">else</span>
|
||
<span class="s">ngx.say("no</span> <span class="s">data</span> <span class="s">yet")</span>
|
||
<span class="s">end</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc31</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="log_by_lua_file">log_by_lua_file</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>log_by_lua_file <path-to-lua-script-file></em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location, location if</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>log</em></p>
|
||
|
||
<p>Equivalent to <a href="#log_by_lua">log_by_lua</a>, except that the file specified by <code class="language-plaintext highlighter-rouge"><path-to-lua-script-file></code> contains the Lua code, or, as from the <code class="language-plaintext highlighter-rouge">v0.5.0rc32</code> release, the <a href="#lualuajit-bytecode-support">Lua/LuaJIT bytecode</a> to be executed.</p>
|
||
|
||
<p>When a relative path like <code class="language-plaintext highlighter-rouge">foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code class="language-plaintext highlighter-rouge">server prefix</code> path determined by the <code class="language-plaintext highlighter-rouge">-p PATH</code> command-line option while starting the Nginx server.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc31</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_need_request_body">lua_need_request_body</h2>
|
||
|
||
<table>
|
||
<tbody>
|
||
<tr>
|
||
<td><strong>syntax:</strong> *lua_need_request_body <on</td>
|
||
<td>off>*</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<p><strong>default:</strong> <em>off</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location, location if</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>depends on usage</em></p>
|
||
|
||
<p>Determines whether to force the request body data to be read before running rewrite/access/access_by_lua* or not. The Nginx core does not read the client request body by default and if request body data is required, then this directive should be turned <code class="language-plaintext highlighter-rouge">on</code> or the <a href="#ngxreqread_body">ngx.req.read_body</a> function should be called within the Lua code.</p>
|
||
|
||
<p>To read the request body data within the <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#var_request_body">$request_body</a> variable,
|
||
<a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_buffer_size">client_body_buffer_size</a> must have the same value as <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size">client_max_body_size</a>. Because when the content length exceeds <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_buffer_size">client_body_buffer_size</a> but less than <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size">client_max_body_size</a>, Nginx will buffer the data into a temporary file on the disk, which will lead to empty value in the <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#var_request_body">$request_body</a> variable.</p>
|
||
|
||
<p>If the current location includes <a href="#rewrite_by_lua">rewrite_by_lua</a> or <a href="#rewrite_by_lua_file">rewrite_by_lua_file</a> directives,
|
||
then the request body will be read just before the <a href="#rewrite_by_lua">rewrite_by_lua</a> or <a href="#rewrite_by_lua_file">rewrite_by_lua_file</a> code is run (and also at the
|
||
<code class="language-plaintext highlighter-rouge">rewrite</code> phase). Similarly, if only <a href="#content_by_lua">content_by_lua</a> is specified,
|
||
the request body will not be read until the content handler’s Lua code is
|
||
about to run (i.e., the request body will be read during the content phase).</p>
|
||
|
||
<p>It is recommended however, to use the <a href="#ngxreqread_body">ngx.req.read_body</a> and <a href="#ngxreqdiscard_body">ngx.req.discard_body</a> functions for finer control over the request body reading process instead.</p>
|
||
|
||
<p>This also applies to <a href="#access_by_lua">access_by_lua</a> and <a href="#access_by_lua_file">access_by_lua_file</a>.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_shared_dict">lua_shared_dict</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_shared_dict <name> <size></em></p>
|
||
|
||
<p><strong>default:</strong> <em>no</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>depends on usage</em></p>
|
||
|
||
<p>Declares a shared memory zone, <code class="language-plaintext highlighter-rouge"><name></code>, to serve as storage for the shm based Lua dictionary <code class="language-plaintext highlighter-rouge">ngx.shared.<name></code>.</p>
|
||
|
||
<p>Shared memory zones are always shared by all the nginx worker processes in the current nginx server instance.</p>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge"><size></code> argument accepts size units such as <code class="language-plaintext highlighter-rouge">k</code> and <code class="language-plaintext highlighter-rouge">m</code>:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">http</span> <span class="p">{</span>
|
||
<span class="kn">lua_shared_dict</span> <span class="s">dogs</span> <span class="mi">10m</span><span class="p">;</span>
|
||
<span class="kn">...</span>
|
||
<span class="err">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>See <a href="#ngxshareddict">ngx.shared.DICT</a> for details.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc22</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_socket_connect_timeout">lua_socket_connect_timeout</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_socket_connect_timeout <time></em></p>
|
||
|
||
<p><strong>default:</strong> <em>lua_socket_connect_timeout 60s</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location</em></p>
|
||
|
||
<p>This directive controls the default timeout value used in TCP/unix-domain socket object’s <a href="#tcpsockconnect">connect</a> method and can be overridden by the <a href="#tcpsocksettimeout">settimeout</a> method.</p>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge"><time></code> argument can be an integer, with an optional time unit, like <code class="language-plaintext highlighter-rouge">s</code> (second), <code class="language-plaintext highlighter-rouge">ms</code> (millisecond), <code class="language-plaintext highlighter-rouge">m</code> (minute). The default time unit is <code class="language-plaintext highlighter-rouge">s</code>, i.e., “second”. The default setting is <code class="language-plaintext highlighter-rouge">60s</code>.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_socket_send_timeout">lua_socket_send_timeout</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_socket_send_timeout <time></em></p>
|
||
|
||
<p><strong>default:</strong> <em>lua_socket_send_timeout 60s</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location</em></p>
|
||
|
||
<p>Controls the default timeout value used in TCP/unix-domain socket object’s <a href="#tcpsocksend">send</a> method and can be overridden by the <a href="#tcpsocksettimeout">settimeout</a> method.</p>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge"><time></code> argument can be an integer, with an optional time unit, like <code class="language-plaintext highlighter-rouge">s</code> (second), <code class="language-plaintext highlighter-rouge">ms</code> (millisecond), <code class="language-plaintext highlighter-rouge">m</code> (minute). The default time unit is <code class="language-plaintext highlighter-rouge">s</code>, i.e., “second”. The default setting is <code class="language-plaintext highlighter-rouge">60s</code>.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_socket_send_lowat">lua_socket_send_lowat</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_socket_send_lowat <size></em></p>
|
||
|
||
<p><strong>default:</strong> <em>lua_socket_send_lowat 0</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location</em></p>
|
||
|
||
<p>Controls the <code class="language-plaintext highlighter-rouge">lowat</code> (low water) value for the cosocket send buffer.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_socket_read_timeout">lua_socket_read_timeout</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_socket_read_timeout <time></em></p>
|
||
|
||
<p><strong>default:</strong> <em>lua_socket_read_timeout 60s</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location</em></p>
|
||
|
||
<p><strong>phase:</strong> <em>depends on usage</em></p>
|
||
|
||
<p>This directive controls the default timeout value used in TCP/unix-domain socket object’s <a href="#tcpsockreceive">receive</a> method and iterator functions returned by the <a href="#tcpsockreceiveuntil">receiveuntil</a> method. This setting can be overridden by the <a href="#tcpsocksettimeout">settimeout</a> method.</p>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge"><time></code> argument can be an integer, with an optional time unit, like <code class="language-plaintext highlighter-rouge">s</code> (second), <code class="language-plaintext highlighter-rouge">ms</code> (millisecond), <code class="language-plaintext highlighter-rouge">m</code> (minute). The default time unit is <code class="language-plaintext highlighter-rouge">s</code>, i.e., “second”. The default setting is <code class="language-plaintext highlighter-rouge">60s</code>.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_socket_buffer_size">lua_socket_buffer_size</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_socket_buffer_size <size></em></p>
|
||
|
||
<p><strong>default:</strong> <em>lua_socket_buffer_size 4k/8k</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location</em></p>
|
||
|
||
<p>Specifies the buffer size used by cosocket reading operations.</p>
|
||
|
||
<p>This buffer does not have to be that big to hold everything at the same time because cosocket supports 100% non-buffered reading and parsing. So even <code class="language-plaintext highlighter-rouge">1</code> byte buffer size should still work everywhere but the performance could be terrible.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_socket_pool_size">lua_socket_pool_size</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_socket_pool_size <size></em></p>
|
||
|
||
<p><strong>default:</strong> <em>lua_socket_pool_size 30</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location</em></p>
|
||
|
||
<p>Specifies the size limit (in terms of connection count) for every cosocket connection pool associated with every remote server (i.e., identified by either the host-port pair or the unix domain socket file path).</p>
|
||
|
||
<p>Default to 30 connections for every pool.</p>
|
||
|
||
<p>When the connection pool exceeds the available size limit, the least recently used (idle) connection already in the pool will be closed to make room for the current connection.</p>
|
||
|
||
<p>Note that the cosocket connection pool is per nginx worker process rather than per nginx server instance, so size limit specified here also applies to every single nginx worker process.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_socket_keepalive_timeout">lua_socket_keepalive_timeout</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_socket_keepalive_timeout <time></em></p>
|
||
|
||
<p><strong>default:</strong> <em>lua_socket_keepalive_timeout 60s</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location</em></p>
|
||
|
||
<p>This directive controls the default maximal idle time of the connections in the cosocket built-in connection pool. When this timeout reaches, idle connections will be closed and removed from the pool. This setting can be overridden by cosocket objects’ <a href="#tcpsocksetkeepalive">setkeepalive</a> method.</p>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge"><time></code> argument can be an integer, with an optional time unit, like <code class="language-plaintext highlighter-rouge">s</code> (second), <code class="language-plaintext highlighter-rouge">ms</code> (millisecond), <code class="language-plaintext highlighter-rouge">m</code> (minute). The default time unit is <code class="language-plaintext highlighter-rouge">s</code>, i.e., “second”. The default setting is <code class="language-plaintext highlighter-rouge">60s</code>.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_socket_log_errors">lua_socket_log_errors</h2>
|
||
|
||
<table>
|
||
<tbody>
|
||
<tr>
|
||
<td><strong>syntax:</strong> *lua_socket_log_errors on</td>
|
||
<td>off*</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<p><strong>default:</strong> <em>lua_socket_log_errors on</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location</em></p>
|
||
|
||
<p>This directive can be used to toggle error logging when a failure occurs for the TCP or UDP cosockets. If you are already doing proper error handling and logging in your Lua code, then it is recommended to turn this directive off to prevent data flushing in your nginx error log files (which is usually rather expensive).</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.13</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_ssl_ciphers">lua_ssl_ciphers</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_ssl_ciphers <ciphers></em></p>
|
||
|
||
<p><strong>default:</strong> <em>lua_ssl_ciphers DEFAULT</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location</em></p>
|
||
|
||
<p>Specifies the enabled ciphers for requests to a SSL/TLS server in the <a href="#tcpsocksslhandshake">tcpsock:sslhandshake</a> method. The ciphers are specified in the format understood by the OpenSSL library.</p>
|
||
|
||
<p>The full list can be viewed using the “openssl ciphers” command.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.9.11</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_ssl_crl">lua_ssl_crl</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_ssl_crl <file></em></p>
|
||
|
||
<p><strong>default:</strong> <em>no</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location</em></p>
|
||
|
||
<p>Specifies a file with revoked certificates (CRL) in the PEM format used to verify the certificate of the SSL/TLS server in the <a href="#tcpsocksslhandshake">tcpsock:sslhandshake</a> method.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.9.11</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_ssl_protocols">lua_ssl_protocols</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_ssl_protocols [SSLv2] [SSLv3] [TLSv1] [TLSv1.1] [TLSv1.2]</em></p>
|
||
|
||
<p><strong>default:</strong> <em>lua_ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location</em></p>
|
||
|
||
<p>Enables the specified protocols for requests to a SSL/TLS server in the <a href="#tcpsocksslhandshake">tcpsock:sslhandshake</a> method.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.9.11</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_ssl_trusted_certificate">lua_ssl_trusted_certificate</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_ssl_trusted_certificate <file></em></p>
|
||
|
||
<p><strong>default:</strong> <em>no</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location</em></p>
|
||
|
||
<p>Specifies a file path with trusted CA certificates in the PEM format used to verify the certificate of the SSL/TLS server in the <a href="#tcpsocksslhandshake">tcpsock:sslhandshake</a> method.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.9.11</code> release.</p>
|
||
|
||
<p>See also <a href="#lua_ssl_verify_depth">lua_ssl_verify_depth</a>.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_ssl_verify_depth">lua_ssl_verify_depth</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_ssl_verify_depth <number></em></p>
|
||
|
||
<p><strong>default:</strong> <em>lua_ssl_verify_depth 1</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location</em></p>
|
||
|
||
<p>Sets the verification depth in the server certificates chain.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.9.11</code> release.</p>
|
||
|
||
<p>See also <a href="#lua_ssl_trusted_certificate">lua_ssl_trusted_certificate</a>.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_http10_buffering">lua_http10_buffering</h2>
|
||
|
||
<table>
|
||
<tbody>
|
||
<tr>
|
||
<td><strong>syntax:</strong> *lua_http10_buffering on</td>
|
||
<td>off*</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<p><strong>default:</strong> <em>lua_http10_buffering on</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location, location-if</em></p>
|
||
|
||
<p>Enables or disables automatic response buffering for HTTP 1.0 (or older) requests. This buffering mechanism is mainly used for HTTP 1.0 keep-alive which replies on a proper <code class="language-plaintext highlighter-rouge">Content-Length</code> response header.</p>
|
||
|
||
<p>If the Lua code explicitly sets a <code class="language-plaintext highlighter-rouge">Content-Length</code> response header before sending the headers (either explicitly via <a href="#ngxsend_headers">ngx.send_headers</a> or implicitly via the first <a href="#ngxsay">ngx.say</a> or <a href="#ngxprint">ngx.print</a> call), then the HTTP 1.0 response buffering will be disabled even when this directive is turned on.</p>
|
||
|
||
<p>To output very large response data in a streaming fashion (via the <a href="#ngxflush">ngx.flush</a> call, for example), this directive MUST be turned off to minimize memory usage.</p>
|
||
|
||
<p>This directive is turned <code class="language-plaintext highlighter-rouge">on</code> by default.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc19</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="rewrite_by_lua_no_postpone">rewrite_by_lua_no_postpone</h2>
|
||
|
||
<table>
|
||
<tbody>
|
||
<tr>
|
||
<td><strong>syntax:</strong> *rewrite_by_lua_no_postpone on</td>
|
||
<td>off*</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<p><strong>default:</strong> <em>rewrite_by_lua_no_postpone off</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http</em></p>
|
||
|
||
<p>Controls whether or not to disable postponing <a href="#rewrite_by_lua">rewrite_by_lua</a> and <a href="#rewrite_by_lua_file">rewrite_by_lua_file</a> directives to run at the end of the <code class="language-plaintext highlighter-rouge">rewrite</code> request-processing phase. By default, this directive is turned off and the Lua code is postponed to run at the end of the <code class="language-plaintext highlighter-rouge">rewrite</code> phase.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc29</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_transform_underscores_in_response_headers">lua_transform_underscores_in_response_headers</h2>
|
||
|
||
<table>
|
||
<tbody>
|
||
<tr>
|
||
<td><strong>syntax:</strong> *lua_transform_underscores_in_response_headers on</td>
|
||
<td>off*</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<p><strong>default:</strong> <em>lua_transform_underscores_in_response_headers on</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location, location-if</em></p>
|
||
|
||
<p>Controls whether to transform underscores (<code class="language-plaintext highlighter-rouge">_</code>) in the response header names specified in the <a href="#ngxheaderheader">ngx.header.HEADER</a> API to hypens (<code class="language-plaintext highlighter-rouge">-</code>).</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc32</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_check_client_abort">lua_check_client_abort</h2>
|
||
|
||
<table>
|
||
<tbody>
|
||
<tr>
|
||
<td><strong>syntax:</strong> *lua_check_client_abort on</td>
|
||
<td>off*</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<p><strong>default:</strong> <em>lua_check_client_abort off</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http, server, location, location-if</em></p>
|
||
|
||
<p>This directive controls whether to check for premature client connection abortion.</p>
|
||
|
||
<p>When this directive is turned on, the ngx_lua module will monitor the premature connection close event on the downstream connections. And when there is such an event, it will call the user Lua function callback (registered by <a href="#ngxon_abort">ngx.on_abort</a>) or just stop and clean up all the Lua “light threads” running in the current request’s request handler when there is no user callback function registered.</p>
|
||
|
||
<p>According to the current implementation, however, if the client closes the connection before the Lua code finishes reading the request body data via <a href="#ngxreqsocket">ngx.req.socket</a>, then ngx_lua will neither stop all the running “light threads” nor call the user callback (if <a href="#ngxon_abort">ngx.on_abort</a> has been called). Instead, the reading operation on <a href="#ngxreqsocket">ngx.req.socket</a> will just return the error message “client aborted” as the second return value (the first return value is surely <code class="language-plaintext highlighter-rouge">nil</code>).</p>
|
||
|
||
<p>When TCP keepalive is disabled, it is relying on the client side to close the socket gracefully (by sending a <code class="language-plaintext highlighter-rouge">FIN</code> packet or something like that). For (soft) real-time web applications, it is highly recommended to configure the <a href="http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html">TCP keepalive</a> support in your system’s TCP stack implementation in order to detect “half-open” TCP connections in time.</p>
|
||
|
||
<p>For example, on Linux, you can configure the standard <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#listen">listen</a> directive in your <code class="language-plaintext highlighter-rouge">nginx.conf</code> file like this:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">listen</span> <span class="mi">80</span> <span class="s">so_keepalive=2s:2s:8</span><span class="p">;</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>On FreeBSD, you can only tune the system-wide configuration for TCP keepalive, for example:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code># sysctl net.inet.tcp.keepintvl=2000
|
||
# sysctl net.inet.tcp.keepidle=2000
|
||
</code></pre></div></div>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.7.4</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxon_abort">ngx.on_abort</a>.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_max_pending_timers">lua_max_pending_timers</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_max_pending_timers <count></em></p>
|
||
|
||
<p><strong>default:</strong> <em>lua_max_pending_timers 1024</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http</em></p>
|
||
|
||
<p>Controls the maximum number of pending timers allowed.</p>
|
||
|
||
<p>Pending timers are those timers that have not expired yet.</p>
|
||
|
||
<p>When exceeding this limit, the <a href="#ngxtimerat">ngx.timer.at</a> call will immediately return <code class="language-plaintext highlighter-rouge">nil</code> and the error string “too many pending timers”.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.8.0</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h2 id="lua_max_running_timers">lua_max_running_timers</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>lua_max_running_timers <count></em></p>
|
||
|
||
<p><strong>default:</strong> <em>lua_max_running_timers 256</em></p>
|
||
|
||
<p><strong>context:</strong> <em>http</em></p>
|
||
|
||
<p>Controls the maximum number of “running timers” allowed.</p>
|
||
|
||
<p>Running timers are those timers whose user callback functions are still running.</p>
|
||
|
||
<p>When exceeding this limit, Nginx will stop running the callbacks of newly expired timers and log an error message “N lua_max_running_timers are not enough” where “N” is the current value of this directive.</p>
|
||
|
||
<p>This directive was first introduced in the <code class="language-plaintext highlighter-rouge">v0.8.0</code> release.</p>
|
||
|
||
<p><a href="#directives">Back to TOC</a></p>
|
||
|
||
<h1 id="nginx-api-for-lua">Nginx API for Lua</h1>
|
||
|
||
<ul>
|
||
<li><a href="#introduction">Introduction</a></li>
|
||
<li><a href="#ngxarg">ngx.arg</a></li>
|
||
<li><a href="#ngxvarvariable">ngx.var.VARIABLE</a></li>
|
||
<li><a href="#core-constants">Core constants</a></li>
|
||
<li><a href="#http-method-constants">HTTP method constants</a></li>
|
||
<li><a href="#http-status-constants">HTTP status constants</a></li>
|
||
<li><a href="#nginx-log-level-constants">Nginx log level constants</a></li>
|
||
<li><a href="#print">print</a></li>
|
||
<li><a href="#ngxctx">ngx.ctx</a></li>
|
||
<li><a href="#ngxlocationcapture">ngx.location.capture</a></li>
|
||
<li><a href="#ngxlocationcapture_multi">ngx.location.capture_multi</a></li>
|
||
<li><a href="#ngxstatus">ngx.status</a></li>
|
||
<li><a href="#ngxheaderheader">ngx.header.HEADER</a></li>
|
||
<li><a href="#ngxrespget_headers">ngx.resp.get_headers</a></li>
|
||
<li><a href="#ngxreqstart_time">ngx.req.start_time</a></li>
|
||
<li><a href="#ngxreqhttp_version">ngx.req.http_version</a></li>
|
||
<li><a href="#ngxreqraw_header">ngx.req.raw_header</a></li>
|
||
<li><a href="#ngxreqget_method">ngx.req.get_method</a></li>
|
||
<li><a href="#ngxreqset_method">ngx.req.set_method</a></li>
|
||
<li><a href="#ngxreqset_uri">ngx.req.set_uri</a></li>
|
||
<li><a href="#ngxreqset_uri_args">ngx.req.set_uri_args</a></li>
|
||
<li><a href="#ngxreqget_uri_args">ngx.req.get_uri_args</a></li>
|
||
<li><a href="#ngxreqget_post_args">ngx.req.get_post_args</a></li>
|
||
<li><a href="#ngxreqget_headers">ngx.req.get_headers</a></li>
|
||
<li><a href="#ngxreqset_header">ngx.req.set_header</a></li>
|
||
<li><a href="#ngxreqclear_header">ngx.req.clear_header</a></li>
|
||
<li><a href="#ngxreqread_body">ngx.req.read_body</a></li>
|
||
<li><a href="#ngxreqdiscard_body">ngx.req.discard_body</a></li>
|
||
<li><a href="#ngxreqget_body_data">ngx.req.get_body_data</a></li>
|
||
<li><a href="#ngxreqget_body_file">ngx.req.get_body_file</a></li>
|
||
<li><a href="#ngxreqset_body_data">ngx.req.set_body_data</a></li>
|
||
<li><a href="#ngxreqset_body_file">ngx.req.set_body_file</a></li>
|
||
<li><a href="#ngxreqinit_body">ngx.req.init_body</a></li>
|
||
<li><a href="#ngxreqappend_body">ngx.req.append_body</a></li>
|
||
<li><a href="#ngxreqfinish_body">ngx.req.finish_body</a></li>
|
||
<li><a href="#ngxreqsocket">ngx.req.socket</a></li>
|
||
<li><a href="#ngxexec">ngx.exec</a></li>
|
||
<li><a href="#ngxredirect">ngx.redirect</a></li>
|
||
<li><a href="#ngxsend_headers">ngx.send_headers</a></li>
|
||
<li><a href="#ngxheaders_sent">ngx.headers_sent</a></li>
|
||
<li><a href="#ngxprint">ngx.print</a></li>
|
||
<li><a href="#ngxsay">ngx.say</a></li>
|
||
<li><a href="#ngxlog">ngx.log</a></li>
|
||
<li><a href="#ngxflush">ngx.flush</a></li>
|
||
<li><a href="#ngxexit">ngx.exit</a></li>
|
||
<li><a href="#ngxeof">ngx.eof</a></li>
|
||
<li><a href="#ngxsleep">ngx.sleep</a></li>
|
||
<li><a href="#ngxescape_uri">ngx.escape_uri</a></li>
|
||
<li><a href="#ngxunescape_uri">ngx.unescape_uri</a></li>
|
||
<li><a href="#ngxencode_args">ngx.encode_args</a></li>
|
||
<li><a href="#ngxdecode_args">ngx.decode_args</a></li>
|
||
<li><a href="#ngxencode_base64">ngx.encode_base64</a></li>
|
||
<li><a href="#ngxdecode_base64">ngx.decode_base64</a></li>
|
||
<li><a href="#ngxcrc32_short">ngx.crc32_short</a></li>
|
||
<li><a href="#ngxcrc32_long">ngx.crc32_long</a></li>
|
||
<li><a href="#ngxhmac_sha1">ngx.hmac_sha1</a></li>
|
||
<li><a href="#ngxmd5">ngx.md5</a></li>
|
||
<li><a href="#ngxmd5_bin">ngx.md5_bin</a></li>
|
||
<li><a href="#ngxsha1_bin">ngx.sha1_bin</a></li>
|
||
<li><a href="#ngxquote_sql_str">ngx.quote_sql_str</a></li>
|
||
<li><a href="#ngxtoday">ngx.today</a></li>
|
||
<li><a href="#ngxtime">ngx.time</a></li>
|
||
<li><a href="#ngxnow">ngx.now</a></li>
|
||
<li><a href="#ngxupdate_time">ngx.update_time</a></li>
|
||
<li><a href="#ngxlocaltime">ngx.localtime</a></li>
|
||
<li><a href="#ngxutctime">ngx.utctime</a></li>
|
||
<li><a href="#ngxcookie_time">ngx.cookie_time</a></li>
|
||
<li><a href="#ngxhttp_time">ngx.http_time</a></li>
|
||
<li><a href="#ngxparse_http_time">ngx.parse_http_time</a></li>
|
||
<li><a href="#ngxis_subrequest">ngx.is_subrequest</a></li>
|
||
<li><a href="#ngxrematch">ngx.re.match</a></li>
|
||
<li><a href="#ngxrefind">ngx.re.find</a></li>
|
||
<li><a href="#ngxregmatch">ngx.re.gmatch</a></li>
|
||
<li><a href="#ngxresub">ngx.re.sub</a></li>
|
||
<li><a href="#ngxregsub">ngx.re.gsub</a></li>
|
||
<li><a href="#ngxshareddict">ngx.shared.DICT</a></li>
|
||
<li><a href="#ngxshareddictget">ngx.shared.DICT.get</a></li>
|
||
<li><a href="#ngxshareddictget_stale">ngx.shared.DICT.get_stale</a></li>
|
||
<li><a href="#ngxshareddictset">ngx.shared.DICT.set</a></li>
|
||
<li><a href="#ngxshareddictsafe_set">ngx.shared.DICT.safe_set</a></li>
|
||
<li><a href="#ngxshareddictadd">ngx.shared.DICT.add</a></li>
|
||
<li><a href="#ngxshareddictsafe_add">ngx.shared.DICT.safe_add</a></li>
|
||
<li><a href="#ngxshareddictreplace">ngx.shared.DICT.replace</a></li>
|
||
<li><a href="#ngxshareddictdelete">ngx.shared.DICT.delete</a></li>
|
||
<li><a href="#ngxshareddictincr">ngx.shared.DICT.incr</a></li>
|
||
<li><a href="#ngxshareddictflush_all">ngx.shared.DICT.flush_all</a></li>
|
||
<li><a href="#ngxshareddictflush_expired">ngx.shared.DICT.flush_expired</a></li>
|
||
<li><a href="#ngxshareddictget_keys">ngx.shared.DICT.get_keys</a></li>
|
||
<li><a href="#ngxsocketudp">ngx.socket.udp</a></li>
|
||
<li><a href="#udpsocksetpeername">udpsock:setpeername</a></li>
|
||
<li><a href="#udpsocksend">udpsock:send</a></li>
|
||
<li><a href="#udpsockreceive">udpsock:receive</a></li>
|
||
<li><a href="#udpsockclose">udpsock:close</a></li>
|
||
<li><a href="#udpsocksettimeout">udpsock:settimeout</a></li>
|
||
<li><a href="#ngxsockettcp">ngx.socket.tcp</a></li>
|
||
<li><a href="#tcpsockconnect">tcpsock:connect</a></li>
|
||
<li><a href="#tcpsocksslhandshake">tcpsock:sslhandshake</a></li>
|
||
<li><a href="#tcpsocksend">tcpsock:send</a></li>
|
||
<li><a href="#tcpsockreceive">tcpsock:receive</a></li>
|
||
<li><a href="#tcpsockreceiveuntil">tcpsock:receiveuntil</a></li>
|
||
<li><a href="#tcpsockclose">tcpsock:close</a></li>
|
||
<li><a href="#tcpsocksettimeout">tcpsock:settimeout</a></li>
|
||
<li><a href="#tcpsocksetoption">tcpsock:setoption</a></li>
|
||
<li><a href="#tcpsocksetkeepalive">tcpsock:setkeepalive</a></li>
|
||
<li><a href="#tcpsockgetreusedtimes">tcpsock:getreusedtimes</a></li>
|
||
<li><a href="#ngxsocketconnect">ngx.socket.connect</a></li>
|
||
<li><a href="#ngxget_phase">ngx.get_phase</a></li>
|
||
<li><a href="#ngxthreadspawn">ngx.thread.spawn</a></li>
|
||
<li><a href="#ngxthreadwait">ngx.thread.wait</a></li>
|
||
<li><a href="#ngxthreadkill">ngx.thread.kill</a></li>
|
||
<li><a href="#ngxon_abort">ngx.on_abort</a></li>
|
||
<li><a href="#ngxtimerat">ngx.timer.at</a></li>
|
||
<li><a href="#ngxconfigdebug">ngx.config.debug</a></li>
|
||
<li><a href="#ngxconfigprefix">ngx.config.prefix</a></li>
|
||
<li><a href="#ngxconfignginx_version">ngx.config.nginx_version</a></li>
|
||
<li><a href="#ngxconfignginx_configure">ngx.config.nginx_configure</a></li>
|
||
<li><a href="#ngxconfigngx_lua_version">ngx.config.ngx_lua_version</a></li>
|
||
<li><a href="#ngxworkerexiting">ngx.worker.exiting</a></li>
|
||
<li><a href="#ngxworkerpid">ngx.worker.pid</a></li>
|
||
<li><a href="#ndkset_vardirective">ndk.set_var.DIRECTIVE</a></li>
|
||
<li><a href="#coroutinecreate">coroutine.create</a></li>
|
||
<li><a href="#coroutineresume">coroutine.resume</a></li>
|
||
<li><a href="#coroutineyield">coroutine.yield</a></li>
|
||
<li><a href="#coroutinewrap">coroutine.wrap</a></li>
|
||
<li><a href="#coroutinerunning">coroutine.running</a></li>
|
||
<li><a href="#coroutinestatus">coroutine.status</a></li>
|
||
</ul>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h2 id="introduction">Introduction</h2>
|
||
<p>The various <code class="language-plaintext highlighter-rouge">*_by_lua</code> and <code class="language-plaintext highlighter-rouge">*_by_lua_file</code> configuration directives serve as gateways to the Lua API within the <code class="language-plaintext highlighter-rouge">nginx.conf</code> file. The Nginx Lua API described below can only be called within the user Lua code run in the context of these configuration directives.</p>
|
||
|
||
<p>The API is exposed to Lua in the form of two standard packages <code class="language-plaintext highlighter-rouge">ngx</code> and <code class="language-plaintext highlighter-rouge">ndk</code>. These packages are in the default global scope within ngx_lua and are always available within ngx_lua directives.</p>
|
||
|
||
<p>The packages can be introduced into external Lua modules like this:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">say</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">say</span>
|
||
|
||
<span class="kd">local</span> <span class="n">_M</span> <span class="o">=</span> <span class="p">{}</span>
|
||
|
||
<span class="k">function</span> <span class="nc">_M</span><span class="p">.</span><span class="nf">foo</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
|
||
<span class="n">say</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="k">return</span> <span class="n">_M</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Use of the <a href="http://www.lua.org/manual/5.1/manual.html#pdf-package.seeall">package.seeall</a> flag is strongly discouraged due to its various bad side-effects.</p>
|
||
|
||
<p>It is also possible to directly require the packages in external Lua modules:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">ngx</span> <span class="o">=</span> <span class="nb">require</span> <span class="s2">"ngx"</span>
|
||
<span class="kd">local</span> <span class="n">ndk</span> <span class="o">=</span> <span class="nb">require</span> <span class="s2">"ndk"</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>The ability to require these packages was introduced in the <code class="language-plaintext highlighter-rouge">v0.2.1rc19</code> release.</p>
|
||
|
||
<p>Network I/O operations in user code should only be done through the Nginx Lua API calls as the Nginx event loop may be blocked and performance drop off dramatically otherwise. Disk operations with relatively small amount of data can be done using the standard Lua <code class="language-plaintext highlighter-rouge">io</code> library but huge file reading and writing should be avoided wherever possible as they may block the Nginx process significantly. Delegating all network and disk I/O operations to Nginx’s subrequests (via the <a href="#ngxlocationcapture">ngx.location.capture</a> method and similar) is strongly recommended for maximum performance.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxarg">ngx.arg</h2>
|
||
<p><strong>syntax:</strong> <em>val = ngx.arg[index]</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, body_filter_by_lua**</p>
|
||
|
||
<p>When this is used in the context of the <a href="#set_by_lua">set_by_lua</a> or <a href="#set_by_lua_file">set_by_lua_file</a> directives, this table is read-only and holds the input arguments to the config directives:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">value</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">arg</span><span class="p">[</span><span class="n">n</span><span class="p">]</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Here is an example</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/foo</span> <span class="p">{</span>
|
||
<span class="kn">set</span> <span class="nv">$a</span> <span class="mi">32</span><span class="p">;</span>
|
||
<span class="kn">set</span> <span class="nv">$b</span> <span class="mi">56</span><span class="p">;</span>
|
||
|
||
<span class="kn">set_by_lua</span> <span class="nv">$sum</span>
|
||
<span class="s">'return</span> <span class="s">tonumber(ngx.arg[1])</span> <span class="s">+</span> <span class="s">tonumber(ngx.arg[2])'</span>
|
||
<span class="nv">$a</span> <span class="nv">$b</span><span class="p">;</span>
|
||
|
||
<span class="kn">echo</span> <span class="nv">$sum</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>that writes out <code class="language-plaintext highlighter-rouge">88</code>, the sum of <code class="language-plaintext highlighter-rouge">32</code> and <code class="language-plaintext highlighter-rouge">56</code>.</p>
|
||
|
||
<p>When this table is used in the context of <a href="#body_filter_by_lua">body_filter_by_lua</a> or <a href="#body_filter_by_lua_file">body_filter_by_lua_file</a>, the first element holds the input data chunk to the output filter code and the second element holds the boolean flag for the “eof” flag indicating the end of the whole output data stream.</p>
|
||
|
||
<p>The data chunk and “eof” flag passed to the downstream Nginx output filters can also be overridden by assigning values directly to the corresponding table elements. When setting <code class="language-plaintext highlighter-rouge">nil</code> or an empty Lua string value to <code class="language-plaintext highlighter-rouge">ngx.arg[1]</code>, no data chunk will be passed to the downstream Nginx output filters at all.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxvarvariable">ngx.var.VARIABLE</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.var.VAR_NAME</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua*, log_by_lua**</p>
|
||
|
||
<p>Read and write Nginx variable values.</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">value</span> <span class="p">=</span> <span class="s">ngx.var.some_nginx_variable_name</span>
|
||
<span class="s">ngx.var.some_nginx_variable_name</span> <span class="p">=</span> <span class="s">value</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Note that only already defined nginx variables can be written to.
|
||
For example:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/foo</span> <span class="p">{</span>
|
||
<span class="kn">set</span> <span class="nv">$my_var</span> <span class="s">''</span><span class="p">;</span> <span class="c1"># this line is required to create $my_var at config time</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">ngx.var.my_var</span> <span class="p">=</span> <span class="mi">123</span><span class="p">;</span>
|
||
<span class="kn">...</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>That is, nginx variables cannot be created on-the-fly.</p>
|
||
|
||
<p>Some special nginx variables like <code class="language-plaintext highlighter-rouge">$args</code> and <code class="language-plaintext highlighter-rouge">$limit_rate</code> can be assigned a value,
|
||
many others are not, like <code class="language-plaintext highlighter-rouge">$query_string</code>, <code class="language-plaintext highlighter-rouge">$arg_PARAMETER</code>, and <code class="language-plaintext highlighter-rouge">$http_NAME</code>.</p>
|
||
|
||
<p>Nginx regex group capturing variables <code class="language-plaintext highlighter-rouge">$1</code>, <code class="language-plaintext highlighter-rouge">$2</code>, <code class="language-plaintext highlighter-rouge">$3</code>, and etc, can be read by this
|
||
interface as well, by writing <code class="language-plaintext highlighter-rouge">ngx.var[1]</code>, <code class="language-plaintext highlighter-rouge">ngx.var[2]</code>, <code class="language-plaintext highlighter-rouge">ngx.var[3]</code>, and etc.</p>
|
||
|
||
<p>Setting <code class="language-plaintext highlighter-rouge">ngx.var.Foo</code> to a <code class="language-plaintext highlighter-rouge">nil</code> value will unset the <code class="language-plaintext highlighter-rouge">$Foo</code> Nginx variable.</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">var</span><span class="p">.</span><span class="n">args</span> <span class="o">=</span> <span class="kc">nil</span>
|
||
</code></pre></div></div>
|
||
|
||
<p><strong>WARNING</strong> When reading from an Nginx variable, Nginx will allocate memory in the per-request memory pool which is freed only at request termination. So when you need to read from an Nginx variable repeatedly in your Lua code, cache the Nginx variable value to your own Lua variable, for example,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">val</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">var</span><span class="p">.</span><span class="n">some_var</span>
|
||
<span class="c1">--- use the val repeatedly later</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>to prevent (temporary) memory leaking within the current request’s lifetime. Another way of caching the result is to use the <a href="#ngxctx">ngx.ctx</a> table.</p>
|
||
|
||
<p>This API requires a relatively expensive metamethod call and it is recommended to avoid using it on hot code paths.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="core-constants">Core constants</h2>
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua, *log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">OK</span> <span class="p">(</span><span class="mi">0</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">ERROR</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">AGAIN</span> <span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">DONE</span> <span class="p">(</span><span class="o">-</span><span class="mi">4</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">DECLINED</span> <span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Note that only three of these constants are utilized by the <a href="#nginx-api-for-lua">Nginx API for Lua</a> (i.e., <a href="#ngxexit">ngx.exit</a> accepts <code class="language-plaintext highlighter-rouge">NGX_OK</code>, <code class="language-plaintext highlighter-rouge">NGX_ERROR</code>, and <code class="language-plaintext highlighter-rouge">NGX_DECLINED</code> as input).</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">null</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">ngx.null</code> constant is a <code class="language-plaintext highlighter-rouge">NULL</code> light userdata usually used to represent nil values in Lua tables etc and is similar to the <a href="http://www.kyne.com.au/~mark/software/lua-cjson.php">lua-cjson</a> library’s <code class="language-plaintext highlighter-rouge">cjson.null</code> constant. This constant was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc5</code> release.</p>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">ngx.DECLINED</code> constant was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc19</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="http-method-constants">HTTP method constants</h2>
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> ngx.HTTP_GET
|
||
ngx.HTTP_HEAD
|
||
ngx.HTTP_PUT
|
||
ngx.HTTP_POST
|
||
ngx.HTTP_DELETE
|
||
ngx.HTTP_OPTIONS (added in the v0.5.0rc24 release)
|
||
ngx.HTTP_MKCOL (added in the v0.8.2 release)
|
||
ngx.HTTP_COPY (added in the v0.8.2 release)
|
||
ngx.HTTP_MOVE (added in the v0.8.2 release)
|
||
ngx.HTTP_PROPFIND (added in the v0.8.2 release)
|
||
ngx.HTTP_PROPPATCH (added in the v0.8.2 release)
|
||
ngx.HTTP_LOCK (added in the v0.8.2 release)
|
||
ngx.HTTP_UNLOCK (added in the v0.8.2 release)
|
||
ngx.HTTP_PATCH (added in the v0.8.2 release)
|
||
ngx.HTTP_TRACE (added in the v0.8.2 release)
|
||
</code></pre></div></div>
|
||
|
||
<p>These constants are usually used in <a href="#ngxlocationcapture">ngx.location.capture</a> and <a href="#ngxlocationcapture_multi">ngx.location.capture_multi</a> method calls.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="http-status-constants">HTTP status constants</h2>
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_OK</span> <span class="s">(200)</span>
|
||
<span class="s">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_CREATED</span> <span class="s">(201)</span>
|
||
<span class="s">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_SPECIAL_RESPONSE</span> <span class="s">(300)</span>
|
||
<span class="s">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_MOVED_PERMANENTLY</span> <span class="s">(301)</span>
|
||
<span class="s">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_MOVED_TEMPORARILY</span> <span class="s">(302)</span>
|
||
<span class="s">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_SEE_OTHER</span> <span class="s">(303)</span>
|
||
<span class="s">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_NOT_MODIFIED</span> <span class="s">(304)</span>
|
||
<span class="s">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_BAD_REQUEST</span> <span class="s">(400)</span>
|
||
<span class="s">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_UNAUTHORIZED</span> <span class="s">(401)</span>
|
||
<span class="s">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_FORBIDDEN</span> <span class="s">(403)</span>
|
||
<span class="s">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_NOT_FOUND</span> <span class="s">(404)</span>
|
||
<span class="s">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_NOT_ALLOWED</span> <span class="s">(405)</span>
|
||
<span class="s">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_GONE</span> <span class="s">(410)</span>
|
||
<span class="s">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_INTERNAL_SERVER_ERROR</span> <span class="s">(500)</span>
|
||
<span class="s">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_METHOD_NOT_IMPLEMENTED</span> <span class="s">(501)</span>
|
||
<span class="s">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_SERVICE_UNAVAILABLE</span> <span class="s">(503)</span>
|
||
<span class="s">value</span> <span class="p">=</span> <span class="s">ngx.HTTP_GATEWAY_TIMEOUT</span> <span class="s">(504)</span> <span class="s">(first</span> <span class="s">added</span> <span class="s">in</span> <span class="s">the</span> <span class="s">v0.3.1rc38</span> <span class="s">release)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="nginx-log-level-constants">Nginx log level constants</h2>
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">STDERR</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">EMERG</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">ALERT</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">CRIT</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">ERR</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">WARN</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">NOTICE</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">INFO</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">DEBUG</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>These constants are usually used by the <a href="#ngxlog">ngx.log</a> method.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="print">print</h2>
|
||
<p><strong>syntax:</strong> <em>print(…)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, init_worker_by_lua<em>, set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Writes argument values into the nginx <code class="language-plaintext highlighter-rouge">error.log</code> file with the <code class="language-plaintext highlighter-rouge">ngx.NOTICE</code> log level.</p>
|
||
|
||
<p>It is equivalent to</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">log</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">NOTICE</span><span class="p">,</span> <span class="o">...</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Lua <code class="language-plaintext highlighter-rouge">nil</code> arguments are accepted and result in literal <code class="language-plaintext highlighter-rouge">"nil"</code> strings while Lua booleans result in literal <code class="language-plaintext highlighter-rouge">"true"</code> or <code class="language-plaintext highlighter-rouge">"false"</code> strings. And the <code class="language-plaintext highlighter-rouge">ngx.null</code> constant will yield the <code class="language-plaintext highlighter-rouge">"null"</code> string output.</p>
|
||
|
||
<p>There is a hard coded <code class="language-plaintext highlighter-rouge">2048</code> byte limitation on error message lengths in the Nginx core. This limit includes trailing newlines and leading time stamps. If the message size exceeds this limit, Nginx will truncate the message text accordingly. This limit can be manually modified by editing the <code class="language-plaintext highlighter-rouge">NGX_MAX_ERROR_STR</code> macro definition in the <code class="language-plaintext highlighter-rouge">src/core/ngx_log.h</code> file in the Nginx source tree.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxctx">ngx.ctx</h2>
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>This table can be used to store per-request Lua context data and has a life time identical to the current request (as with the Nginx variables).</p>
|
||
|
||
<p>Consider the following example,</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/test</span> <span class="p">{</span>
|
||
<span class="kn">rewrite_by_lua</span> <span class="s">'</span>
|
||
<span class="s">ngx.ctx.foo</span> <span class="p">=</span> <span class="mi">76</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="kn">access_by_lua</span> <span class="s">'</span>
|
||
<span class="s">ngx.ctx.foo</span> <span class="p">=</span> <span class="s">ngx.ctx.foo</span> <span class="s">+</span> <span class="mi">3</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">ngx.say(ngx.ctx.foo)</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Then <code class="language-plaintext highlighter-rouge">GET /test</code> will yield the output</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
79
|
||
</code></pre></div></div>
|
||
|
||
<p>That is, the <code class="language-plaintext highlighter-rouge">ngx.ctx.foo</code> entry persists across the rewrite, access, and content phases of a request.</p>
|
||
|
||
<p>Every request, including subrequests, has its own copy of the table. For example:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/sub</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">ngx.say("sub</span> <span class="s">pre:</span> <span class="s">",</span> <span class="s">ngx.ctx.blah)</span>
|
||
<span class="s">ngx.ctx.blah</span> <span class="p">=</span> <span class="mi">32</span>
|
||
<span class="s">ngx.say("sub</span> <span class="s">post:</span> <span class="s">",</span> <span class="s">ngx.ctx.blah)</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="k">location</span> <span class="n">/main</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">ngx.ctx.blah</span> <span class="p">=</span> <span class="mi">73</span>
|
||
<span class="s">ngx.say("main</span> <span class="s">pre:</span> <span class="s">",</span> <span class="s">ngx.ctx.blah)</span>
|
||
<span class="s">local</span> <span class="s">res</span> <span class="p">=</span> <span class="s">ngx.location.capture("/sub")</span>
|
||
<span class="s">ngx.print(res.body)</span>
|
||
<span class="s">ngx.say("main</span> <span class="s">post:</span> <span class="s">",</span> <span class="s">ngx.ctx.blah)</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Then <code class="language-plaintext highlighter-rouge">GET /main</code> will give the output</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
main pre: 73
|
||
sub pre: nil
|
||
sub post: 32
|
||
main post: 73
|
||
</code></pre></div></div>
|
||
|
||
<p>Here, modification of the <code class="language-plaintext highlighter-rouge">ngx.ctx.blah</code> entry in the subrequest does not affect the one in the parent request. This is because they have two separate versions of <code class="language-plaintext highlighter-rouge">ngx.ctx.blah</code>.</p>
|
||
|
||
<p>Internal redirection will destroy the original request <code class="language-plaintext highlighter-rouge">ngx.ctx</code> data (if any) and the new request will have an empty <code class="language-plaintext highlighter-rouge">ngx.ctx</code> table. For instance,</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/new</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">ngx.say(ngx.ctx.foo)</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="k">location</span> <span class="n">/orig</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">ngx.ctx.foo</span> <span class="p">=</span> <span class="s">"hello"</span>
|
||
<span class="s">ngx.exec("/new")</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Then <code class="language-plaintext highlighter-rouge">GET /orig</code> will give</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
nil
|
||
</code></pre></div></div>
|
||
|
||
<p>rather than the original <code class="language-plaintext highlighter-rouge">"hello"</code> value.</p>
|
||
|
||
<p>Arbitrary data values, including Lua closures and nested tables, can be inserted into this “magic” table. It also allows the registration of custom meta methods.</p>
|
||
|
||
<p>Overriding <code class="language-plaintext highlighter-rouge">ngx.ctx</code> with a new Lua table is also supported, for example,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">ctx</span> <span class="o">=</span> <span class="p">{</span> <span class="n">foo</span> <span class="o">=</span> <span class="mi">32</span><span class="p">,</span> <span class="n">bar</span> <span class="o">=</span> <span class="mi">54</span> <span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>When being used in the context of <a href="#init_worker_by_lua">init_worker_by_lua*</a>, this table just has the same lifetime of the current Lua handler.</p>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">ngx.ctx</code> lookup requires relatively expensive metamethod calls and it is much slower than explicitly passing per-request data along by your own function arguments. So do not abuse this API for saving your own function arguments because it usually has quite some performance impact. And because of the metamethod magic, never “local” the <code class="language-plaintext highlighter-rouge">ngx.ctx</code> table outside your function scope.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxlocationcapture">ngx.location.capture</h2>
|
||
<p><strong>syntax:</strong> <em>res = ngx.location.capture(uri, options?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Issue a synchronous but still non-blocking <em>Nginx Subrequest</em> using <code class="language-plaintext highlighter-rouge">uri</code>.</p>
|
||
|
||
<p>Nginx’s subrequests provide a powerful way to make non-blocking internal requests to other locations configured with disk file directory or <em>any</em> other nginx C modules like <code class="language-plaintext highlighter-rouge">ngx_proxy</code>, <code class="language-plaintext highlighter-rouge">ngx_fastcgi</code>, <code class="language-plaintext highlighter-rouge">ngx_memc</code>,
|
||
<code class="language-plaintext highlighter-rouge">ngx_postgres</code>, <code class="language-plaintext highlighter-rouge">ngx_drizzle</code>, and even ngx_lua itself and etc etc etc.</p>
|
||
|
||
<p>Also note that subrequests just mimic the HTTP interface but there is <em>no</em> extra HTTP/TCP traffic <em>nor</em> IPC involved. Everything works internally, efficiently, on the C level.</p>
|
||
|
||
<p>Subrequests are completely different from HTTP 301/302 redirection (via <a href="#ngxredirect">ngx.redirect</a>) and internal redirection (via <a href="#ngxexec">ngx.exec</a>).</p>
|
||
|
||
<p>You should always read the request body (by either calling <a href="#ngxreqread_body">ngx.req.read_body</a> or configuring <a href="#lua_need_request_body">lua_need_request_body</a> on) before initiating a subrequest.</p>
|
||
|
||
<p>Here is a basic example:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">res</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">location</span><span class="p">.</span><span class="n">capture</span><span class="p">(</span><span class="n">uri</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Returns a Lua table with 4 slots: <code class="language-plaintext highlighter-rouge">res.status</code>, <code class="language-plaintext highlighter-rouge">res.header</code>, <code class="language-plaintext highlighter-rouge">res.body</code>, and <code class="language-plaintext highlighter-rouge">res.truncated</code>.</p>
|
||
|
||
<p><code class="language-plaintext highlighter-rouge">res.status</code> holds the response status code for the subrequest response.</p>
|
||
|
||
<p><code class="language-plaintext highlighter-rouge">res.header</code> holds all the response headers of the
|
||
subrequest and it is a normal Lua table. For multi-value response headers,
|
||
the value is a Lua (array) table that holds all the values in the order that
|
||
they appear. For instance, if the subrequest response headers contain the following
|
||
lines:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
Set-Cookie: <span class="nv">a</span><span class="o">=</span>3
|
||
Set-Cookie: <span class="nv">foo</span><span class="o">=</span>bar
|
||
Set-Cookie: <span class="nv">baz</span><span class="o">=</span>blah
|
||
</code></pre></div></div>
|
||
|
||
<p>Then <code class="language-plaintext highlighter-rouge">res.header["Set-Cookie"]</code> will be evaluated to the table value
|
||
<code class="language-plaintext highlighter-rouge">{"a=3", "foo=bar", "baz=blah"}</code>.</p>
|
||
|
||
<p><code class="language-plaintext highlighter-rouge">res.body</code> holds the subrequest’s response body data, which might be truncated. You always need to check the <code class="language-plaintext highlighter-rouge">res.truncated</code> boolean flag to see if <code class="language-plaintext highlighter-rouge">res.body</code> contains truncated data. The data truncation here can only be caused by those unrecoverable errors in your subrequests like the cases that the remote end aborts the connection prematurely in the middle of the response body data stream or a read timeout happens when your subrequest is receiving the response body data from the remote.</p>
|
||
|
||
<p>URI query strings can be concatenated to URI itself, for instance,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">res</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">location</span><span class="p">.</span><span class="n">capture</span><span class="p">(</span><span class="s1">'/foo/bar?a=3&b=4'</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Named locations like <code class="language-plaintext highlighter-rouge">@foo</code> are not allowed due to a limitation in
|
||
the nginx core. Use normal locations combined with the <code class="language-plaintext highlighter-rouge">internal</code> directive to
|
||
prepare internal-only locations.</p>
|
||
|
||
<p>An optional option table can be fed as the second
|
||
argument, which supports the options:</p>
|
||
|
||
<ul>
|
||
<li><code class="language-plaintext highlighter-rouge">method</code>
|
||
specify the subrequest’s request method, which only accepts constants like <code class="language-plaintext highlighter-rouge">ngx.HTTP_POST</code>.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">body</code>
|
||
specify the subrequest’s request body (string value only).</li>
|
||
<li><code class="language-plaintext highlighter-rouge">args</code>
|
||
specify the subrequest’s URI query arguments (both string value and Lua tables are accepted)</li>
|
||
<li><code class="language-plaintext highlighter-rouge">ctx</code>
|
||
specify a Lua table to be the <a href="#ngxctx">ngx.ctx</a> table for the subrequest. It can be the current request’s <a href="#ngxctx">ngx.ctx</a> table, which effectively makes the parent and its subrequest to share exactly the same context table. This option was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc25</code> release.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">vars</code>
|
||
take a Lua table which holds the values to set the specified Nginx variables in the subrequest as this option’s value. This option was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc31</code> release.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">copy_all_vars</code>
|
||
specify whether to copy over all the Nginx variable values of the current request to the subrequest in question. modifications of the nginx variables in the subrequest will not affect the current (parent) request. This option was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc31</code> release.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">share_all_vars</code>
|
||
specify whether to share all the Nginx variables of the subrequest with the current (parent) request. modifications of the Nginx variables in the subrequest will affect the current (parent) request. Enabling this option may lead to hard-to-debug issues due to bad side-effects and is considered bad and harmful. Only enable this option when you completely know what you are doing.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">always_forward_body</code>
|
||
when set to true, the current (parent) request’s request body will always be forwarded to the subrequest being created if the <code class="language-plaintext highlighter-rouge">body</code> option is not specified. The request body read by either <a href="#ngxreqread_body">ngx.req.read_body()</a> or <a href="#lua_need_request_body">lua_need_request_body on</a> will be directly forwarded to the subrequest without copying the whole request body data when creating the subrequest (no matter the request body data is buffered in memory buffers or temporary files). By default, this option is <code class="language-plaintext highlighter-rouge">false</code> and when the <code class="language-plaintext highlighter-rouge">body</code> option is not specified, the request body of the current (parent) request is only forwarded when the subrequest takes the <code class="language-plaintext highlighter-rouge">PUT</code> or <code class="language-plaintext highlighter-rouge">POST</code> request method.</li>
|
||
</ul>
|
||
|
||
<p>Issuing a POST subrequest, for example, can be done as follows</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">res</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">location</span><span class="p">.</span><span class="n">capture</span><span class="p">(</span>
|
||
<span class="s1">'/foo/bar'</span><span class="p">,</span>
|
||
<span class="p">{</span> <span class="n">method</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">HTTP_POST</span><span class="p">,</span> <span class="n">body</span> <span class="o">=</span> <span class="s1">'hello, world'</span> <span class="p">}</span>
|
||
<span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>See HTTP method constants methods other than POST.
|
||
The <code class="language-plaintext highlighter-rouge">method</code> option is <code class="language-plaintext highlighter-rouge">ngx.HTTP_GET</code> by default.</p>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">args</code> option can specify extra URI arguments, for instance,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">location</span><span class="p">.</span><span class="n">capture</span><span class="p">(</span><span class="s1">'/foo?a=1'</span><span class="p">,</span>
|
||
<span class="p">{</span> <span class="n">args</span> <span class="o">=</span> <span class="p">{</span> <span class="n">b</span> <span class="o">=</span> <span class="mi">3</span><span class="p">,</span> <span class="n">c</span> <span class="o">=</span> <span class="s1">':'</span> <span class="p">}</span> <span class="p">}</span>
|
||
<span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>is equivalent to</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">location</span><span class="p">.</span><span class="n">capture</span><span class="p">(</span><span class="s1">'/foo?a=1&b=3&c=%3a'</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>that is, this method will escape argument keys and values according to URI rules and
|
||
concatenate them together into a complete query string. The format for the Lua table passed as the <code class="language-plaintext highlighter-rouge">args</code> argument is identical to the format used in the <a href="#ngxencode_args">ngx.encode_args</a> method.</p>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">args</code> option can also take plain query strings:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">location</span><span class="p">.</span><span class="n">capture</span><span class="p">(</span><span class="s1">'/foo?a=1'</span><span class="p">,</span>
|
||
<span class="p">{</span> <span class="n">args</span> <span class="o">=</span> <span class="s1">'b=3&c=%3a'</span> <span class="p">}</span> <span class="p">}</span>
|
||
<span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This is functionally identical to the previous examples.</p>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">share_all_vars</code> option controls whether to share nginx variables among the current request and its subrequests.
|
||
If this option is set to <code class="language-plaintext highlighter-rouge">true</code>, then the current request and associated subrequests will share the same Nginx variable scope. Hence, changes to Nginx variables made by a subrequest will affect the current request.</p>
|
||
|
||
<p>Care should be taken in using this option as variable scope sharing can have unexpected side effects. The <code class="language-plaintext highlighter-rouge">args</code>, <code class="language-plaintext highlighter-rouge">vars</code>, or <code class="language-plaintext highlighter-rouge">copy_all_vars</code> options are generally preferable instead.</p>
|
||
|
||
<p>This option is set to <code class="language-plaintext highlighter-rouge">false</code> by default</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/other</span> <span class="p">{</span>
|
||
<span class="kn">set</span> <span class="nv">$dog</span> <span class="s">"</span><span class="nv">$dog</span> <span class="s">world"</span><span class="p">;</span>
|
||
<span class="kn">echo</span> <span class="s">"</span><span class="nv">$uri</span> <span class="s">dog:</span> <span class="nv">$dog</span><span class="s">"</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="k">location</span> <span class="n">/lua</span> <span class="p">{</span>
|
||
<span class="kn">set</span> <span class="nv">$dog</span> <span class="s">'hello'</span><span class="p">;</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">res</span> <span class="p">=</span> <span class="s">ngx.location.capture("/other",</span>
|
||
<span class="p">{</span> <span class="kn">share_all_vars</span> <span class="p">=</span> <span class="s">true</span> <span class="err">}</span><span class="s">)</span><span class="p">;</span>
|
||
|
||
<span class="kn">ngx.print</span><span class="s">(res.body)</span>
|
||
<span class="s">ngx.say(ngx.var.uri,</span> <span class="s">":</span> <span class="s">",</span> <span class="s">ngx.var.dog)</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Accessing location <code class="language-plaintext highlighter-rouge">/lua</code> gives</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/other dog: hello world
|
||
/lua: hello world
|
||
</code></pre></div></div>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">copy_all_vars</code> option provides a copy of the parent request’s Nginx variables to subrequests when such subrequests are issued. Changes made to these variables by such subrequests will not affect the parent request or any other subrequests sharing the parent request’s variables.</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/other</span> <span class="p">{</span>
|
||
<span class="kn">set</span> <span class="nv">$dog</span> <span class="s">"</span><span class="nv">$dog</span> <span class="s">world"</span><span class="p">;</span>
|
||
<span class="kn">echo</span> <span class="s">"</span><span class="nv">$uri</span> <span class="s">dog:</span> <span class="nv">$dog</span><span class="s">"</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="k">location</span> <span class="n">/lua</span> <span class="p">{</span>
|
||
<span class="kn">set</span> <span class="nv">$dog</span> <span class="s">'hello'</span><span class="p">;</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">res</span> <span class="p">=</span> <span class="s">ngx.location.capture("/other",</span>
|
||
<span class="p">{</span> <span class="kn">copy_all_vars</span> <span class="p">=</span> <span class="s">true</span> <span class="err">}</span><span class="s">)</span><span class="p">;</span>
|
||
|
||
<span class="kn">ngx.print</span><span class="s">(res.body)</span>
|
||
<span class="s">ngx.say(ngx.var.uri,</span> <span class="s">":</span> <span class="s">",</span> <span class="s">ngx.var.dog)</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Request <code class="language-plaintext highlighter-rouge">GET /lua</code> will give the output</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/other dog: hello world
|
||
/lua: hello
|
||
</code></pre></div></div>
|
||
|
||
<p>Note that if both <code class="language-plaintext highlighter-rouge">share_all_vars</code> and <code class="language-plaintext highlighter-rouge">copy_all_vars</code> are set to true, then <code class="language-plaintext highlighter-rouge">share_all_vars</code> takes precedence.</p>
|
||
|
||
<p>In addition to the two settings above, it is possible to specify
|
||
values for variables in the subrequest using the <code class="language-plaintext highlighter-rouge">vars</code> option. These
|
||
variables are set after the sharing or copying of variables has been
|
||
evaluated, and provides a more efficient method of passing specific
|
||
values to a subrequest over encoding them as URL arguments and
|
||
unescaping them in the Nginx config file.</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/other</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">ngx.say("dog</span> <span class="p">=</span> <span class="s">",</span> <span class="s">ngx.var.dog)</span>
|
||
<span class="s">ngx.say("cat</span> <span class="p">=</span> <span class="s">",</span> <span class="s">ngx.var.cat)</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="k">location</span> <span class="n">/lua</span> <span class="p">{</span>
|
||
<span class="kn">set</span> <span class="nv">$dog</span> <span class="s">''</span><span class="p">;</span>
|
||
<span class="kn">set</span> <span class="nv">$cat</span> <span class="s">''</span><span class="p">;</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">res</span> <span class="p">=</span> <span class="s">ngx.location.capture("/other",</span>
|
||
<span class="p">{</span> <span class="kn">vars</span> <span class="p">=</span> <span class="p">{</span> <span class="kn">dog</span> <span class="p">=</span> <span class="s">"hello",</span> <span class="s">cat</span> <span class="p">=</span> <span class="mi">32</span> <span class="err">}}</span><span class="s">)</span><span class="p">;</span>
|
||
|
||
<span class="kn">ngx.print</span><span class="s">(res.body)</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Accessing <code class="language-plaintext highlighter-rouge">/lua</code> will yield the output</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>dog = hello
|
||
cat = 32
|
||
</code></pre></div></div>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">ctx</code> option can be used to specify a custom Lua table to serve as the <a href="#ngxctx">ngx.ctx</a> table for the subrequest.</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/sub</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">ngx.ctx.foo</span> <span class="p">=</span> <span class="s">"bar"</span><span class="p">;</span>
|
||
<span class="kn">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="k">location</span> <span class="n">/lua</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">ctx</span> <span class="p">=</span> <span class="p">{}</span>
|
||
<span class="kn">res</span> <span class="p">=</span> <span class="s">ngx.location.capture("/sub",</span> <span class="p">{</span> <span class="kn">ctx</span> <span class="p">=</span> <span class="s">ctx</span> <span class="err">}</span><span class="s">)</span>
|
||
|
||
<span class="s">ngx.say(ctx.foo)</span><span class="p">;</span>
|
||
<span class="kn">ngx.say</span><span class="s">(ngx.ctx.foo)</span><span class="p">;</span>
|
||
<span class="kn">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Then request <code class="language-plaintext highlighter-rouge">GET /lua</code> gives</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bar
|
||
nil
|
||
</code></pre></div></div>
|
||
|
||
<p>It is also possible to use this <code class="language-plaintext highlighter-rouge">ctx</code> option to share the same <a href="#ngxctx">ngx.ctx</a> table between the current (parent) request and the subrequest:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/sub</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">ngx.ctx.foo</span> <span class="p">=</span> <span class="s">"bar"</span><span class="p">;</span>
|
||
<span class="kn">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="k">location</span> <span class="n">/lua</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">res</span> <span class="p">=</span> <span class="s">ngx.location.capture("/sub",</span> <span class="p">{</span> <span class="kn">ctx</span> <span class="p">=</span> <span class="s">ngx.ctx</span> <span class="err">}</span><span class="s">)</span>
|
||
<span class="s">ngx.say(ngx.ctx.foo)</span><span class="p">;</span>
|
||
<span class="kn">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Request <code class="language-plaintext highlighter-rouge">GET /lua</code> yields the output</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bar
|
||
</code></pre></div></div>
|
||
|
||
<p>Note that subrequests issued by <a href="#ngxlocationcapture">ngx.location.capture</a> inherit all the
|
||
request headers of the current request by default and that this may have unexpected side effects on the
|
||
subrequest responses. For example, when using the standard <code class="language-plaintext highlighter-rouge">ngx_proxy</code> module to serve
|
||
subrequests, an “Accept-Encoding: gzip” header in the main request may result
|
||
in gzipped responses that cannot be handled properly in Lua code. Original request headers should be ignored by setting
|
||
<a href="http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass_request_headers">proxy_pass_request_headers</a> to <code class="language-plaintext highlighter-rouge">off</code> in subrequest locations.</p>
|
||
|
||
<p>When the <code class="language-plaintext highlighter-rouge">body</code> option is not specified and the <code class="language-plaintext highlighter-rouge">always_forward_body</code> option is false (the default value), the <code class="language-plaintext highlighter-rouge">POST</code> and <code class="language-plaintext highlighter-rouge">PUT</code> subrequests will inherit the request bodies of the parent request (if any).</p>
|
||
|
||
<p>There is a hard-coded upper limit on the number of concurrent subrequests possible for every main request. In older versions of Nginx, the limit was <code class="language-plaintext highlighter-rouge">50</code> concurrent subrequests and in more recent versions, Nginx <code class="language-plaintext highlighter-rouge">1.1.x</code> onwards, this was increased to <code class="language-plaintext highlighter-rouge">200</code> concurrent subrequests. When this limit is exceeded, the following error message is added to the <code class="language-plaintext highlighter-rouge">error.log</code> file:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>[error] 13983#0: *1 subrequests cycle while processing "/uri"
|
||
</code></pre></div></div>
|
||
|
||
<p>The limit can be manually modified if required by editing the definition of the <code class="language-plaintext highlighter-rouge">NGX_HTTP_MAX_SUBREQUESTS</code> macro in the <code class="language-plaintext highlighter-rouge">nginx/src/http/ngx_http_request.h</code> file in the Nginx source tree.</p>
|
||
|
||
<p>Please also refer to restrictions on capturing locations configured by <a href="#locations-configured-by-subrequest-directives-of-other-modules">subrequest directives of other modules</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxlocationcapture_multi">ngx.location.capture_multi</h2>
|
||
<p><strong>syntax:</strong> <em>res1, res2, … = ngx.location.capture_multi({ {uri, options?}, {uri, options?}, … })</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Just like <a href="#ngxlocationcapture">ngx.location.capture</a>, but supports multiple subrequests running in parallel.</p>
|
||
|
||
<p>This function issues several parallel subrequests specified by the input table and returns their results in the same order. For example,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">res1</span><span class="p">,</span> <span class="n">res2</span><span class="p">,</span> <span class="n">res3</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">location</span><span class="p">.</span><span class="n">capture_multi</span><span class="p">{</span>
|
||
<span class="p">{</span> <span class="s2">"/foo"</span><span class="p">,</span> <span class="p">{</span> <span class="n">args</span> <span class="o">=</span> <span class="s2">"a=3&b=4"</span> <span class="p">}</span> <span class="p">},</span>
|
||
<span class="p">{</span> <span class="s2">"/bar"</span> <span class="p">},</span>
|
||
<span class="p">{</span> <span class="s2">"/baz"</span><span class="p">,</span> <span class="p">{</span> <span class="n">method</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">HTTP_POST</span><span class="p">,</span> <span class="n">body</span> <span class="o">=</span> <span class="s2">"hello"</span> <span class="p">}</span> <span class="p">},</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="k">if</span> <span class="n">res1</span><span class="p">.</span><span class="n">status</span> <span class="o">==</span> <span class="n">ngx</span><span class="p">.</span><span class="n">HTTP_OK</span> <span class="k">then</span>
|
||
<span class="o">...</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="k">if</span> <span class="n">res2</span><span class="p">.</span><span class="n">body</span> <span class="o">==</span> <span class="s2">"BLAH"</span> <span class="k">then</span>
|
||
<span class="o">...</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This function will not return until all the subrequests terminate.
|
||
The total latency is the longest latency of the individual subrequests rather than the sum.</p>
|
||
|
||
<p>Lua tables can be used for both requests and responses when the number of subrequests to be issued is not known in advance:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="c1">-- construct the requests table</span>
|
||
<span class="kd">local</span> <span class="n">reqs</span> <span class="o">=</span> <span class="p">{}</span>
|
||
<span class="nb">table.insert</span><span class="p">(</span><span class="n">reqs</span><span class="p">,</span> <span class="p">{</span> <span class="s2">"/mysql"</span> <span class="p">})</span>
|
||
<span class="nb">table.insert</span><span class="p">(</span><span class="n">reqs</span><span class="p">,</span> <span class="p">{</span> <span class="s2">"/postgres"</span> <span class="p">})</span>
|
||
<span class="nb">table.insert</span><span class="p">(</span><span class="n">reqs</span><span class="p">,</span> <span class="p">{</span> <span class="s2">"/redis"</span> <span class="p">})</span>
|
||
<span class="nb">table.insert</span><span class="p">(</span><span class="n">reqs</span><span class="p">,</span> <span class="p">{</span> <span class="s2">"/memcached"</span> <span class="p">})</span>
|
||
|
||
<span class="c1">-- issue all the requests at once and wait until they all return</span>
|
||
<span class="kd">local</span> <span class="n">resps</span> <span class="o">=</span> <span class="p">{</span> <span class="n">ngx</span><span class="p">.</span><span class="n">location</span><span class="p">.</span><span class="n">capture_multi</span><span class="p">(</span><span class="n">reqs</span><span class="p">)</span> <span class="p">}</span>
|
||
|
||
<span class="c1">-- loop over the responses table</span>
|
||
<span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">resp</span> <span class="k">in</span> <span class="nb">ipairs</span><span class="p">(</span><span class="n">resps</span><span class="p">)</span> <span class="k">do</span>
|
||
<span class="c1">-- process the response table "resp"</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>The <a href="#ngxlocationcapture">ngx.location.capture</a> function is just a special form
|
||
of this function. Logically speaking, the <a href="#ngxlocationcapture">ngx.location.capture</a> can be implemented like this</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">location</span><span class="p">.</span><span class="n">capture</span> <span class="o">=</span>
|
||
<span class="k">function</span> <span class="p">(</span><span class="n">uri</span><span class="p">,</span> <span class="n">args</span><span class="p">)</span>
|
||
<span class="k">return</span> <span class="n">ngx</span><span class="p">.</span><span class="n">location</span><span class="p">.</span><span class="n">capture_multi</span><span class="p">({</span> <span class="p">{</span><span class="n">uri</span><span class="p">,</span> <span class="n">args</span><span class="p">}</span> <span class="p">})</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Please also refer to restrictions on capturing locations configured by <a href="#locations-configured-by-subrequest-directives-of-other-modules">subrequest directives of other modules</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxstatus">ngx.status</h2>
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua, log_by_lua**</p>
|
||
|
||
<p>Read and write the current request’s response status. This should be called
|
||
before sending out the response headers.</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">status</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">HTTP_CREATED</span>
|
||
<span class="n">status</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">status</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Setting <code class="language-plaintext highlighter-rouge">ngx.status</code> after the response header is sent out has no effect but leaving an error message in your nginx’s error log file:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>attempt to set ngx.status after sending out response headers
|
||
</code></pre></div></div>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxheaderheader">ngx.header.HEADER</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.header.HEADER = VALUE</em></p>
|
||
|
||
<p><strong>syntax:</strong> <em>value = ngx.header.HEADER</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua*, body_filter_by_lua, log_by_lua**</p>
|
||
|
||
<p>Set, add to, or clear the current request’s <code class="language-plaintext highlighter-rouge">HEADER</code> response header that is to be sent.</p>
|
||
|
||
<p>Underscores (<code class="language-plaintext highlighter-rouge">_</code>) in the header names will be replaced by hyphens (<code class="language-plaintext highlighter-rouge">-</code>) by default. This transformation can be turned off via the <a href="#lua_transform_underscores_in_response_headers">lua_transform_underscores_in_response_headers</a> directive.</p>
|
||
|
||
<p>The header names are matched case-insensitively.</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="c1">-- equivalent to ngx.header["Content-Type"] = 'text/plain'</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">header</span><span class="p">.</span><span class="n">content_type</span> <span class="o">=</span> <span class="s1">'text/plain'</span><span class="p">;</span>
|
||
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">header</span><span class="p">[</span><span class="s2">"X-My-Header"</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'blah blah'</span><span class="p">;</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Multi-value headers can be set this way:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">header</span><span class="p">[</span><span class="s1">'Set-Cookie'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'a=32; path=/'</span><span class="p">,</span> <span class="s1">'b=4; path=/'</span><span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>will yield</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
Set-Cookie: <span class="nv">a</span><span class="o">=</span>32<span class="p">;</span> <span class="nv">path</span><span class="o">=</span>/
|
||
Set-Cookie: <span class="nv">b</span><span class="o">=</span>4<span class="p">;</span> <span class="nv">path</span><span class="o">=</span>/
|
||
</code></pre></div></div>
|
||
|
||
<p>in the response headers.</p>
|
||
|
||
<p>Only Lua tables are accepted (Only the last element in the table will take effect for standard headers such as <code class="language-plaintext highlighter-rouge">Content-Type</code> that only accept a single value).</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">header</span><span class="p">.</span><span class="n">content_type</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'a'</span><span class="p">,</span> <span class="s1">'b'</span><span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>is equivalent to</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">header</span><span class="p">.</span><span class="n">content_type</span> <span class="o">=</span> <span class="s1">'b'</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Setting a slot to <code class="language-plaintext highlighter-rouge">nil</code> effectively removes it from the response headers:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">header</span><span class="p">[</span><span class="s2">"X-My-Header"</span><span class="p">]</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">;</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>The same applies to assigning an empty table:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">header</span><span class="p">[</span><span class="s2">"X-My-Header"</span><span class="p">]</span> <span class="o">=</span> <span class="p">{};</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Setting <code class="language-plaintext highlighter-rouge">ngx.header.HEADER</code> after sending out response headers (either explicitly with <a href="#ngxsend_headers">ngx.send_headers</a> or implicitly with <a href="#ngxprint">ngx.print</a> and similar) will throw out a Lua exception.</p>
|
||
|
||
<p>Reading <code class="language-plaintext highlighter-rouge">ngx.header.HEADER</code> will return the value of the response header named <code class="language-plaintext highlighter-rouge">HEADER</code>.</p>
|
||
|
||
<p>Underscores (<code class="language-plaintext highlighter-rouge">_</code>) in the header names will also be replaced by dashes (<code class="language-plaintext highlighter-rouge">-</code>) and the header names will be matched case-insensitively. If the response header is not present at all, <code class="language-plaintext highlighter-rouge">nil</code> will be returned.</p>
|
||
|
||
<p>This is particularly useful in the context of <a href="#header_filter_by_lua">header_filter_by_lua</a> and <a href="#header_filter_by_lua_file">header_filter_by_lua_file</a>, for example,</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/test</span> <span class="p">{</span>
|
||
<span class="kn">set</span> <span class="nv">$footer</span> <span class="s">''</span><span class="p">;</span>
|
||
|
||
<span class="kn">proxy_pass</span> <span class="s">http://some-backend</span><span class="p">;</span>
|
||
|
||
<span class="kn">header_filter_by_lua</span> <span class="s">'</span>
|
||
<span class="s">if</span> <span class="s">ngx.header["X-My-Header"]</span> <span class="p">==</span> <span class="s">"blah"</span> <span class="s">then</span>
|
||
<span class="s">ngx.var.footer</span> <span class="p">=</span> <span class="s">"some</span> <span class="s">value"</span>
|
||
<span class="s">end</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
|
||
<span class="kn">echo_after_body</span> <span class="nv">$footer</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>For multi-value headers, all of the values of header will be collected in order and returned as a Lua table. For example, response headers</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Foo: bar
|
||
Foo: baz
|
||
</code></pre></div></div>
|
||
|
||
<p>will result in</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="p">{</span><span class="s2">"bar"</span><span class="p">,</span> <span class="s2">"baz"</span><span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>to be returned when reading <code class="language-plaintext highlighter-rouge">ngx.header.Foo</code>.</p>
|
||
|
||
<p>Note that <code class="language-plaintext highlighter-rouge">ngx.header</code> is not a normal Lua table and as such, it is not possible to iterate through it using the Lua <code class="language-plaintext highlighter-rouge">ipairs</code> function.</p>
|
||
|
||
<p>For reading <em>request</em> headers, use the <a href="#ngxreqget_headers">ngx.req.get_headers</a> function instead.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxrespget_headers">ngx.resp.get_headers</h2>
|
||
<p><strong>syntax:</strong> <em>headers = ngx.resp.get_headers(max_headers?, raw?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua, log_by_lua**</p>
|
||
|
||
<p>Returns a Lua table holding all the current response headers for the current request.</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">h</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">resp</span><span class="p">.</span><span class="n">get_headers</span><span class="p">()</span>
|
||
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="k">in</span> <span class="nb">pairs</span><span class="p">(</span><span class="n">h</span><span class="p">)</span> <span class="k">do</span>
|
||
<span class="o">...</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This function has the same signature as <a href="#ngxreqget_headers">ngx.req.get_headers</a> except getting response headers instead of request headers.</p>
|
||
|
||
<p>This API was first introduced in the <code class="language-plaintext highlighter-rouge">v0.9.5</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqstart_time">ngx.req.start_time</h2>
|
||
<p><strong>syntax:</strong> <em>secs = ngx.req.start_time()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua*, log_by_lua**</p>
|
||
|
||
<p>Returns a floating-point number representing the timestamp (including milliseconds as the decimal part) when the current request was created.</p>
|
||
|
||
<p>The following example emulates the <code class="language-plaintext highlighter-rouge">$request_time</code> variable value (provided by <a href="http://nginx.org/en/docs/http/ngx_http_log_module.html">ngx_http_log_module</a>) in pure Lua:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">request_time</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">now</span><span class="p">()</span> <span class="o">-</span> <span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">start_time</span><span class="p">()</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This function was first introduced in the <code class="language-plaintext highlighter-rouge">v0.7.7</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxnow">ngx.now</a> and <a href="#ngxupdate_time">ngx.update_time</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqhttp_version">ngx.req.http_version</h2>
|
||
<p><strong>syntax:</strong> <em>num = ngx.req.http_version()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua*, header_filter_by_lua**</p>
|
||
|
||
<p>Returns the HTTP version number for the current request as a Lua number.</p>
|
||
|
||
<p>Current possible values are 1.0, 1.1, and 0.9. Returns <code class="language-plaintext highlighter-rouge">nil</code> for unrecognized values.</p>
|
||
|
||
<p>This method was first introduced in the <code class="language-plaintext highlighter-rouge">v0.7.17</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqraw_header">ngx.req.raw_header</h2>
|
||
<p><strong>syntax:</strong> <em>str = ngx.req.raw_header(no_request_line?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua*, header_filter_by_lua**</p>
|
||
|
||
<p>Returns the original raw HTTP protocol header received by the Nginx server.</p>
|
||
|
||
<p>By default, the request line and trailing <code class="language-plaintext highlighter-rouge">CR LF</code> terminator will also be included. For example,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">print</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">raw_header</span><span class="p">())</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>gives something like this:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>GET /t HTTP/1.1
|
||
Host: localhost
|
||
Connection: close
|
||
Foo: bar
|
||
</code></pre></div></div>
|
||
|
||
<p>You can specify the optional
|
||
<code class="language-plaintext highlighter-rouge">no_request_line</code> argument as a <code class="language-plaintext highlighter-rouge">true</code> value to exclude the request line from the result. For example,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">print</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">raw_header</span><span class="p">(</span><span class="kc">true</span><span class="p">))</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>outputs something like this:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Host: localhost
|
||
Connection: close
|
||
Foo: bar
|
||
</code></pre></div></div>
|
||
|
||
<p>This method was first introduced in the <code class="language-plaintext highlighter-rouge">v0.7.17</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqget_method">ngx.req.get_method</h2>
|
||
<p><strong>syntax:</strong> <em>method_name = ngx.req.get_method()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua*, header_filter_by_lua**</p>
|
||
|
||
<p>Retrieves the current request’s request method name. Strings like <code class="language-plaintext highlighter-rouge">"GET"</code> and <code class="language-plaintext highlighter-rouge">"POST"</code> are returned instead of numerical <a href="#http-method-constants">method constants</a>.</p>
|
||
|
||
<p>If the current request is an Nginx subrequest, then the subrequest’s method name will be returned.</p>
|
||
|
||
<p>This method was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.6</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxreqset_method">ngx.req.set_method</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqset_method">ngx.req.set_method</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.req.set_method(method_id)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua*, header_filter_by_lua**</p>
|
||
|
||
<p>Overrides the current request’s request method with the <code class="language-plaintext highlighter-rouge">method_id</code> argument. Currently only numerical <a href="#http-method-constants">method constants</a> are supported, like <code class="language-plaintext highlighter-rouge">ngx.HTTP_POST</code> and <code class="language-plaintext highlighter-rouge">ngx.HTTP_GET</code>.</p>
|
||
|
||
<p>If the current request is an Nginx subrequest, then the subrequest’s method will be overridden.</p>
|
||
|
||
<p>This method was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.6</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxreqget_method">ngx.req.get_method</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqset_uri">ngx.req.set_uri</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.req.set_uri(uri, jump?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua**</p>
|
||
|
||
<p>Rewrite the current request’s (parsed) URI by the <code class="language-plaintext highlighter-rouge">uri</code> argument. The <code class="language-plaintext highlighter-rouge">uri</code> argument must be a Lua string and cannot be of zero length, or a Lua exception will be thrown.</p>
|
||
|
||
<p>The optional boolean <code class="language-plaintext highlighter-rouge">jump</code> argument can trigger location rematch (or location jump) as <a href="http://nginx.org/en/docs/http/ngx_http_rewrite_module.html">ngx_http_rewrite_module</a>’s <a href="http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite">rewrite</a> directive, that is, when <code class="language-plaintext highlighter-rouge">jump</code> is <code class="language-plaintext highlighter-rouge">true</code> (default to <code class="language-plaintext highlighter-rouge">false</code>), this function will never return and it will tell Nginx to try re-searching locations with the new URI value at the later <code class="language-plaintext highlighter-rouge">post-rewrite</code> phase and jumping to the new location.</p>
|
||
|
||
<p>Location jump will not be triggered otherwise, and only the current request’s URI will be modified, which is also the default behavior. This function will return but with no returned values when the <code class="language-plaintext highlighter-rouge">jump</code> argument is <code class="language-plaintext highlighter-rouge">false</code> or absent altogether.</p>
|
||
|
||
<p>For example, the following nginx config snippet</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">rewrite</span> <span class="s">^</span> <span class="n">/foo</span> <span class="s">last</span><span class="p">;</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>can be coded in Lua like this:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">set_uri</span><span class="p">(</span><span class="s2">"/foo"</span><span class="p">,</span> <span class="kc">true</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Similarly, Nginx config</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">rewrite</span> <span class="s">^</span> <span class="n">/foo</span> <span class="s">break</span><span class="p">;</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>can be coded in Lua as</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">set_uri</span><span class="p">(</span><span class="s2">"/foo"</span><span class="p">,</span> <span class="kc">false</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>or equivalently,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">set_uri</span><span class="p">(</span><span class="s2">"/foo"</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">jump</code> argument can only be set to <code class="language-plaintext highlighter-rouge">true</code> in <a href="#rewrite_by_lua">rewrite_by_lua</a> and <a href="#rewrite_by_lua_file">rewrite_by_lua_file</a>. Use of jump in other contexts is prohibited and will throw out a Lua exception.</p>
|
||
|
||
<p>A more sophisticated example involving regex substitutions is as follows</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/test</span> <span class="p">{</span>
|
||
<span class="kn">rewrite_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">uri</span> <span class="p">=</span> <span class="s">ngx.re.sub(ngx.var.uri,</span> <span class="s">"^/test/(.*)",</span> <span class="s">"/</span><span class="nv">$1</span><span class="s">",</span> <span class="s">"o")</span>
|
||
<span class="s">ngx.req.set_uri(uri)</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="kn">proxy_pass</span> <span class="s">http://my_backend</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>which is functionally equivalent to</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/test</span> <span class="p">{</span>
|
||
<span class="kn">rewrite</span> <span class="s">^/test/(.*)</span> <span class="n">/</span><span class="nv">$1</span> <span class="s">break</span><span class="p">;</span>
|
||
<span class="kn">proxy_pass</span> <span class="s">http://my_backend</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Note that it is not possible to use this interface to rewrite URI arguments and that <a href="#ngxreqset_uri_args">ngx.req.set_uri_args</a> should be used for this instead. For instance, Nginx config</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">rewrite</span> <span class="s">^</span> <span class="n">/foo?a=3?</span> <span class="s">last</span><span class="p">;</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>can be coded as</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">ngx.req.set_uri_args</span><span class="s">("a=3")</span>
|
||
<span class="s">ngx.req.set_uri("/foo",</span> <span class="s">true)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>or</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">ngx.req.set_uri_args</span><span class="s">(</span><span class="p">{</span><span class="kn">a</span> <span class="p">=</span> <span class="mi">3</span><span class="err">}</span><span class="s">)</span>
|
||
<span class="s">ngx.req.set_uri("/foo",</span> <span class="s">true)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This interface was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc14</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqset_uri_args">ngx.req.set_uri_args</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.req.set_uri_args(args)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua**</p>
|
||
|
||
<p>Rewrite the current request’s URI query arguments by the <code class="language-plaintext highlighter-rouge">args</code> argument. The <code class="language-plaintext highlighter-rouge">args</code> argument can be either a Lua string, as in</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">set_uri_args</span><span class="p">(</span><span class="s2">"a=3&b=hello%20world"</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>or a Lua table holding the query arguments’ key-value pairs, as in</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">set_uri_args</span><span class="p">({</span> <span class="n">a</span> <span class="o">=</span> <span class="mi">3</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="s2">"hello world"</span> <span class="p">})</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>where in the latter case, this method will escape argument keys and values according to the URI escaping rule.</p>
|
||
|
||
<p>Multi-value arguments are also supported:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">set_uri_args</span><span class="p">({</span> <span class="n">a</span> <span class="o">=</span> <span class="mi">3</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="p">{</span><span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">}</span> <span class="p">})</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>which will result in a query string like <code class="language-plaintext highlighter-rouge">a=3&b=5&b=6</code>.</p>
|
||
|
||
<p>This interface was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc13</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxreqset_uri">ngx.req.set_uri</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqget_uri_args">ngx.req.get_uri_args</h2>
|
||
<p><strong>syntax:</strong> <em>args = ngx.req.get_uri_args(max_args?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua, log_by_lua**</p>
|
||
|
||
<p>Returns a Lua table holding all the current request URL query arguments.</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="p">=</span> <span class="n">/test</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">args</span> <span class="p">=</span> <span class="s">ngx.req.get_uri_args()</span>
|
||
<span class="s">for</span> <span class="s">key,</span> <span class="s">val</span> <span class="s">in</span> <span class="s">pairs(args)</span> <span class="s">do</span>
|
||
<span class="s">if</span> <span class="s">type(val)</span> <span class="p">==</span> <span class="s">"table"</span> <span class="s">then</span>
|
||
<span class="s">ngx.say(key,</span> <span class="s">":</span> <span class="s">",</span> <span class="s">table.concat(val,</span> <span class="s">",</span> <span class="s">"))</span>
|
||
<span class="s">else</span>
|
||
<span class="s">ngx.say(key,</span> <span class="s">":</span> <span class="s">",</span> <span class="s">val)</span>
|
||
<span class="s">end</span>
|
||
<span class="s">end</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Then <code class="language-plaintext highlighter-rouge">GET /test?foo=bar&bar=baz&bar=blah</code> will yield the response body</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
foo: bar
|
||
bar: baz, blah
|
||
</code></pre></div></div>
|
||
|
||
<p>Multiple occurrences of an argument key will result in a table value holding all the values for that key in order.</p>
|
||
|
||
<p>Keys and values are unescaped according to URI escaping rules. In the settings above, <code class="language-plaintext highlighter-rouge">GET /test?a%20b=1%61+2</code> will yield:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
a b: 1a 2
|
||
</code></pre></div></div>
|
||
|
||
<p>Arguments without the <code class="language-plaintext highlighter-rouge">=<value></code> parts are treated as boolean arguments. <code class="language-plaintext highlighter-rouge">GET /test?foo&bar</code> will yield:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
foo: <span class="nb">true
|
||
</span>bar: <span class="nb">true</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>That is, they will take Lua boolean values <code class="language-plaintext highlighter-rouge">true</code>. However, they are different from arguments taking empty string values. <code class="language-plaintext highlighter-rouge">GET /test?foo=&bar=</code> will give something like</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
foo:
|
||
bar:
|
||
</code></pre></div></div>
|
||
|
||
<p>Empty key arguments are discarded. <code class="language-plaintext highlighter-rouge">GET /test?=hello&=world</code> will yield an empty output for instance.</p>
|
||
|
||
<p>Updating query arguments via the nginx variable <code class="language-plaintext highlighter-rouge">$args</code> (or <code class="language-plaintext highlighter-rouge">ngx.var.args</code> in Lua) at runtime is also supported:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">var</span><span class="p">.</span><span class="n">args</span> <span class="o">=</span> <span class="s2">"a=3&b=42"</span>
|
||
<span class="kd">local</span> <span class="n">args</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">get_uri_args</span><span class="p">()</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Here the <code class="language-plaintext highlighter-rouge">args</code> table will always look like</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="p">{</span><span class="n">a</span> <span class="o">=</span> <span class="mi">3</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="mi">42</span><span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>regardless of the actual request query string.</p>
|
||
|
||
<p>Note that a maximum of 100 request arguments are parsed by default (including those with the same name) and that additional request arguments are silently discarded to guard against potential denial of service attacks.</p>
|
||
|
||
<p>However, the optional <code class="language-plaintext highlighter-rouge">max_args</code> function argument can be used to override this limit:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">args</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">get_uri_args</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This argument can be set to zero to remove the limit and to process all request arguments received:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">args</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">get_uri_args</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Removing the <code class="language-plaintext highlighter-rouge">max_args</code> cap is strongly discouraged.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqget_post_args">ngx.req.get_post_args</h2>
|
||
<p><strong>syntax:</strong> <em>args, err = ngx.req.get_post_args(max_args?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua*, body_filter_by_lua, log_by_lua**</p>
|
||
|
||
<p>Returns a Lua table holding all the current request POST query arguments (of the MIME type <code class="language-plaintext highlighter-rouge">application/x-www-form-urlencoded</code>). Call <a href="#ngxreqread_body">ngx.req.read_body</a> to read the request body first or turn on the <a href="#lua_need_request_body">lua_need_request_body</a> directive to avoid errors.</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="p">=</span> <span class="n">/test</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">ngx.req.read_body()</span>
|
||
<span class="s">local</span> <span class="s">args,</span> <span class="s">err</span> <span class="p">=</span> <span class="s">ngx.req.get_post_args()</span>
|
||
<span class="s">if</span> <span class="s">not</span> <span class="s">args</span> <span class="s">then</span>
|
||
<span class="s">ngx.say("failed</span> <span class="s">to</span> <span class="s">get</span> <span class="s">post</span> <span class="s">args:</span> <span class="s">",</span> <span class="s">err)</span>
|
||
<span class="s">return</span>
|
||
<span class="s">end</span>
|
||
<span class="s">for</span> <span class="s">key,</span> <span class="s">val</span> <span class="s">in</span> <span class="s">pairs(args)</span> <span class="s">do</span>
|
||
<span class="s">if</span> <span class="s">type(val)</span> <span class="p">==</span> <span class="s">"table"</span> <span class="s">then</span>
|
||
<span class="s">ngx.say(key,</span> <span class="s">":</span> <span class="s">",</span> <span class="s">table.concat(val,</span> <span class="s">",</span> <span class="s">"))</span>
|
||
<span class="s">else</span>
|
||
<span class="s">ngx.say(key,</span> <span class="s">":</span> <span class="s">",</span> <span class="s">val)</span>
|
||
<span class="s">end</span>
|
||
<span class="s">end</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Then</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="c"># Post request with the body 'foo=bar&bar=baz&bar=blah'</span>
|
||
<span class="nv">$ </span>curl <span class="nt">--data</span> <span class="s1">'foo=bar&bar=baz&bar=blah'</span> localhost/test
|
||
</code></pre></div></div>
|
||
|
||
<p>will yield the response body like</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
foo: bar
|
||
bar: baz, blah
|
||
</code></pre></div></div>
|
||
|
||
<p>Multiple occurrences of an argument key will result in a table value holding all of the values for that key in order.</p>
|
||
|
||
<p>Keys and values will be unescaped according to URI escaping rules.</p>
|
||
|
||
<p>With the settings above,</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="c"># POST request with body 'a%20b=1%61+2'</span>
|
||
<span class="nv">$ </span>curl <span class="nt">-d</span> <span class="s1">'a%20b=1%61+2'</span> localhost/test
|
||
</code></pre></div></div>
|
||
|
||
<p>will yield:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
a b: 1a 2
|
||
</code></pre></div></div>
|
||
|
||
<p>Arguments without the <code class="language-plaintext highlighter-rouge">=<value></code> parts are treated as boolean arguments. <code class="language-plaintext highlighter-rouge">POST /test</code> with the request body <code class="language-plaintext highlighter-rouge">foo&bar</code> will yield:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
foo: <span class="nb">true
|
||
</span>bar: <span class="nb">true</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>That is, they will take Lua boolean values <code class="language-plaintext highlighter-rouge">true</code>. However, they are different from arguments taking empty string values. <code class="language-plaintext highlighter-rouge">POST /test</code> with request body <code class="language-plaintext highlighter-rouge">foo=&bar=</code> will return something like</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
foo:
|
||
bar:
|
||
</code></pre></div></div>
|
||
|
||
<p>Empty key arguments are discarded. <code class="language-plaintext highlighter-rouge">POST /test</code> with body <code class="language-plaintext highlighter-rouge">=hello&=world</code> will yield empty outputs for instance.</p>
|
||
|
||
<p>Note that a maximum of 100 request arguments are parsed by default (including those with the same name) and that additional request arguments are silently discarded to guard against potential denial of service attacks.</p>
|
||
|
||
<p>However, the optional <code class="language-plaintext highlighter-rouge">max_args</code> function argument can be used to override this limit:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">args</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">get_post_args</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This argument can be set to zero to remove the limit and to process all request arguments received:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">args</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">get_post_args</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Removing the <code class="language-plaintext highlighter-rouge">max_args</code> cap is strongly discouraged.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqget_headers">ngx.req.get_headers</h2>
|
||
<p><strong>syntax:</strong> <em>headers = ngx.req.get_headers(max_headers?, raw?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua, log_by_lua**</p>
|
||
|
||
<p>Returns a Lua table holding all the current request headers.</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">h</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">get_headers</span><span class="p">()</span>
|
||
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="k">in</span> <span class="nb">pairs</span><span class="p">(</span><span class="n">h</span><span class="p">)</span> <span class="k">do</span>
|
||
<span class="o">...</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>To read an individual header:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"Host: "</span><span class="p">,</span> <span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">get_headers</span><span class="p">()[</span><span class="s2">"Host"</span><span class="p">])</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Note that the <a href="#ngxvarvariable">ngx.var.HEADER</a> API call, which uses core <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#var_http_">$http_HEADER</a> variables, may be more preferable for reading individual request headers.</p>
|
||
|
||
<p>For multiple instances of request headers such as:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
Foo: foo
|
||
Foo: bar
|
||
Foo: baz
|
||
</code></pre></div></div>
|
||
|
||
<p>the value of <code class="language-plaintext highlighter-rouge">ngx.req.get_headers()["Foo"]</code> will be a Lua (array) table such as:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="p">{</span><span class="s2">"foo"</span><span class="p">,</span> <span class="s2">"bar"</span><span class="p">,</span> <span class="s2">"baz"</span><span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Note that a maximum of 100 request headers are parsed by default (including those with the same name) and that additional request headers are silently discarded to guard against potential denial of service attacks.</p>
|
||
|
||
<p>However, the optional <code class="language-plaintext highlighter-rouge">max_headers</code> function argument can be used to override this limit:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">headers</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">get_headers</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This argument can be set to zero to remove the limit and to process all request headers received:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">headers</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">get_headers</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Removing the <code class="language-plaintext highlighter-rouge">max_headers</code> cap is strongly discouraged.</p>
|
||
|
||
<p>Since the <code class="language-plaintext highlighter-rouge">0.6.9</code> release, all the header names in the Lua table returned are converted to the pure lower-case form by default, unless the <code class="language-plaintext highlighter-rouge">raw</code> argument is set to <code class="language-plaintext highlighter-rouge">true</code> (default to <code class="language-plaintext highlighter-rouge">false</code>).</p>
|
||
|
||
<p>Also, by default, an <code class="language-plaintext highlighter-rouge">__index</code> metamethod is added to the resulting Lua table and will normalize the keys to a pure lowercase form with all underscores converted to dashes in case of a lookup miss. For example, if a request header <code class="language-plaintext highlighter-rouge">My-Foo-Header</code> is present, then the following invocations will all pick up the value of this header correctly:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="n">headers</span><span class="p">.</span><span class="n">my_foo_header</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="n">headers</span><span class="p">[</span><span class="s2">"My-Foo-Header"</span><span class="p">])</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="n">headers</span><span class="p">[</span><span class="s2">"my-foo-header"</span><span class="p">])</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">__index</code> metamethod will not be added when the <code class="language-plaintext highlighter-rouge">raw</code> argument is set to <code class="language-plaintext highlighter-rouge">true</code>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqset_header">ngx.req.set_header</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.req.set_header(header_name, header_value)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua*</p>
|
||
|
||
<p>Set the current request’s request header named <code class="language-plaintext highlighter-rouge">header_name</code> to value <code class="language-plaintext highlighter-rouge">header_value</code>, overriding any existing ones.</p>
|
||
|
||
<p>By default, all the subrequests subsequently initiated by <a href="#ngxlocationcapture">ngx.location.capture</a> and <a href="#ngxlocationcapture_multi">ngx.location.capture_multi</a> will inherit the new header.</p>
|
||
|
||
<p>Here is an example of setting the <code class="language-plaintext highlighter-rouge">Content-Type</code> header:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">set_header</span><span class="p">(</span><span class="s2">"Content-Type"</span><span class="p">,</span> <span class="s2">"text/css"</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">header_value</code> can take an array list of values,
|
||
for example,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">set_header</span><span class="p">(</span><span class="s2">"Foo"</span><span class="p">,</span> <span class="p">{</span><span class="s2">"a"</span><span class="p">,</span> <span class="s2">"abc"</span><span class="p">})</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>will produce two new request headers:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
Foo: a
|
||
Foo: abc
|
||
</code></pre></div></div>
|
||
|
||
<p>and old <code class="language-plaintext highlighter-rouge">Foo</code> headers will be overridden if there is any.</p>
|
||
|
||
<p>When the <code class="language-plaintext highlighter-rouge">header_value</code> argument is <code class="language-plaintext highlighter-rouge">nil</code>, the request header will be removed. So</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">set_header</span><span class="p">(</span><span class="s2">"X-Foo"</span><span class="p">,</span> <span class="kc">nil</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>is equivalent to</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">clear_header</span><span class="p">(</span><span class="s2">"X-Foo"</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqclear_header">ngx.req.clear_header</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.req.clear_header(header_name)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua**</p>
|
||
|
||
<p>Clears the current request’s request header named <code class="language-plaintext highlighter-rouge">header_name</code>. None of the current request’s existing subrequests will be affected but subsequently initiated subrequests will inherit the change by default.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqread_body">ngx.req.read_body</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.req.read_body()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Reads the client request body synchronously without blocking the Nginx event loop.</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">read_body</span><span class="p">()</span>
|
||
<span class="kd">local</span> <span class="n">args</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">get_post_args</span><span class="p">()</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>If the request body is already read previously by turning on <a href="#lua_need_request_body">lua_need_request_body</a> or by using other modules, then this function does not run and returns immediately.</p>
|
||
|
||
<p>If the request body has already been explicitly discarded, either by the <a href="#ngxreqdiscard_body">ngx.req.discard_body</a> function or other modules, this function does not run and returns immediately.</p>
|
||
|
||
<p>In case of errors, such as connection errors while reading the data, this method will throw out a Lua exception <em>or</em> terminate the current request with a 500 status code immediately.</p>
|
||
|
||
<p>The request body data read using this function can be retrieved later via <a href="#ngxreqget_body_data">ngx.req.get_body_data</a> or, alternatively, the temporary file name for the body data cached to disk using <a href="#ngxreqget_body_file">ngx.req.get_body_file</a>. This depends on</p>
|
||
|
||
<ol>
|
||
<li>whether the current request body is already larger than the <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_buffer_size">client_body_buffer_size</a>,</li>
|
||
<li>and whether <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_in_file_only">client_body_in_file_only</a> has been switched on.</li>
|
||
</ol>
|
||
|
||
<p>In cases where current request may have a request body and the request body data is not required, The <a href="#ngxreqdiscard_body">ngx.req.discard_body</a> function must be used to explicitly discard the request body to avoid breaking things under HTTP 1.1 keepalive or HTTP 1.1 pipelining.</p>
|
||
|
||
<p>This function was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc17</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqdiscard_body">ngx.req.discard_body</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.req.discard_body()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Explicitly discard the request body, i.e., read the data on the connection and throw it away immediately. Please note that ignoring request body is not the right way to discard it, and that this function must be called to avoid breaking things under HTTP 1.1 keepalive or HTTP 1.1 pipelining.</p>
|
||
|
||
<p>This function is an asynchronous call and returns immediately.</p>
|
||
|
||
<p>If the request body has already been read, this function does nothing and returns immediately.</p>
|
||
|
||
<p>This function was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc17</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxreqread_body">ngx.req.read_body</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqget_body_data">ngx.req.get_body_data</h2>
|
||
<p><strong>syntax:</strong> <em>data = ngx.req.get_body_data()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Retrieves in-memory request body data. It returns a Lua string rather than a Lua table holding all the parsed query arguments. Use the <a href="#ngxreqget_post_args">ngx.req.get_post_args</a> function instead if a Lua table is required.</p>
|
||
|
||
<p>This function returns <code class="language-plaintext highlighter-rouge">nil</code> if</p>
|
||
|
||
<ol>
|
||
<li>the request body has not been read,</li>
|
||
<li>the request body has been read into disk temporary files,</li>
|
||
<li>or the request body has zero size.</li>
|
||
</ol>
|
||
|
||
<p>If the request body has not been read yet, call <a href="#ngxreqread_body">ngx.req.read_body</a> first (or turned on <a href="#lua_need_request_body">lua_need_request_body</a> to force this module to read the request body. This is not recommended however).</p>
|
||
|
||
<p>If the request body has been read into disk files, try calling the <a href="#ngxreqget_body_file">ngx.req.get_body_file</a> function instead.</p>
|
||
|
||
<p>To force in-memory request bodies, try setting <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_buffer_size">client_body_buffer_size</a> to the same size value in <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size">client_max_body_size</a>.</p>
|
||
|
||
<p>Note that calling this function instead of using <code class="language-plaintext highlighter-rouge">ngx.var.request_body</code> or <code class="language-plaintext highlighter-rouge">ngx.var.echo_request_body</code> is more efficient because it can save one dynamic memory allocation and one data copy.</p>
|
||
|
||
<p>This function was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc17</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxreqget_body_file">ngx.req.get_body_file</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqget_body_file">ngx.req.get_body_file</h2>
|
||
<p><strong>syntax:</strong> <em>file_name = ngx.req.get_body_file()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Retrieves the file name for the in-file request body data. Returns <code class="language-plaintext highlighter-rouge">nil</code> if the request body has not been read or has been read into memory.</p>
|
||
|
||
<p>The returned file is read only and is usually cleaned up by Nginx’s memory pool. It should not be manually modified, renamed, or removed in Lua code.</p>
|
||
|
||
<p>If the request body has not been read yet, call <a href="#ngxreqread_body">ngx.req.read_body</a> first (or turned on <a href="#lua_need_request_body">lua_need_request_body</a> to force this module to read the request body. This is not recommended however).</p>
|
||
|
||
<p>If the request body has been read into memory, try calling the <a href="#ngxreqget_body_data">ngx.req.get_body_data</a> function instead.</p>
|
||
|
||
<p>To force in-file request bodies, try turning on <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_in_file_only">client_body_in_file_only</a>.</p>
|
||
|
||
<p>This function was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc17</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxreqget_body_data">ngx.req.get_body_data</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqset_body_data">ngx.req.set_body_data</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.req.set_body_data(data)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Set the current request’s request body using the in-memory data specified by the <code class="language-plaintext highlighter-rouge">data</code> argument.</p>
|
||
|
||
<p>If the current request’s request body has not been read, then it will be properly discarded. When the current request’s request body has been read into memory or buffered into a disk file, then the old request body’s memory will be freed or the disk file will be cleaned up immediately, respectively.</p>
|
||
|
||
<p>This function was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc18</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxreqset_body_file">ngx.req.set_body_file</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqset_body_file">ngx.req.set_body_file</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.req.set_body_file(file_name, auto_clean?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Set the current request’s request body using the in-file data specified by the <code class="language-plaintext highlighter-rouge">file_name</code> argument.</p>
|
||
|
||
<p>If the optional <code class="language-plaintext highlighter-rouge">auto_clean</code> argument is given a <code class="language-plaintext highlighter-rouge">true</code> value, then this file will be removed at request completion or the next time this function or <a href="#ngxreqset_body_data">ngx.req.set_body_data</a> are called in the same request. The <code class="language-plaintext highlighter-rouge">auto_clean</code> is default to <code class="language-plaintext highlighter-rouge">false</code>.</p>
|
||
|
||
<p>Please ensure that the file specified by the <code class="language-plaintext highlighter-rouge">file_name</code> argument exists and is readable by an Nginx worker process by setting its permission properly to avoid Lua exception errors.</p>
|
||
|
||
<p>If the current request’s request body has not been read, then it will be properly discarded. When the current request’s request body has been read into memory or buffered into a disk file, then the old request body’s memory will be freed or the disk file will be cleaned up immediately, respectively.</p>
|
||
|
||
<p>This function was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc18</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxreqset_body_data">ngx.req.set_body_data</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqinit_body">ngx.req.init_body</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.req.init_body(buffer_size?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua**</p>
|
||
|
||
<p>Creates a new blank request body for the current request and inializes the buffer for later request body data writing via the <a href="#ngxreqappend_body">ngx.req.append_body</a> and <a href="#ngxreqfinish_body">ngx.req.finish_body</a> APIs.</p>
|
||
|
||
<p>If the <code class="language-plaintext highlighter-rouge">buffer_size</code> argument is specified, then its value will be used for the size of the memory buffer for body writing with <a href="#ngxreqappend_body">ngx.req.append_body</a>. If the argument is omitted, then the value specified by the standard <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_buffer_size">client_body_buffer_size</a> directive will be used instead.</p>
|
||
|
||
<p>When the data can no longer be hold in the memory buffer for the request body, then the data will be flushed onto a temporary file just like the standard request body reader in the Nginx core.</p>
|
||
|
||
<p>It is important to always call the <a href="#ngxreqfinish_body">ngx.req.finish_body</a> after all the data has been appended onto the current request body. Also, when this function is used together with <a href="#ngxreqsocket">ngx.req.socket</a>, it is required to call <a href="#ngxreqsocket">ngx.req.socket</a> <em>before</em> this function, or you will get the “request body already exists” error message.</p>
|
||
|
||
<p>The usage of this function is often like this:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">init_body</span><span class="p">(</span><span class="mi">128</span> <span class="o">*</span> <span class="mi">1024</span><span class="p">)</span> <span class="c1">-- buffer is 128KB</span>
|
||
<span class="k">for</span> <span class="n">chunk</span> <span class="k">in</span> <span class="n">next_data_chunk</span><span class="p">()</span> <span class="k">do</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">append_body</span><span class="p">(</span><span class="n">chunk</span><span class="p">)</span> <span class="c1">-- each chunk can be 4KB</span>
|
||
<span class="k">end</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">req</span><span class="p">.</span><span class="n">finish_body</span><span class="p">()</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This function can be used with <a href="#ngxreqappend_body">ngx.req.append_body</a>, <a href="#ngxreqfinish_body">ngx.req.finish_body</a>, and <a href="#ngxreqsocket">ngx.req.socket</a> to implement efficient input filters in pure Lua (in the context of <a href="#rewrite_by_lua">rewrite_by_lua</a>* or <a href="#access_by_lua">access_by_lua</a>*), which can be used with other Nginx content handler or upstream modules like <a href="http://nginx.org/en/docs/http/ngx_http_proxy_module.html">ngx_http_proxy_module</a> and <a href="http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html">ngx_http_fastcgi_module</a>.</p>
|
||
|
||
<p>This function was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.11</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqappend_body">ngx.req.append_body</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.req.append_body(data_chunk)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua**</p>
|
||
|
||
<p>Append new data chunk specified by the <code class="language-plaintext highlighter-rouge">data_chunk</code> argument onto the existing request body created by the <a href="#ngxreqinit_body">ngx.req.init_body</a> call.</p>
|
||
|
||
<p>When the data can no longer be hold in the memory buffer for the request body, then the data will be flushed onto a temporary file just like the standard request body reader in the Nginx core.</p>
|
||
|
||
<p>It is important to always call the <a href="#ngxreqfinish_body">ngx.req.finish_body</a> after all the data has been appended onto the current request body.</p>
|
||
|
||
<p>This function can be used with <a href="#ngxreqinit_body">ngx.req.init_body</a>, <a href="#ngxreqfinish_body">ngx.req.finish_body</a>, and <a href="#ngxreqsocket">ngx.req.socket</a> to implement efficient input filters in pure Lua (in the context of <a href="#rewrite_by_lua">rewrite_by_lua</a>* or <a href="#access_by_lua">access_by_lua</a>*), which can be used with other Nginx content handler or upstream modules like <a href="http://nginx.org/en/docs/http/ngx_http_proxy_module.html">ngx_http_proxy_module</a> and <a href="http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html">ngx_http_fastcgi_module</a>.</p>
|
||
|
||
<p>This function was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.11</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxreqinit_body">ngx.req.init_body</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqfinish_body">ngx.req.finish_body</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.req.finish_body()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua**</p>
|
||
|
||
<p>Completes the construction process of the new request body created by the <a href="#ngxreqinit_body">ngx.req.init_body</a> and <a href="#ngxreqappend_body">ngx.req.append_body</a> calls.</p>
|
||
|
||
<p>This function can be used with <a href="#ngxreqinit_body">ngx.req.init_body</a>, <a href="#ngxreqappend_body">ngx.req.append_body</a>, and <a href="#ngxreqsocket">ngx.req.socket</a> to implement efficient input filters in pure Lua (in the context of <a href="#rewrite_by_lua">rewrite_by_lua</a>* or <a href="#access_by_lua">access_by_lua</a>*), which can be used with other Nginx content handler or upstream modules like <a href="http://nginx.org/en/docs/http/ngx_http_proxy_module.html">ngx_http_proxy_module</a> and <a href="http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html">ngx_http_fastcgi_module</a>.</p>
|
||
|
||
<p>This function was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.11</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxreqinit_body">ngx.req.init_body</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxreqsocket">ngx.req.socket</h2>
|
||
<p><strong>syntax:</strong> <em>tcpsock, err = ngx.req.socket()</em></p>
|
||
|
||
<p><strong>syntax:</strong> <em>tcpsock, err = ngx.req.socket(raw)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Returns a read-only cosocket object that wraps the downstream connection. Only <a href="#tcpsockreceive">receive</a> and <a href="#tcpsockreceiveuntil">receiveuntil</a> methods are supported on this object.</p>
|
||
|
||
<p>In case of error, <code class="language-plaintext highlighter-rouge">nil</code> will be returned as well as a string describing the error.</p>
|
||
|
||
<p>The socket object returned by this method is usually used to read the current request’s body in a streaming fashion. Do not turn on the <a href="#lua_need_request_body">lua_need_request_body</a> directive, and do not mix this call with <a href="#ngxreqread_body">ngx.req.read_body</a> and <a href="#ngxreqdiscard_body">ngx.req.discard_body</a>.</p>
|
||
|
||
<p>If any request body data has been pre-read into the Nginx core request header buffer, the resulting cosocket object will take care of this to avoid potential data loss resulting from such pre-reading.
|
||
Chunked request bodies are not yet supported in this API.</p>
|
||
|
||
<p>Since the <code class="language-plaintext highlighter-rouge">v0.9.0</code> release, this function accepts an optional boolean <code class="language-plaintext highlighter-rouge">raw</code> argument. When this argument is <code class="language-plaintext highlighter-rouge">true</code>, this function returns a full-duplex cosocket object wrapping around the raw downstream connection socket, upon which you can call the <a href="#tcpsockreceive">receive</a>, <a href="#tcpsockreceiveuntil">receiveuntil</a>, and <a href="#tcpsocksend">send</a> methods.</p>
|
||
|
||
<p>When the <code class="language-plaintext highlighter-rouge">raw</code> argument is <code class="language-plaintext highlighter-rouge">true</code>, it is required that no pending data from any previous <a href="#ngxsay">ngx.say</a>, <a href="#ngxprint">ngx.print</a>, or <a href="#ngxsend_headers">ngx.send_headers</a> calls exists. So if you have these downstream output calls previously, you should call <a href="#ngxflush">ngx.flush(true)</a> before calling <code class="language-plaintext highlighter-rouge">ngx.req.socket(true)</code> to ensure that there is no pending output data. If the request body has not been read yet, then this “raw socket” can also be used to read the request body.</p>
|
||
|
||
<p>You can use the “raw request socket” returned by <code class="language-plaintext highlighter-rouge">ngx.req.socket(true)</code> to implement fancy protocols like <a href="http://en.wikipedia.org/wiki/WebSocket">WebSocket</a>, or just emit your own raw HTTP response header or body data. You can refer to the <a href="https://github.com/openresty/lua-resty-websocket">lua-resty-websocket library</a> for a real world example.</p>
|
||
|
||
<p>This function was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxexec">ngx.exec</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.exec(uri, args?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Does an internal redirect to <code class="language-plaintext highlighter-rouge">uri</code> with <code class="language-plaintext highlighter-rouge">args</code> and is similar to the <a href="http://github.com/openresty/echo-nginx-module#echo_exec">echo_exec</a> directive of the <a href="http://github.com/openresty/echo-nginx-module">echo-nginx-module</a>.</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">exec</span><span class="p">(</span><span class="s1">'/some-location'</span><span class="p">);</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">exec</span><span class="p">(</span><span class="s1">'/some-location'</span><span class="p">,</span> <span class="s1">'a=3&b=5&c=6'</span><span class="p">);</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">exec</span><span class="p">(</span><span class="s1">'/some-location?a=3&b=5'</span><span class="p">,</span> <span class="s1">'c=6'</span><span class="p">);</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>The optional second <code class="language-plaintext highlighter-rouge">args</code> can be used to specify extra URI query arguments, for example:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">exec</span><span class="p">(</span><span class="s2">"/foo"</span><span class="p">,</span> <span class="s2">"a=3&b=hello%20world"</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Alternatively, a Lua table can be passed for the <code class="language-plaintext highlighter-rouge">args</code> argument for ngx_lua to carry out URI escaping and string concatenation.</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">exec</span><span class="p">(</span><span class="s2">"/foo"</span><span class="p">,</span> <span class="p">{</span> <span class="n">a</span> <span class="o">=</span> <span class="mi">3</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="s2">"hello world"</span> <span class="p">})</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>The result is exactly the same as the previous example.</p>
|
||
|
||
<p>The format for the Lua table passed as the <code class="language-plaintext highlighter-rouge">args</code> argument is identical to the format used in the <a href="#ngxencode_args">ngx.encode_args</a> method.</p>
|
||
|
||
<p>Named locations are also supported but the second <code class="language-plaintext highlighter-rouge">args</code> argument will be ignored if present and the querystring for the new target is inherited from the referring location (if any).</p>
|
||
|
||
<p><code class="language-plaintext highlighter-rouge">GET /foo/file.php?a=hello</code> will return “hello” and not “goodbye” in the example below</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/foo</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">ngx.exec("@bar",</span> <span class="s">"a=goodbye")</span><span class="p">;</span>
|
||
<span class="kn">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="k">location</span> <span class="s">@bar</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">args</span> <span class="p">=</span> <span class="s">ngx.req.get_uri_args()</span>
|
||
<span class="s">for</span> <span class="s">key,</span> <span class="s">val</span> <span class="s">in</span> <span class="s">pairs(args)</span> <span class="s">do</span>
|
||
<span class="s">if</span> <span class="s">key</span> <span class="p">==</span> <span class="s">"a"</span> <span class="s">then</span>
|
||
<span class="s">ngx.say(val)</span>
|
||
<span class="s">end</span>
|
||
<span class="s">end</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Note that the <code class="language-plaintext highlighter-rouge">ngx.exec</code> method is different from <a href="#ngxredirect">ngx.redirect</a> in that
|
||
it is purely an internal redirect and that no new external HTTP traffic is involved.</p>
|
||
|
||
<p>Also note that this method call terminates the processing of the current request and that it <em>must</em> be called before <a href="#ngxsend_headers">ngx.send_headers</a> or explicit response body
|
||
outputs by either <a href="#ngxprint">ngx.print</a> or <a href="#ngxsay">ngx.say</a>.</p>
|
||
|
||
<p>It is recommended that a coding style that combines this method call with the <code class="language-plaintext highlighter-rouge">return</code> statement, i.e., <code class="language-plaintext highlighter-rouge">return ngx.exec(...)</code> be adopted when this method call is used in contexts other than <a href="#header_filter_by_lua">header_filter_by_lua</a> to reinforce the fact that the request processing is being terminated.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxredirect">ngx.redirect</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.redirect(uri, status?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Issue an <code class="language-plaintext highlighter-rouge">HTTP 301</code> or <code class="language-plaintext highlighter-rouge">302</code> redirection to <code class="language-plaintext highlighter-rouge">uri</code>.</p>
|
||
|
||
<p>The optional <code class="language-plaintext highlighter-rouge">status</code> parameter specifies whether
|
||
<code class="language-plaintext highlighter-rouge">301</code> or <code class="language-plaintext highlighter-rouge">302</code> to be used. It is <code class="language-plaintext highlighter-rouge">302</code> (<code class="language-plaintext highlighter-rouge">ngx.HTTP_MOVED_TEMPORARILY</code>) by default.</p>
|
||
|
||
<p>Here is an example assuming the current server name is <code class="language-plaintext highlighter-rouge">localhost</code> and that it is listening on port 1984:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">return</span> <span class="n">ngx</span><span class="p">.</span><span class="n">redirect</span><span class="p">(</span><span class="s2">"/foo"</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>which is equivalent to</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">return</span> <span class="n">ngx</span><span class="p">.</span><span class="n">redirect</span><span class="p">(</span><span class="s2">"/foo"</span><span class="p">,</span> <span class="n">ngx</span><span class="p">.</span><span class="n">HTTP_MOVED_TEMPORARILY</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Redirecting arbitrary external URLs is also supported, for example:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">return</span> <span class="n">ngx</span><span class="p">.</span><span class="n">redirect</span><span class="p">(</span><span class="s2">"http://www.google.com"</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>We can also use the numerical code directly as the second <code class="language-plaintext highlighter-rouge">status</code> argument:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">return</span> <span class="n">ngx</span><span class="p">.</span><span class="n">redirect</span><span class="p">(</span><span class="s2">"/foo"</span><span class="p">,</span> <span class="mi">301</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This method is similar to the <a href="http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite">rewrite</a> directive with the <code class="language-plaintext highlighter-rouge">redirect</code> modifier in the standard
|
||
<a href="http://nginx.org/en/docs/http/ngx_http_rewrite_module.html">ngx_http_rewrite_module</a>, for example, this <code class="language-plaintext highlighter-rouge">nginx.conf</code> snippet</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">rewrite</span> <span class="s">^</span> <span class="n">/foo?</span> <span class="s">redirect</span><span class="p">;</span> <span class="c1"># nginx config</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>is equivalent to the following Lua code</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">return</span> <span class="n">ngx</span><span class="p">.</span><span class="n">redirect</span><span class="p">(</span><span class="s1">'/foo'</span><span class="p">);</span> <span class="c1">-- Lua code</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>while</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">rewrite</span> <span class="s">^</span> <span class="n">/foo?</span> <span class="s">permanent</span><span class="p">;</span> <span class="c1"># nginx config</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>is equivalent to</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">return</span> <span class="n">ngx</span><span class="p">.</span><span class="n">redirect</span><span class="p">(</span><span class="s1">'/foo'</span><span class="p">,</span> <span class="n">ngx</span><span class="p">.</span><span class="n">HTTP_MOVED_PERMANENTLY</span><span class="p">)</span> <span class="c1">-- Lua code</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>URI arguments can be specified as well, for example:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">return</span> <span class="n">ngx</span><span class="p">.</span><span class="n">redirect</span><span class="p">(</span><span class="s1">'/foo?a=3&b=4'</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Note that this method call terminates the processing of the current request and that it <em>must</em> be called before <a href="#ngxsend_headers">ngx.send_headers</a> or explicit response body
|
||
outputs by either <a href="#ngxprint">ngx.print</a> or <a href="#ngxsay">ngx.say</a>.</p>
|
||
|
||
<p>It is recommended that a coding style that combines this method call with the <code class="language-plaintext highlighter-rouge">return</code> statement, i.e., <code class="language-plaintext highlighter-rouge">return ngx.redirect(...)</code> be adopted when this method call is used in contexts other than <a href="#header_filter_by_lua">header_filter_by_lua</a> to reinforce the fact that the request processing is being terminated.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxsend_headers">ngx.send_headers</h2>
|
||
<p><strong>syntax:</strong> <em>ok, err = ngx.send_headers()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Explicitly send out the response headers.</p>
|
||
|
||
<p>Since <code class="language-plaintext highlighter-rouge">v0.8.3</code> this function returns <code class="language-plaintext highlighter-rouge">1</code> on success, or returns <code class="language-plaintext highlighter-rouge">nil</code> and a string describing the error otherwise.</p>
|
||
|
||
<p>Note that there is normally no need to manually send out response headers as ngx_lua will automatically send headers out
|
||
before content is output with <a href="#ngxsay">ngx.say</a> or <a href="#ngxprint">ngx.print</a> or when <a href="#content_by_lua">content_by_lua</a> exits normally.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxheaders_sent">ngx.headers_sent</h2>
|
||
<p><strong>syntax:</strong> <em>value = ngx.headers_sent</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua**</p>
|
||
|
||
<p>Returns <code class="language-plaintext highlighter-rouge">true</code> if the response headers have been sent (by ngx_lua), and <code class="language-plaintext highlighter-rouge">false</code> otherwise.</p>
|
||
|
||
<p>This API was first introduced in ngx_lua v0.3.1rc6.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxprint">ngx.print</h2>
|
||
<p><strong>syntax:</strong> <em>ok, err = ngx.print(…)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Emits arguments concatenated to the HTTP client (as response body). If response headers have not been sent, this function will send headers out first and then output body data.</p>
|
||
|
||
<p>Since <code class="language-plaintext highlighter-rouge">v0.8.3</code> this function returns <code class="language-plaintext highlighter-rouge">1</code> on success, or returns <code class="language-plaintext highlighter-rouge">nil</code> and a string describing the error otherwise.</p>
|
||
|
||
<p>Lua <code class="language-plaintext highlighter-rouge">nil</code> values will output <code class="language-plaintext highlighter-rouge">"nil"</code> strings and Lua boolean values will output <code class="language-plaintext highlighter-rouge">"true"</code> and <code class="language-plaintext highlighter-rouge">"false"</code> literal strings respectively.</p>
|
||
|
||
<p>Nested arrays of strings are permitted and the elements in the arrays will be sent one by one:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">table</span> <span class="o">=</span> <span class="p">{</span>
|
||
<span class="s2">"hello, "</span><span class="p">,</span>
|
||
<span class="p">{</span><span class="s2">"world: "</span><span class="p">,</span> <span class="kc">true</span><span class="p">,</span> <span class="s2">" or "</span><span class="p">,</span> <span class="kc">false</span><span class="p">,</span>
|
||
<span class="p">{</span><span class="s2">": "</span><span class="p">,</span> <span class="kc">nil</span><span class="p">}}</span>
|
||
<span class="p">}</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">print</span><span class="p">(</span><span class="n">table</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>will yield the output</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
hello, world: <span class="nb">true </span>or <span class="nb">false</span>: nil
|
||
</code></pre></div></div>
|
||
|
||
<p>Non-array table arguments will cause a Lua exception to be thrown.</p>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">ngx.null</code> constant will yield the <code class="language-plaintext highlighter-rouge">"null"</code> string output.</p>
|
||
|
||
<p>This is an asynchronous call and will return immediately without waiting for all the data to be written into the system send buffer. To run in synchronous mode, call <code class="language-plaintext highlighter-rouge">ngx.flush(true)</code> after calling <code class="language-plaintext highlighter-rouge">ngx.print</code>. This can be particularly useful for streaming output. See <a href="#ngxflush">ngx.flush</a> for more details.</p>
|
||
|
||
<p>Please note that both <code class="language-plaintext highlighter-rouge">ngx.print</code> and <a href="#ngxsay">ngx.say</a> will always invoke the whole Nginx output body filter chain, which is an expensive operation. So be careful when calling either of these two in a tight loop; buffer the data yourself in Lua and save the calls.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxsay">ngx.say</h2>
|
||
<p><strong>syntax:</strong> <em>ok, err = ngx.say(…)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Just as <a href="#ngxprint">ngx.print</a> but also emit a trailing newline.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxlog">ngx.log</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.log(log_level, …)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, init_worker_by_lua<em>, set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Log arguments concatenated to error.log with the given logging level.</p>
|
||
|
||
<p>Lua <code class="language-plaintext highlighter-rouge">nil</code> arguments are accepted and result in literal <code class="language-plaintext highlighter-rouge">"nil"</code> string while Lua booleans result in literal <code class="language-plaintext highlighter-rouge">"true"</code> or <code class="language-plaintext highlighter-rouge">"false"</code> string outputs. And the <code class="language-plaintext highlighter-rouge">ngx.null</code> constant will yield the <code class="language-plaintext highlighter-rouge">"null"</code> string output.</p>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">log_level</code> argument can take constants like <code class="language-plaintext highlighter-rouge">ngx.ERR</code> and <code class="language-plaintext highlighter-rouge">ngx.WARN</code>. Check out <a href="#nginx-log-level-constants">Nginx log level constants</a> for details.</p>
|
||
|
||
<p>There is a hard coded <code class="language-plaintext highlighter-rouge">2048</code> byte limitation on error message lengths in the Nginx core. This limit includes trailing newlines and leading time stamps. If the message size exceeds this limit, Nginx will truncate the message text accordingly. This limit can be manually modified by editing the <code class="language-plaintext highlighter-rouge">NGX_MAX_ERROR_STR</code> macro definition in the <code class="language-plaintext highlighter-rouge">src/core/ngx_log.h</code> file in the Nginx source tree.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxflush">ngx.flush</h2>
|
||
<p><strong>syntax:</strong> <em>ok, err = ngx.flush(wait?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Flushes response output to the client.</p>
|
||
|
||
<p><code class="language-plaintext highlighter-rouge">ngx.flush</code> accepts an optional boolean <code class="language-plaintext highlighter-rouge">wait</code> argument (Default: <code class="language-plaintext highlighter-rouge">false</code>) first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc34</code> release. When called with the default argument, it issues an asynchronous call (Returns immediately without waiting for output data to be written into the system send buffer). Calling the function with the <code class="language-plaintext highlighter-rouge">wait</code> argument set to <code class="language-plaintext highlighter-rouge">true</code> switches to synchronous mode.</p>
|
||
|
||
<p>In synchronous mode, the function will not return until all output data has been written into the system send buffer or until the <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#send_timeout">send_timeout</a> setting has expired. Note that using the Lua coroutine mechanism means that this function does not block the Nginx event loop even in the synchronous mode.</p>
|
||
|
||
<p>When <code class="language-plaintext highlighter-rouge">ngx.flush(true)</code> is called immediately after <a href="#ngxprint">ngx.print</a> or <a href="#ngxsay">ngx.say</a>, it causes the latter functions to run in synchronous mode. This can be particularly useful for streaming output.</p>
|
||
|
||
<p>Note that <code class="language-plaintext highlighter-rouge">ngx.flush</code> is not functional when in the HTTP 1.0 output buffering mode. See <a href="#http-10-support">HTTP 1.0 support</a>.</p>
|
||
|
||
<p>Since <code class="language-plaintext highlighter-rouge">v0.8.3</code> this function returns <code class="language-plaintext highlighter-rouge">1</code> on success, or returns <code class="language-plaintext highlighter-rouge">nil</code> and a string describing the error otherwise.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxexit">ngx.exit</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.exit(status)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>When <code class="language-plaintext highlighter-rouge">status >= 200</code> (i.e., <code class="language-plaintext highlighter-rouge">ngx.HTTP_OK</code> and above), it will interrupt the execution of the current request and return status code to nginx.</p>
|
||
|
||
<p>When <code class="language-plaintext highlighter-rouge">status == 0</code> (i.e., <code class="language-plaintext highlighter-rouge">ngx.OK</code>), it will only quit the current phase handler (or the content handler if the <a href="#content_by_lua">content_by_lua</a> directive is used) and continue to run later phases (if any) for the current request.</p>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">status</code> argument can be <code class="language-plaintext highlighter-rouge">ngx.OK</code>, <code class="language-plaintext highlighter-rouge">ngx.ERROR</code>, <code class="language-plaintext highlighter-rouge">ngx.HTTP_NOT_FOUND</code>,
|
||
<code class="language-plaintext highlighter-rouge">ngx.HTTP_MOVED_TEMPORARILY</code>, or other <a href="#http-status-constants">HTTP status constants</a>.</p>
|
||
|
||
<p>To return an error page with custom contents, use code snippets like this:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">status</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">HTTP_GONE</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"This is our own content"</span><span class="p">)</span>
|
||
<span class="c1">-- to cause quit the whole request rather than the current phase handler</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">exit</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">HTTP_OK</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>The effect in action:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="nv">$ </span>curl <span class="nt">-i</span> http://localhost/test
|
||
HTTP/1.1 410 Gone
|
||
Server: nginx/1.0.6
|
||
Date: Thu, 15 Sep 2011 00:51:48 GMT
|
||
Content-Type: text/plain
|
||
Transfer-Encoding: chunked
|
||
Connection: keep-alive
|
||
|
||
This is our own content
|
||
</code></pre></div></div>
|
||
|
||
<p>Number literals can be used directly as the argument, for instance,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">501</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Note that while this method accepts all <a href="#http-status-constants">HTTP status constants</a> as input, it only accepts <code class="language-plaintext highlighter-rouge">NGX_OK</code> and <code class="language-plaintext highlighter-rouge">NGX_ERROR</code> of the <a href="#core-constants">core constants</a>.</p>
|
||
|
||
<p>Also note that this method call terminates the processing of the current request and that it is recommended that a coding style that combines this method call with the <code class="language-plaintext highlighter-rouge">return</code> statement, i.e., <code class="language-plaintext highlighter-rouge">return ngx.exit(...)</code> be used to reinforce the fact that the request processing is being terminated.</p>
|
||
|
||
<p>When being used in the context of <a href="#header_filter_by_lua">header_filter_by_lua</a>, <code class="language-plaintext highlighter-rouge">ngx.exit()</code> is an asynchronous operation and will return immediately. This behavior may change in future and it is recommended that users always use <code class="language-plaintext highlighter-rouge">return</code> in combination as suggested above.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxeof">ngx.eof</h2>
|
||
<p><strong>syntax:</strong> <em>ok, err = ngx.eof()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Explicitly specify the end of the response output stream. In the case of HTTP 1.1 chunked encoded output, it will just trigger the Nginx core to send out the “last chunk”.</p>
|
||
|
||
<p>When you disable the HTTP 1.1 keep-alive feature for your downstream connections, you can rely on descent HTTP clients to close the connection actively for you when you call this method. This trick can be used do back-ground jobs without letting the HTTP clients to wait on the connection, as in the following example:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="p">=</span> <span class="n">/async</span> <span class="p">{</span>
|
||
<span class="kn">keepalive_timeout</span> <span class="mi">0</span><span class="p">;</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">ngx.say("got</span> <span class="s">the</span> <span class="s">task!")</span>
|
||
<span class="s">ngx.eof()</span> <span class="s">--</span> <span class="s">a</span> <span class="s">descent</span> <span class="s">HTTP</span> <span class="s">client</span> <span class="s">will</span> <span class="s">close</span> <span class="s">the</span> <span class="s">connection</span> <span class="s">at</span> <span class="s">this</span> <span class="s">point</span>
|
||
<span class="s">--</span> <span class="s">access</span> <span class="s">MySQL,</span> <span class="s">PostgreSQL,</span> <span class="s">Redis,</span> <span class="s">Memcached,</span> <span class="s">and</span> <span class="s">etc</span> <span class="s">here...</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>But if you create subrequests to access other locations configured by Nginx upstream modules, then you should configure those upstream modules to ignore client connection abortions if they are not by default. For example, by default the standard <a href="http://nginx.org/en/docs/http/ngx_http_proxy_module.html">ngx_http_proxy_module</a> will terminate both the subrequest and the main request as soon as the client closes the connection, so it is important to turn on the <a href="http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_client_abort">proxy_ignore_client_abort</a> directive in your location block configured by <a href="http://nginx.org/en/docs/http/ngx_http_proxy_module.html">ngx_http_proxy_module</a>:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">proxy_ignore_client_abort</span> <span class="no">on</span><span class="p">;</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>A better way to do background jobs is to use the <a href="#ngxtimerat">ngx.timer.at</a> API.</p>
|
||
|
||
<p>Since <code class="language-plaintext highlighter-rouge">v0.8.3</code> this function returns <code class="language-plaintext highlighter-rouge">1</code> on success, or returns <code class="language-plaintext highlighter-rouge">nil</code> and a string describing the error otherwise.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxsleep">ngx.sleep</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.sleep(seconds)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Sleeps for the specified seconds without blocking. One can specify time resolution up to 0.001 seconds (i.e., one milliseconds).</p>
|
||
|
||
<p>Behind the scene, this method makes use of the Nginx timers.</p>
|
||
|
||
<p>Since the <code class="language-plaintext highlighter-rouge">0.7.20</code> release, The <code class="language-plaintext highlighter-rouge">0</code> time argument can also be specified.</p>
|
||
|
||
<p>This method was introduced in the <code class="language-plaintext highlighter-rouge">0.5.0rc30</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxescape_uri">ngx.escape_uri</h2>
|
||
<p><strong>syntax:</strong> <em>newstr = ngx.escape_uri(str)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, init_worker_by_lua<em>, set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Escape <code class="language-plaintext highlighter-rouge">str</code> as a URI component.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxunescape_uri">ngx.unescape_uri</h2>
|
||
<p><strong>syntax:</strong> <em>newstr = ngx.unescape_uri(str)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, init_worker_by_lua<em>, set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Unescape <code class="language-plaintext highlighter-rouge">str</code> as an escaped URI component.</p>
|
||
|
||
<p>For example,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">unescape_uri</span><span class="p">(</span><span class="s2">"b%20r56+7"</span><span class="p">))</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>gives the output</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>b r56 7
|
||
</code></pre></div></div>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxencode_args">ngx.encode_args</h2>
|
||
<p><strong>syntax:</strong> <em>str = ngx.encode_args(table)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Encode the Lua table to a query args string according to the URI encoded rules.</p>
|
||
|
||
<p>For example,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">encode_args</span><span class="p">({</span><span class="n">foo</span> <span class="o">=</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[</span><span class="s2">"b r"</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"hello world"</span><span class="p">})</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>yields</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>foo=3&b%20r=hello%20world
|
||
</code></pre></div></div>
|
||
|
||
<p>The table keys must be Lua strings.</p>
|
||
|
||
<p>Multi-value query args are also supported. Just use a Lua table for the argument’s value, for example:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">encode_args</span><span class="p">({</span><span class="n">baz</span> <span class="o">=</span> <span class="p">{</span><span class="mi">32</span><span class="p">,</span> <span class="s2">"hello"</span><span class="p">}})</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>gives</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>baz=32&baz=hello
|
||
</code></pre></div></div>
|
||
|
||
<p>If the value table is empty and the effect is equivalent to the <code class="language-plaintext highlighter-rouge">nil</code> value.</p>
|
||
|
||
<p>Boolean argument values are also supported, for instance,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">encode_args</span><span class="p">({</span><span class="n">a</span> <span class="o">=</span> <span class="kc">true</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="mi">1</span><span class="p">})</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>yields</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>a&b=1
|
||
</code></pre></div></div>
|
||
|
||
<p>If the argument value is <code class="language-plaintext highlighter-rouge">false</code>, then the effect is equivalent to the <code class="language-plaintext highlighter-rouge">nil</code> value.</p>
|
||
|
||
<p>This method was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc27</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxdecode_args">ngx.decode_args</h2>
|
||
<p><strong>syntax:</strong> <em>table = ngx.decode_args(str, max_args?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Decodes a URI encoded query-string into a Lua table. This is the inverse function of <a href="#ngxencode_args">ngx.encode_args</a>.</p>
|
||
|
||
<p>The optional <code class="language-plaintext highlighter-rouge">max_args</code> argument can be used to specify the maximum number of arguments parsed from the <code class="language-plaintext highlighter-rouge">str</code> argument. By default, a maximum of 100 request arguments are parsed (including those with the same name) and that additional URI arguments are silently discarded to guard against potential denial of service attacks.</p>
|
||
|
||
<p>This argument can be set to zero to remove the limit and to process all request arguments received:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">args</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">decode_args</span><span class="p">(</span><span class="n">str</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Removing the <code class="language-plaintext highlighter-rouge">max_args</code> cap is strongly discouraged.</p>
|
||
|
||
<p>This method was introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc29</code>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxencode_base64">ngx.encode_base64</h2>
|
||
<p><strong>syntax:</strong> <em>newstr = ngx.encode_base64(str, no_padding?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Encodes <code class="language-plaintext highlighter-rouge">str</code> to a base64 digest.</p>
|
||
|
||
<p>Since the <code class="language-plaintext highlighter-rouge">0.9.16</code> release, an optional boolean-typed <code class="language-plaintext highlighter-rouge">no_padding</code> argument can be specified to control whether the base64 padding should be appended to the resulting digest (default to <code class="language-plaintext highlighter-rouge">false</code>, i.e., with padding enabled). This enables streaming base64 digest calculation by (data chunks) though it would be the caller’s responsibility to append an appropriate padding at the end of data stream.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxdecode_base64">ngx.decode_base64</h2>
|
||
<p><strong>syntax:</strong> <em>newstr = ngx.decode_base64(str)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Decodes the <code class="language-plaintext highlighter-rouge">str</code> argument as a base64 digest to the raw form. Returns <code class="language-plaintext highlighter-rouge">nil</code> if <code class="language-plaintext highlighter-rouge">str</code> is not well formed.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxcrc32_short">ngx.crc32_short</h2>
|
||
<p><strong>syntax:</strong> <em>intval = ngx.crc32_short(str)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Calculates the CRC-32 (Cyclic Redundancy Code) digest for the <code class="language-plaintext highlighter-rouge">str</code> argument.</p>
|
||
|
||
<p>This method performs better on relatively short <code class="language-plaintext highlighter-rouge">str</code> inputs (i.e., less than 30 ~ 60 bytes), as compared to <a href="#ngxcrc32_long">ngx.crc32_long</a>. The result is exactly the same as <a href="#ngxcrc32_long">ngx.crc32_long</a>.</p>
|
||
|
||
<p>Behind the scene, it is just a thin wrapper around the <code class="language-plaintext highlighter-rouge">ngx_crc32_short</code> function defined in the Nginx core.</p>
|
||
|
||
<p>This API was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc8</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxcrc32_long">ngx.crc32_long</h2>
|
||
<p><strong>syntax:</strong> <em>intval = ngx.crc32_long(str)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Calculates the CRC-32 (Cyclic Redundancy Code) digest for the <code class="language-plaintext highlighter-rouge">str</code> argument.</p>
|
||
|
||
<p>This method performs better on relatively long <code class="language-plaintext highlighter-rouge">str</code> inputs (i.e., longer than 30 ~ 60 bytes), as compared to <a href="#ngxcrc32_short">ngx.crc32_short</a>. The result is exactly the same as <a href="#ngxcrc32_short">ngx.crc32_short</a>.</p>
|
||
|
||
<p>Behind the scene, it is just a thin wrapper around the <code class="language-plaintext highlighter-rouge">ngx_crc32_long</code> function defined in the Nginx core.</p>
|
||
|
||
<p>This API was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc8</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxhmac_sha1">ngx.hmac_sha1</h2>
|
||
<p><strong>syntax:</strong> <em>digest = ngx.hmac_sha1(secret_key, str)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Computes the <a href="http://en.wikipedia.org/wiki/HMAC">HMAC-SHA1</a> digest of the argument <code class="language-plaintext highlighter-rouge">str</code> and turns the result using the secret key <code class="language-plaintext highlighter-rouge"><secret_key></code>.</p>
|
||
|
||
<p>The raw binary form of the <code class="language-plaintext highlighter-rouge">HMAC-SHA1</code> digest will be generated, use <a href="#ngxencode_base64">ngx.encode_base64</a>, for example, to encode the result to a textual representation if desired.</p>
|
||
|
||
<p>For example,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">key</span> <span class="o">=</span> <span class="s2">"thisisverysecretstuff"</span>
|
||
<span class="kd">local</span> <span class="n">src</span> <span class="o">=</span> <span class="s2">"some string we want to sign"</span>
|
||
<span class="kd">local</span> <span class="n">digest</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">hmac_sha1</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">src</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">encode_base64</span><span class="p">(</span><span class="n">digest</span><span class="p">))</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>yields the output</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>R/pvxzHC4NLtj7S+kXFg/NePTmk=
|
||
</code></pre></div></div>
|
||
|
||
<p>This API requires the OpenSSL library enabled in the Nginx build (usually by passing the <code class="language-plaintext highlighter-rouge">--with-http_ssl_module</code> option to the <code class="language-plaintext highlighter-rouge">./configure</code> script).</p>
|
||
|
||
<p>This function was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc29</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxmd5">ngx.md5</h2>
|
||
<p><strong>syntax:</strong> <em>digest = ngx.md5(str)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Returns the hexadecimal representation of the MD5 digest of the <code class="language-plaintext highlighter-rouge">str</code> argument.</p>
|
||
|
||
<p>For example,</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="p">=</span> <span class="n">/md5</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'ngx.say(ngx.md5("hello"))'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>yields the output</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>5d41402abc4b2a76b9719d911017c592
|
||
</code></pre></div></div>
|
||
|
||
<p>See <a href="#ngxmd5_bin">ngx.md5_bin</a> if the raw binary MD5 digest is required.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxmd5_bin">ngx.md5_bin</h2>
|
||
<p><strong>syntax:</strong> <em>digest = ngx.md5_bin(str)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Returns the binary form of the MD5 digest of the <code class="language-plaintext highlighter-rouge">str</code> argument.</p>
|
||
|
||
<p>See <a href="#ngxmd5">ngx.md5</a> if the hexadecimal form of the MD5 digest is required.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxsha1_bin">ngx.sha1_bin</h2>
|
||
<p><strong>syntax:</strong> <em>digest = ngx.sha1_bin(str)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Returns the binary form of the SHA-1 digest of the <code class="language-plaintext highlighter-rouge">str</code> argument.</p>
|
||
|
||
<p>This function requires SHA-1 support in the Nginx build. (This usually just means OpenSSL should be installed while building Nginx).</p>
|
||
|
||
<p>This function was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc6</code>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxquote_sql_str">ngx.quote_sql_str</h2>
|
||
<p><strong>syntax:</strong> <em>quoted_value = ngx.quote_sql_str(raw_value)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Returns a quoted SQL string literal according to the MySQL quoting rules.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxtoday">ngx.today</h2>
|
||
<p><strong>syntax:</strong> <em>str = ngx.today()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Returns current date (in the format <code class="language-plaintext highlighter-rouge">yyyy-mm-dd</code>) from the nginx cached time (no syscall involved unlike Lua’s date library).</p>
|
||
|
||
<p>This is the local time.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxtime">ngx.time</h2>
|
||
<p><strong>syntax:</strong> <em>secs = ngx.time()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Returns the elapsed seconds from the epoch for the current time stamp from the nginx cached time (no syscall involved unlike Lua’s date library).</p>
|
||
|
||
<p>Updates of the Nginx time cache an be forced by calling <a href="#ngxupdate_time">ngx.update_time</a> first.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxnow">ngx.now</h2>
|
||
<p><strong>syntax:</strong> <em>secs = ngx.now()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Returns a floating-point number for the elapsed time in seconds (including milliseconds as the decimal part) from the epoch for the current time stamp from the nginx cached time (no syscall involved unlike Lua’s date library).</p>
|
||
|
||
<p>You can forcibly update the Nginx time cache by calling <a href="#ngxupdate_time">ngx.update_time</a> first.</p>
|
||
|
||
<p>This API was first introduced in <code class="language-plaintext highlighter-rouge">v0.3.1rc32</code>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxupdate_time">ngx.update_time</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.update_time()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Forcibly updates the Nginx current time cache. This call involves a syscall and thus has some overhead, so do not abuse it.</p>
|
||
|
||
<p>This API was first introduced in <code class="language-plaintext highlighter-rouge">v0.3.1rc32</code>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxlocaltime">ngx.localtime</h2>
|
||
<p><strong>syntax:</strong> <em>str = ngx.localtime()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Returns the current time stamp (in the format <code class="language-plaintext highlighter-rouge">yyyy-mm-dd hh:mm:ss</code>) of the nginx cached time (no syscall involved unlike Lua’s <a href="http://www.lua.org/manual/5.1/manual.html#pdf-os.date">os.date</a> function).</p>
|
||
|
||
<p>This is the local time.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxutctime">ngx.utctime</h2>
|
||
<p><strong>syntax:</strong> <em>str = ngx.utctime()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Returns the current time stamp (in the format <code class="language-plaintext highlighter-rouge">yyyy-mm-dd hh:mm:ss</code>) of the nginx cached time (no syscall involved unlike Lua’s <a href="http://www.lua.org/manual/5.1/manual.html#pdf-os.date">os.date</a> function).</p>
|
||
|
||
<p>This is the UTC time.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxcookie_time">ngx.cookie_time</h2>
|
||
<p><strong>syntax:</strong> <em>str = ngx.cookie_time(sec)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Returns a formatted string can be used as the cookie expiration time. The parameter <code class="language-plaintext highlighter-rouge">sec</code> is the time stamp in seconds (like those returned from <a href="#ngxtime">ngx.time</a>).</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">ngx.say</span><span class="s">(ngx.cookie_time(1290079655))</span>
|
||
<span class="s">--</span> <span class="s">yields</span> <span class="s">"Thu,</span> <span class="mi">18</span><span class="s">-Nov-10</span> <span class="nf">11</span><span class="p">:</span><span class="mi">27</span><span class="p">:</span><span class="mi">35</span> <span class="s">GMT"</span>
|
||
</code></pre></div></div>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxhttp_time">ngx.http_time</h2>
|
||
<p><strong>syntax:</strong> <em>str = ngx.http_time(sec)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Returns a formated string can be used as the http header time (for example, being used in <code class="language-plaintext highlighter-rouge">Last-Modified</code> header). The parameter <code class="language-plaintext highlighter-rouge">sec</code> is the time stamp in seconds (like those returned from <a href="#ngxtime">ngx.time</a>).</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">ngx.say</span><span class="s">(ngx.http_time(1290079655))</span>
|
||
<span class="s">--</span> <span class="s">yields</span> <span class="s">"Thu,</span> <span class="mi">18</span> <span class="s">Nov</span> <span class="mi">2010</span> <span class="nf">11</span><span class="p">:</span><span class="mi">27</span><span class="p">:</span><span class="mi">35</span> <span class="s">GMT"</span>
|
||
</code></pre></div></div>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxparse_http_time">ngx.parse_http_time</h2>
|
||
<p><strong>syntax:</strong> <em>sec = ngx.parse_http_time(str)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Parse the http time string (as returned by <a href="#ngxhttp_time">ngx.http_time</a>) into seconds. Returns the seconds or <code class="language-plaintext highlighter-rouge">nil</code> if the input string is in bad forms.</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">local</span> <span class="s">time</span> <span class="p">=</span> <span class="s">ngx.parse_http_time("Thu,</span> <span class="mi">18</span> <span class="s">Nov</span> <span class="mi">2010</span> <span class="nf">11</span><span class="p">:</span><span class="mi">27</span><span class="p">:</span><span class="mi">35</span> <span class="s">GMT")</span>
|
||
<span class="s">if</span> <span class="s">time</span> <span class="p">==</span> <span class="s">nil</span> <span class="s">then</span>
|
||
<span class="s">...</span>
|
||
<span class="s">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxis_subrequest">ngx.is_subrequest</h2>
|
||
<p><strong>syntax:</strong> <em>value = ngx.is_subrequest</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua*, log_by_lua**</p>
|
||
|
||
<p>Returns <code class="language-plaintext highlighter-rouge">true</code> if the current request is an nginx subrequest, or <code class="language-plaintext highlighter-rouge">false</code> otherwise.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxrematch">ngx.re.match</h2>
|
||
<p><strong>syntax:</strong> <em>captures, err = ngx.re.match(subject, regex, options?, ctx?, res_table?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Matches the <code class="language-plaintext highlighter-rouge">subject</code> string using the Perl compatible regular expression <code class="language-plaintext highlighter-rouge">regex</code> with the optional <code class="language-plaintext highlighter-rouge">options</code>.</p>
|
||
|
||
<p>Only the first occurrence of the match is returned, or <code class="language-plaintext highlighter-rouge">nil</code> if no match is found. In case of errors, like seeing a bad regular expression or exceeding the PCRE stack limit, <code class="language-plaintext highlighter-rouge">nil</code> and a string describing the error will be returned.</p>
|
||
|
||
<p>When a match is found, a Lua table <code class="language-plaintext highlighter-rouge">captures</code> is returned, where <code class="language-plaintext highlighter-rouge">captures[0]</code> holds the whole substring being matched, and <code class="language-plaintext highlighter-rouge">captures[1]</code> holds the first parenthesized sub-pattern’s capturing, <code class="language-plaintext highlighter-rouge">captures[2]</code> the second, and so on.</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">m</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="n">match</span><span class="p">(</span><span class="s2">"hello, 1234"</span><span class="p">,</span> <span class="s2">"[0-9]+"</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="n">m</span> <span class="k">then</span>
|
||
<span class="c1">-- m[0] == "1234"</span>
|
||
|
||
<span class="k">else</span>
|
||
<span class="k">if</span> <span class="n">err</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">log</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">ERR</span><span class="p">,</span> <span class="s2">"error: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"match not found"</span><span class="p">)</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">m</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="n">match</span><span class="p">(</span><span class="s2">"hello, 1234"</span><span class="p">,</span> <span class="s2">"([0-9])[0-9]+"</span><span class="p">)</span>
|
||
<span class="c1">-- m[0] == "1234"</span>
|
||
<span class="c1">-- m[1] == "1"</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Named captures are also supported since the <code class="language-plaintext highlighter-rouge">v0.7.14</code> release
|
||
and are returned in the same Lua table as key-value pairs as the numbered captures.</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">m</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="n">match</span><span class="p">(</span><span class="s2">"hello, 1234"</span><span class="p">,</span> <span class="s2">"([0-9])(?<remaining>[0-9]+)"</span><span class="p">)</span>
|
||
<span class="c1">-- m[0] == "1234"</span>
|
||
<span class="c1">-- m[1] == "1"</span>
|
||
<span class="c1">-- m[2] == "234"</span>
|
||
<span class="c1">-- m["remaining"] == "234"</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Unmatched subpatterns will have <code class="language-plaintext highlighter-rouge">nil</code> values in their <code class="language-plaintext highlighter-rouge">captures</code> table fields.</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">m</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="n">match</span><span class="p">(</span><span class="s2">"hello, world"</span><span class="p">,</span> <span class="s2">"(world)|(hello)|(?<named>howdy)"</span><span class="p">)</span>
|
||
<span class="c1">-- m[0] == "hello"</span>
|
||
<span class="c1">-- m[1] == nil</span>
|
||
<span class="c1">-- m[2] == "hello"</span>
|
||
<span class="c1">-- m[3] == nil</span>
|
||
<span class="c1">-- m["named"] == nil</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Specify <code class="language-plaintext highlighter-rouge">options</code> to control how the match operation will be performed. The following option characters are supported:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>a anchored mode (only match from the beginning)
|
||
|
||
d enable the DFA mode (or the longest token match semantics).
|
||
this requires PCRE 6.0+ or else a Lua exception will be thrown.
|
||
first introduced in ngx_lua v0.3.1rc30.
|
||
|
||
D enable duplicate named pattern support. This allows named
|
||
subpattern names to be repeated, returning the captures in
|
||
an array-like Lua table. for example,
|
||
local m = ngx.re.match("hello, world",
|
||
"(?<named>\w+), (?<named>\w+)",
|
||
"D")
|
||
-- m["named"] == {"hello", "world"}
|
||
this option was first introduced in the v0.7.14 release.
|
||
this option requires at least PCRE 8.12.
|
||
|
||
i case insensitive mode (similar to Perl's /i modifier)
|
||
|
||
j enable PCRE JIT compilation, this requires PCRE 8.21+ which
|
||
must be built with the --enable-jit option. for optimum performance,
|
||
this option should always be used together with the 'o' option.
|
||
first introduced in ngx_lua v0.3.1rc30.
|
||
|
||
J enable the PCRE Javascript compatible mode. this option was
|
||
first introduced in the v0.7.14 release. this option requires
|
||
at least PCRE 8.12.
|
||
|
||
m multi-line mode (similar to Perl's /m modifier)
|
||
|
||
o compile-once mode (similar to Perl's /o modifier),
|
||
to enable the worker-process-level compiled-regex cache
|
||
|
||
s single-line mode (similar to Perl's /s modifier)
|
||
|
||
u UTF-8 mode. this requires PCRE to be built with
|
||
the --enable-utf8 option or else a Lua exception will be thrown.
|
||
|
||
U similar to "u" but disables PCRE's UTF-8 validity check on
|
||
the subject string. first introduced in ngx_lua v0.8.1.
|
||
|
||
x extended mode (similar to Perl's /x modifier)
|
||
</code></pre></div></div>
|
||
|
||
<p>These options can be combined:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">local</span> <span class="s">m,</span> <span class="s">err</span> <span class="p">=</span> <span class="s">ngx.re.match("hello,</span> <span class="s">world",</span> <span class="s">"HEL</span> <span class="s">LO",</span> <span class="s">"ix")</span>
|
||
<span class="s">--</span> <span class="s">m[0]</span> <span class="p">==</span> <span class="s">"hello"</span>
|
||
</code></pre></div></div>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">local</span> <span class="s">m,</span> <span class="s">err</span> <span class="p">=</span> <span class="s">ngx.re.match("hello,</span> <span class="s">美好生活",</span> <span class="s">"HELLO,</span> <span class="s">(.</span><span class="p">{</span><span class="kn">2</span><span class="err">}</span><span class="s">)",</span> <span class="s">"iu")</span>
|
||
<span class="s">--</span> <span class="s">m[0]</span> <span class="p">==</span> <span class="s">"hello,</span> <span class="s">美好"</span>
|
||
<span class="s">--</span> <span class="s">m[1]</span> <span class="p">==</span> <span class="s">"美好"</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">o</code> option is useful for performance tuning, because the regex pattern in question will only be compiled once, cached in the worker-process level, and shared among all requests in the current Nginx worker process. The upper limit of the regex cache can be tuned via the <a href="#lua_regex_cache_max_entries">lua_regex_cache_max_entries</a> directive.</p>
|
||
|
||
<p>The optional fourth argument, <code class="language-plaintext highlighter-rouge">ctx</code>, can be a Lua table holding an optional <code class="language-plaintext highlighter-rouge">pos</code> field. When the <code class="language-plaintext highlighter-rouge">pos</code> field in the <code class="language-plaintext highlighter-rouge">ctx</code> table argument is specified, <code class="language-plaintext highlighter-rouge">ngx.re.match</code> will start matching from that offset (starting from 1). Regardless of the presence of the <code class="language-plaintext highlighter-rouge">pos</code> field in the <code class="language-plaintext highlighter-rouge">ctx</code> table, <code class="language-plaintext highlighter-rouge">ngx.re.match</code> will always set this <code class="language-plaintext highlighter-rouge">pos</code> field to the position <em>after</em> the substring matched by the whole pattern in case of a successful match. When match fails, the <code class="language-plaintext highlighter-rouge">ctx</code> table will be left intact.</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">ctx</span> <span class="o">=</span> <span class="p">{}</span>
|
||
<span class="kd">local</span> <span class="n">m</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="n">match</span><span class="p">(</span><span class="s2">"1234, hello"</span><span class="p">,</span> <span class="s2">"[0-9]+"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="n">ctx</span><span class="p">)</span>
|
||
<span class="c1">-- m[0] = "1234"</span>
|
||
<span class="c1">-- ctx.pos == 5</span>
|
||
</code></pre></div></div>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">ctx</span> <span class="o">=</span> <span class="p">{</span> <span class="n">pos</span> <span class="o">=</span> <span class="mi">2</span> <span class="p">}</span>
|
||
<span class="kd">local</span> <span class="n">m</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="n">match</span><span class="p">(</span><span class="s2">"1234, hello"</span><span class="p">,</span> <span class="s2">"[0-9]+"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="n">ctx</span><span class="p">)</span>
|
||
<span class="c1">-- m[0] = "34"</span>
|
||
<span class="c1">-- ctx.pos == 5</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">ctx</code> table argument combined with the <code class="language-plaintext highlighter-rouge">a</code> regex modifier can be used to construct a lexer atop <code class="language-plaintext highlighter-rouge">ngx.re.match</code>.</p>
|
||
|
||
<p>Note that, the <code class="language-plaintext highlighter-rouge">options</code> argument is not optional when the <code class="language-plaintext highlighter-rouge">ctx</code> argument is specified and that the empty Lua string (<code class="language-plaintext highlighter-rouge">""</code>) must be used as placeholder for <code class="language-plaintext highlighter-rouge">options</code> if no meaningful regex options are required.</p>
|
||
|
||
<p>This method requires the PCRE library enabled in Nginx. (<a href="#special-escaping-sequences">Known Issue With Special Escaping Sequences</a>).</p>
|
||
|
||
<p>To confirm that PCRE JIT is enabled, activate the Nginx debug log by adding the <code class="language-plaintext highlighter-rouge">--with-debug</code> option to Nginx or ngx_openresty’s <code class="language-plaintext highlighter-rouge">./configure</code> script. Then, enable the “debug” error log level in <code class="language-plaintext highlighter-rouge">error_log</code> directive. The following message will be generated if PCRE JIT is enabled:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>pcre JIT compiling result: 1
|
||
</code></pre></div></div>
|
||
|
||
<p>Starting from the <code class="language-plaintext highlighter-rouge">0.9.4</code> release, this function also accepts a 5th argument, <code class="language-plaintext highlighter-rouge">res_table</code>, for letting the caller supply the Lua table used to hold all the capturing results. Starting from <code class="language-plaintext highlighter-rouge">0.9.6</code>, it is the caller’s responsibility to ensure this table is empty. This is very useful for recycling Lua tables and saving GC and table allocation overhead.</p>
|
||
|
||
<p>This feature was introduced in the <code class="language-plaintext highlighter-rouge">v0.2.1rc11</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxrefind">ngx.re.find</h2>
|
||
<p><strong>syntax:</strong> <em>from, to, err = ngx.re.find(subject, regex, options?, ctx?, nth?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Similar to <a href="#ngxrematch">ngx.re.match</a> but only returns the begining index (<code class="language-plaintext highlighter-rouge">from</code>) and end index (<code class="language-plaintext highlighter-rouge">to</code>) of the matched substring. The returned indexes are 1-based and can be fed directly into the <a href="http://www.lua.org/manual/5.1/manual.html#pdf-string.sub">string.sub</a> API function to obtain the matched substring.</p>
|
||
|
||
<p>In case of errors (like bad regexes or any PCRE runtime errors), this API function returns two <code class="language-plaintext highlighter-rouge">nil</code> values followed by a string describing the error.</p>
|
||
|
||
<p>If no match is found, this function just returns a <code class="language-plaintext highlighter-rouge">nil</code> value.</p>
|
||
|
||
<p>Below is an example:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">s</span> <span class="o">=</span> <span class="s2">"hello, 1234"</span>
|
||
<span class="kd">local</span> <span class="n">from</span><span class="p">,</span> <span class="n">to</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="n">find</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="s2">"([0-9]+)"</span><span class="p">,</span> <span class="s2">"jo"</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="n">from</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"from: "</span><span class="p">,</span> <span class="n">from</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"to: "</span><span class="p">,</span> <span class="n">to</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"matched: "</span><span class="p">,</span> <span class="nb">string.sub</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">from</span><span class="p">,</span> <span class="n">to</span><span class="p">))</span>
|
||
<span class="k">else</span>
|
||
<span class="k">if</span> <span class="n">err</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"error: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"not matched!"</span><span class="p">)</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This example produces the output</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>from: 8
|
||
to: 11
|
||
matched: 1234
|
||
</code></pre></div></div>
|
||
|
||
<p>Because this API function does not create new Lua strings nor new Lua tables, it is much faster than <a href="#ngxrematch">ngx.re.match</a>. It should be used wherever possible.</p>
|
||
|
||
<p>Since the <code class="language-plaintext highlighter-rouge">0.9.3</code> release, an optional 5th argument, <code class="language-plaintext highlighter-rouge">nth</code>, is supported to specify which (submatch) capture’s indexes to return. When <code class="language-plaintext highlighter-rouge">nth</code> is 0 (which is the default), the indexes for the whole matched substring is returned; when <code class="language-plaintext highlighter-rouge">nth</code> is 1, then the 1st submatch capture’s indexes are returned; when <code class="language-plaintext highlighter-rouge">nth</code> is 2, then the 2nd submatch capture is returned, and so on. When the specified submatch does not have a match, then two <code class="language-plaintext highlighter-rouge">nil</code> values will be returned. Below is an example for this:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">str</span> <span class="o">=</span> <span class="s2">"hello, 1234"</span>
|
||
<span class="kd">local</span> <span class="n">from</span><span class="p">,</span> <span class="n">to</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="n">find</span><span class="p">(</span><span class="n">str</span><span class="p">,</span> <span class="s2">"([0-9])([0-9]+)"</span><span class="p">,</span> <span class="s2">"jo"</span><span class="p">,</span> <span class="kc">nil</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="n">from</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"matched 2nd submatch: "</span><span class="p">,</span> <span class="nb">string.sub</span><span class="p">(</span><span class="n">str</span><span class="p">,</span> <span class="n">from</span><span class="p">,</span> <span class="n">to</span><span class="p">))</span> <span class="c1">-- yields "234"</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This API function was first introduced in the <code class="language-plaintext highlighter-rouge">v0.9.2</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxregmatch">ngx.re.gmatch</h2>
|
||
<p><strong>syntax:</strong> <em>iterator, err = ngx.re.gmatch(subject, regex, options?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Similar to <a href="#ngxrematch">ngx.re.match</a>, but returns a Lua iterator instead, so as to let the user programmer iterate all the matches over the <code class="language-plaintext highlighter-rouge"><subject></code> string argument with the PCRE <code class="language-plaintext highlighter-rouge">regex</code>.</p>
|
||
|
||
<p>In case of errors, like seeing an ill-formed regular expression, <code class="language-plaintext highlighter-rouge">nil</code> and a string describing the error will be returned.</p>
|
||
|
||
<p>Here is a small example to demonstrate its basic usage:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">iterator</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="n">gmatch</span><span class="p">(</span><span class="s2">"hello, world!"</span><span class="p">,</span> <span class="s2">"([a-z]+)"</span><span class="p">,</span> <span class="s2">"i"</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">iterator</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">log</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">ERR</span><span class="p">,</span> <span class="s2">"error: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="kd">local</span> <span class="n">m</span>
|
||
<span class="n">m</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">iterator</span><span class="p">()</span> <span class="c1">-- m[0] == m[1] == "hello"</span>
|
||
<span class="k">if</span> <span class="n">err</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">log</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">ERR</span><span class="p">,</span> <span class="s2">"error: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="n">m</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">iterator</span><span class="p">()</span> <span class="c1">-- m[0] == m[1] == "world"</span>
|
||
<span class="k">if</span> <span class="n">err</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">log</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">ERR</span><span class="p">,</span> <span class="s2">"error: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="n">m</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">iterator</span><span class="p">()</span> <span class="c1">-- m == nil</span>
|
||
<span class="k">if</span> <span class="n">err</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">log</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">ERR</span><span class="p">,</span> <span class="s2">"error: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>More often we just put it into a Lua loop:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">it</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="n">gmatch</span><span class="p">(</span><span class="s2">"hello, world!"</span><span class="p">,</span> <span class="s2">"([a-z]+)"</span><span class="p">,</span> <span class="s2">"i"</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">it</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">log</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">ERR</span><span class="p">,</span> <span class="s2">"error: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="k">while</span> <span class="kc">true</span> <span class="k">do</span>
|
||
<span class="kd">local</span> <span class="n">m</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">it</span><span class="p">()</span>
|
||
<span class="k">if</span> <span class="n">err</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">log</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">ERR</span><span class="p">,</span> <span class="s2">"error: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">m</span> <span class="k">then</span>
|
||
<span class="c1">-- no match found (any more)</span>
|
||
<span class="k">break</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="c1">-- found a match</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>The optional <code class="language-plaintext highlighter-rouge">options</code> argument takes exactly the same semantics as the <a href="#ngxrematch">ngx.re.match</a> method.</p>
|
||
|
||
<p>The current implementation requires that the iterator returned should only be used in a single request. That is, one should <em>not</em> assign it to a variable belonging to persistent namespace like a Lua package.</p>
|
||
|
||
<p>This method requires the PCRE library enabled in Nginx. (<a href="#special-escaping-sequences">Known Issue With Special Escaping Sequences</a>).</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.2.1rc12</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxresub">ngx.re.sub</h2>
|
||
<p><strong>syntax:</strong> <em>newstr, n, err = ngx.re.sub(subject, regex, replace, options?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Substitutes the first match of the Perl compatible regular expression <code class="language-plaintext highlighter-rouge">regex</code> on the <code class="language-plaintext highlighter-rouge">subject</code> argument string with the string or function argument <code class="language-plaintext highlighter-rouge">replace</code>. The optional <code class="language-plaintext highlighter-rouge">options</code> argument has exactly the same meaning as in <a href="#ngxrematch">ngx.re.match</a>.</p>
|
||
|
||
<p>This method returns the resulting new string as well as the number of successful substitutions. In case of failures, like syntax errors in the regular expressions or the <code class="language-plaintext highlighter-rouge"><replace></code> string argument, it will return <code class="language-plaintext highlighter-rouge">nil</code> and a string describing the error.</p>
|
||
|
||
<p>When the <code class="language-plaintext highlighter-rouge">replace</code> is a string, then it is treated as a special template for string replacement. For example,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">newstr</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="n">sub</span><span class="p">(</span><span class="s2">"hello, 1234"</span><span class="p">,</span> <span class="s2">"([0-9])[0-9]"</span><span class="p">,</span> <span class="s2">"[$0][$1]"</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="n">newstr</span> <span class="k">then</span>
|
||
<span class="c1">-- newstr == "hello, [12][1]34"</span>
|
||
<span class="c1">-- n == 1</span>
|
||
<span class="k">else</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">log</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">ERR</span><span class="p">,</span> <span class="s2">"error: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>where <code class="language-plaintext highlighter-rouge">$0</code> referring to the whole substring matched by the pattern and <code class="language-plaintext highlighter-rouge">$1</code> referring to the first parenthesized capturing substring.</p>
|
||
|
||
<p>Curly braces can also be used to disambiguate variable names from the background string literals:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">newstr</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="n">sub</span><span class="p">(</span><span class="s2">"hello, 1234"</span><span class="p">,</span> <span class="s2">"[0-9]"</span><span class="p">,</span> <span class="s2">"${0}00"</span><span class="p">)</span>
|
||
<span class="c1">-- newstr == "hello, 100234"</span>
|
||
<span class="c1">-- n == 1</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Literal dollar sign characters (<code class="language-plaintext highlighter-rouge">$</code>) in the <code class="language-plaintext highlighter-rouge">replace</code> string argument can be escaped by another dollar sign, for instance,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">newstr</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="n">sub</span><span class="p">(</span><span class="s2">"hello, 1234"</span><span class="p">,</span> <span class="s2">"[0-9]"</span><span class="p">,</span> <span class="s2">"$$"</span><span class="p">)</span>
|
||
<span class="c1">-- newstr == "hello, $234"</span>
|
||
<span class="c1">-- n == 1</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Do not use backlashes to escape dollar signs; it will not work as expected.</p>
|
||
|
||
<p>When the <code class="language-plaintext highlighter-rouge">replace</code> argument is of type “function”, then it will be invoked with the “match table” as the argument to generate the replace string literal for substitution. The “match table” fed into the <code class="language-plaintext highlighter-rouge">replace</code> function is exactly the same as the return value of <a href="#ngxrematch">ngx.re.match</a>. Here is an example:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">func</span> <span class="o">=</span> <span class="k">function</span> <span class="p">(</span><span class="n">m</span><span class="p">)</span>
|
||
<span class="k">return</span> <span class="s2">"["</span> <span class="o">..</span> <span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">..</span> <span class="s2">"]["</span> <span class="o">..</span> <span class="n">m</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">..</span> <span class="s2">"]"</span>
|
||
<span class="k">end</span>
|
||
<span class="kd">local</span> <span class="n">newstr</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="n">sub</span><span class="p">(</span><span class="s2">"hello, 1234"</span><span class="p">,</span> <span class="s2">"( [0-9] ) [0-9]"</span><span class="p">,</span> <span class="n">func</span><span class="p">,</span> <span class="s2">"x"</span><span class="p">)</span>
|
||
<span class="c1">-- newstr == "hello, [12][1]34"</span>
|
||
<span class="c1">-- n == 1</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>The dollar sign characters in the return value of the <code class="language-plaintext highlighter-rouge">replace</code> function argument are not special at all.</p>
|
||
|
||
<p>This method requires the PCRE library enabled in Nginx. (<a href="#special-escaping-sequences">Known Issue With Special Escaping Sequences</a>).</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.2.1rc13</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxregsub">ngx.re.gsub</h2>
|
||
<p><strong>syntax:</strong> <em>newstr, n, err = ngx.re.gsub(subject, regex, replace, options?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Just like <a href="#ngxresub">ngx.re.sub</a>, but does global substitution.</p>
|
||
|
||
<p>Here is some examples:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">newstr</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="nb">gsub</span><span class="p">(</span><span class="sr">"hello, world"</span><span class="p">,</span> <span class="sr">"</span><span class="se">([</span><span class="sr">a-z</span><span class="se">])[</span><span class="sr">a-z</span><span class="se">]</span><span class="sr">+"</span><span class="p">,</span> <span class="sr">"</span><span class="se">[</span><span class="sr">$0,$1</span><span class="se">]</span><span class="sr">"</span><span class="p">,</span> <span class="sr">"i"</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="n">newstr</span> <span class="k">then</span>
|
||
<span class="c1">-- newstr == "[hello,h], [world,w]"</span>
|
||
<span class="c1">-- n == 2</span>
|
||
<span class="k">else</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">log</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">ERR</span><span class="p">,</span> <span class="s2">"error: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">func</span> <span class="o">=</span> <span class="k">function</span> <span class="p">(</span><span class="n">m</span><span class="p">)</span>
|
||
<span class="k">return</span> <span class="s2">"["</span> <span class="o">..</span> <span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">..</span> <span class="s2">","</span> <span class="o">..</span> <span class="n">m</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">..</span> <span class="s2">"]"</span>
|
||
<span class="k">end</span>
|
||
<span class="kd">local</span> <span class="n">newstr</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">re</span><span class="p">.</span><span class="nb">gsub</span><span class="p">(</span><span class="sr">"hello, world"</span><span class="p">,</span> <span class="sr">"</span><span class="se">([</span><span class="sr">a-z</span><span class="se">])[</span><span class="sr">a-z</span><span class="se">]</span><span class="sr">+"</span><span class="p">,</span> <span class="err">func</span><span class="p">,</span> <span class="sr">"i"</span><span class="p">)</span>
|
||
<span class="c1">-- newstr == "[hello,h], [world,w]"</span>
|
||
<span class="c1">-- n == 2</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This method requires the PCRE library enabled in Nginx. (<a href="#special-escaping-sequences">Known Issue With Special Escaping Sequences</a>).</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.2.1rc15</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxshareddict">ngx.shared.DICT</h2>
|
||
<p><strong>syntax:</strong> <em>dict = ngx.shared.DICT</em></p>
|
||
|
||
<p><strong>syntax:</strong> <em>dict = ngx.shared[name_var]</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, init_worker_by_lua<em>, set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Fetching the shm-based Lua dictionary object for the shared memory zone named <code class="language-plaintext highlighter-rouge">DICT</code> defined by the <a href="#lua_shared_dict">lua_shared_dict</a> directive.</p>
|
||
|
||
<p>Shared memory zones are always shared by all the nginx worker processes in the current nginx server instance.</p>
|
||
|
||
<p>The resulting object <code class="language-plaintext highlighter-rouge">dict</code> has the following methods:</p>
|
||
|
||
<ul>
|
||
<li><a href="#ngxshareddictget">get</a></li>
|
||
<li><a href="#ngxshareddictget_stale">get_stale</a></li>
|
||
<li><a href="#ngxshareddictset">set</a></li>
|
||
<li><a href="#ngxshareddictsafe_set">safe_set</a></li>
|
||
<li><a href="#ngxshareddictadd">add</a></li>
|
||
<li><a href="#ngxshareddictsafe_add">safe_add</a></li>
|
||
<li><a href="#ngxshareddictreplace">replace</a></li>
|
||
<li><a href="#ngxshareddictdelete">delete</a></li>
|
||
<li><a href="#ngxshareddictincr">incr</a></li>
|
||
<li><a href="#ngxshareddictflush_all">flush_all</a></li>
|
||
<li><a href="#ngxshareddictflush_expired">flush_expired</a></li>
|
||
<li><a href="#ngxshareddictget_keys">get_keys</a></li>
|
||
</ul>
|
||
|
||
<p>Here is an example:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">http</span> <span class="p">{</span>
|
||
<span class="kn">lua_shared_dict</span> <span class="s">dogs</span> <span class="mi">10m</span><span class="p">;</span>
|
||
<span class="kn">server</span> <span class="p">{</span>
|
||
<span class="kn">location</span> <span class="n">/set</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">dogs</span> <span class="p">=</span> <span class="s">ngx.shared.dogs</span>
|
||
<span class="s">dogs:set("Jim",</span> <span class="mi">8</span><span class="s">)</span>
|
||
<span class="s">ngx.say("STORED")</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="kn">location</span> <span class="n">/get</span> <span class="p">{</span>
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">dogs</span> <span class="p">=</span> <span class="s">ngx.shared.dogs</span>
|
||
<span class="s">ngx.say(dogs:get("Jim"))</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="p">}</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Let us test it:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="nv">$ </span>curl localhost/set
|
||
STORED
|
||
|
||
<span class="nv">$ </span>curl localhost/get
|
||
8
|
||
|
||
<span class="nv">$ </span>curl localhost/get
|
||
8
|
||
</code></pre></div></div>
|
||
|
||
<p>The number <code class="language-plaintext highlighter-rouge">8</code> will be consistently output when accessing <code class="language-plaintext highlighter-rouge">/get</code> regardless of how many Nginx workers there are because the <code class="language-plaintext highlighter-rouge">dogs</code> dictionary resides in the shared memory and visible to <em>all</em> of the worker processes.</p>
|
||
|
||
<p>The shared dictionary will retain its contents through a server config reload (either by sending the <code class="language-plaintext highlighter-rouge">HUP</code> signal to the Nginx process or by using the <code class="language-plaintext highlighter-rouge">-s reload</code> command-line option).</p>
|
||
|
||
<p>The contents in the dictionary storage will be lost, however, when the Nginx server quits.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc22</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxshareddictget">ngx.shared.DICT.get</h2>
|
||
<p><strong>syntax:</strong> <em>value, flags = ngx.shared.DICT:get(key)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Retrieving the value in the dictionary <a href="#ngxshareddict">ngx.shared.DICT</a> for the key <code class="language-plaintext highlighter-rouge">key</code>. If the key does not exist or has been expired, then <code class="language-plaintext highlighter-rouge">nil</code> will be returned.</p>
|
||
|
||
<p>In case of errors, <code class="language-plaintext highlighter-rouge">nil</code> and a string describing the error will be returned.</p>
|
||
|
||
<p>The value returned will have the original data type when they were inserted into the dictionary, for example, Lua booleans, numbers, or strings.</p>
|
||
|
||
<p>The first argument to this method must be the dictionary object itself, for example,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">cats</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">shared</span><span class="p">.</span><span class="n">cats</span>
|
||
<span class="kd">local</span> <span class="n">value</span><span class="p">,</span> <span class="n">flags</span> <span class="o">=</span> <span class="n">cats</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="n">cats</span><span class="p">,</span> <span class="s2">"Marry"</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>or use Lua’s syntactic sugar for method calls:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">cats</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">shared</span><span class="p">.</span><span class="n">cats</span>
|
||
<span class="kd">local</span> <span class="n">value</span><span class="p">,</span> <span class="n">flags</span> <span class="o">=</span> <span class="n">cats</span><span class="p">:</span><span class="n">get</span><span class="p">(</span><span class="s2">"Marry"</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>These two forms are fundamentally equivalent.</p>
|
||
|
||
<p>If the user flags is <code class="language-plaintext highlighter-rouge">0</code> (the default), then no flags value will be returned.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc22</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxshareddict">ngx.shared.DICT</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxshareddictget_stale">ngx.shared.DICT.get_stale</h2>
|
||
<p><strong>syntax:</strong> <em>value, flags, stale = ngx.shared.DICT:get_stale(key)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Similar to the <a href="#ngxshareddictget">get</a> method but returns the value even if the key has already expired.</p>
|
||
|
||
<p>Returns a 3rd value, <code class="language-plaintext highlighter-rouge">stale</code>, indicating whether the key has expired or not.</p>
|
||
|
||
<p>Note that the value of an expired key is not guaranteed to be available so one should never rely on the availability of expired items.</p>
|
||
|
||
<p>This method was first introduced in the <code class="language-plaintext highlighter-rouge">0.8.6</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxshareddict">ngx.shared.DICT</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxshareddictset">ngx.shared.DICT.set</h2>
|
||
<p><strong>syntax:</strong> <em>success, err, forcible = ngx.shared.DICT:set(key, value, exptime?, flags?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Unconditionally sets a key-value pair into the shm-based dictionary <a href="#ngxshareddict">ngx.shared.DICT</a>. Returns three values:</p>
|
||
|
||
<ul>
|
||
<li><code class="language-plaintext highlighter-rouge">success</code>: boolean value to indicate whether the key-value pair is stored or not.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">err</code>: textual error message, can be <code class="language-plaintext highlighter-rouge">"no memory"</code>.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">forcible</code>: a boolean value to indicate whether other valid items have been removed forcibly when out of storage in the shared memory zone.</li>
|
||
</ul>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">value</code> argument inserted can be Lua booleans, numbers, strings, or <code class="language-plaintext highlighter-rouge">nil</code>. Their value type will also be stored into the dictionary and the same data type can be retrieved later via the <a href="#ngxshareddictget">get</a> method.</p>
|
||
|
||
<p>The optional <code class="language-plaintext highlighter-rouge">exptime</code> argument specifies expiration time (in seconds) for the inserted key-value pair. The time resolution is <code class="language-plaintext highlighter-rouge">0.001</code> seconds. If the <code class="language-plaintext highlighter-rouge">exptime</code> takes the value <code class="language-plaintext highlighter-rouge">0</code> (which is the default), then the item will never be expired.</p>
|
||
|
||
<p>The optional <code class="language-plaintext highlighter-rouge">flags</code> argument specifies a user flags value associated with the entry to be stored. It can also be retrieved later with the value. The user flags is stored as an unsigned 32-bit integer internally. Defaults to <code class="language-plaintext highlighter-rouge">0</code>. The user flags argument was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc2</code> release.</p>
|
||
|
||
<p>When it fails to allocate memory for the current key-value item, then <code class="language-plaintext highlighter-rouge">set</code> will try removing existing items in the storage according to the Least-Recently Used (LRU) algorithm. Note that, LRU takes priority over expiration time here. If up to tens of existing items have been removed and the storage left is still insufficient (either due to the total capacity limit specified by <a href="#lua_shared_dict">lua_shared_dict</a> or memory segmentation), then the <code class="language-plaintext highlighter-rouge">err</code> return value will be <code class="language-plaintext highlighter-rouge">no memory</code> and <code class="language-plaintext highlighter-rouge">success</code> will be <code class="language-plaintext highlighter-rouge">false</code>.</p>
|
||
|
||
<p>If this method succeeds in storing the current item by forcibly removing other not-yet-expired items in the dictionary via LRU, the <code class="language-plaintext highlighter-rouge">forcible</code> return value will be <code class="language-plaintext highlighter-rouge">true</code>. If it stores the item without forcibly removing other valid items, then the return value <code class="language-plaintext highlighter-rouge">forcible</code> will be <code class="language-plaintext highlighter-rouge">false</code>.</p>
|
||
|
||
<p>The first argument to this method must be the dictionary object itself, for example,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">cats</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">shared</span><span class="p">.</span><span class="n">cats</span>
|
||
<span class="kd">local</span> <span class="n">succ</span><span class="p">,</span> <span class="n">err</span><span class="p">,</span> <span class="n">forcible</span> <span class="o">=</span> <span class="n">cats</span><span class="p">.</span><span class="n">set</span><span class="p">(</span><span class="n">cats</span><span class="p">,</span> <span class="s2">"Marry"</span><span class="p">,</span> <span class="s2">"it is a nice cat!"</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>or use Lua’s syntactic sugar for method calls:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">cats</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">shared</span><span class="p">.</span><span class="n">cats</span>
|
||
<span class="kd">local</span> <span class="n">succ</span><span class="p">,</span> <span class="n">err</span><span class="p">,</span> <span class="n">forcible</span> <span class="o">=</span> <span class="n">cats</span><span class="p">:</span><span class="n">set</span><span class="p">(</span><span class="s2">"Marry"</span><span class="p">,</span> <span class="s2">"it is a nice cat!"</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>These two forms are fundamentally equivalent.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc22</code> release.</p>
|
||
|
||
<p>Please note that while internally the key-value pair is set atomically, the atomicity does not go across the method call boundary.</p>
|
||
|
||
<p>See also <a href="#ngxshareddict">ngx.shared.DICT</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxshareddictsafe_set">ngx.shared.DICT.safe_set</h2>
|
||
<p><strong>syntax:</strong> <em>ok, err = ngx.shared.DICT:safe_set(key, value, exptime?, flags?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Similar to the <a href="#ngxshareddictset">set</a> method, but never overrides the (least recently used) unexpired items in the store when running out of storage in the shared memory zone. In this case, it will immediately return <code class="language-plaintext highlighter-rouge">nil</code> and the string “no memory”.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.7.18</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxshareddict">ngx.shared.DICT</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxshareddictadd">ngx.shared.DICT.add</h2>
|
||
<p><strong>syntax:</strong> <em>success, err, forcible = ngx.shared.DICT:add(key, value, exptime?, flags?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Just like the <a href="#ngxshareddictset">set</a> method, but only stores the key-value pair into the dictionary <a href="#ngxshareddict">ngx.shared.DICT</a> if the key does <em>not</em> exist.</p>
|
||
|
||
<p>If the <code class="language-plaintext highlighter-rouge">key</code> argument already exists in the dictionary (and not expired for sure), the <code class="language-plaintext highlighter-rouge">success</code> return value will be <code class="language-plaintext highlighter-rouge">false</code> and the <code class="language-plaintext highlighter-rouge">err</code> return value will be <code class="language-plaintext highlighter-rouge">"exists"</code>.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc22</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxshareddict">ngx.shared.DICT</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxshareddictsafe_add">ngx.shared.DICT.safe_add</h2>
|
||
<p><strong>syntax:</strong> <em>ok, err = ngx.shared.DICT:safe_add(key, value, exptime?, flags?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Similar to the <a href="#ngxshareddictadd">add</a> method, but never overrides the (least recently used) unexpired items in the store when running out of storage in the shared memory zone. In this case, it will immediately return <code class="language-plaintext highlighter-rouge">nil</code> and the string “no memory”.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.7.18</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxshareddict">ngx.shared.DICT</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxshareddictreplace">ngx.shared.DICT.replace</h2>
|
||
<p><strong>syntax:</strong> <em>success, err, forcible = ngx.shared.DICT:replace(key, value, exptime?, flags?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Just like the <a href="#ngxshareddictset">set</a> method, but only stores the key-value pair into the dictionary <a href="#ngxshareddict">ngx.shared.DICT</a> if the key <em>does</em> exist.</p>
|
||
|
||
<p>If the <code class="language-plaintext highlighter-rouge">key</code> argument does <em>not</em> exist in the dictionary (or expired already), the <code class="language-plaintext highlighter-rouge">success</code> return value will be <code class="language-plaintext highlighter-rouge">false</code> and the <code class="language-plaintext highlighter-rouge">err</code> return value will be <code class="language-plaintext highlighter-rouge">"not found"</code>.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc22</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxshareddict">ngx.shared.DICT</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxshareddictdelete">ngx.shared.DICT.delete</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.shared.DICT:delete(key)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Unconditionally removes the key-value pair from the shm-based dictionary <a href="#ngxshareddict">ngx.shared.DICT</a>.</p>
|
||
|
||
<p>It is equivalent to <code class="language-plaintext highlighter-rouge">ngx.shared.DICT:set(key, nil)</code>.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc22</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxshareddict">ngx.shared.DICT</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxshareddictincr">ngx.shared.DICT.incr</h2>
|
||
<p><strong>syntax:</strong> <em>newval, err = ngx.shared.DICT:incr(key, value)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Increments the (numerical) value for <code class="language-plaintext highlighter-rouge">key</code> in the shm-based dictionary <a href="#ngxshareddict">ngx.shared.DICT</a> by the step value <code class="language-plaintext highlighter-rouge">value</code>. Returns the new resulting number if the operation is successfully completed or <code class="language-plaintext highlighter-rouge">nil</code> and an error message otherwise.</p>
|
||
|
||
<p>The key must already exist in the dictionary, otherwise it will return <code class="language-plaintext highlighter-rouge">nil</code> and <code class="language-plaintext highlighter-rouge">"not found"</code>.</p>
|
||
|
||
<p>If the original value is not a valid Lua number in the dictionary, it will return <code class="language-plaintext highlighter-rouge">nil</code> and <code class="language-plaintext highlighter-rouge">"not a number"</code>.</p>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">value</code> argument can be any valid Lua numbers, like negative numbers or floating-point numbers.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.3.1rc22</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxshareddict">ngx.shared.DICT</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxshareddictflush_all">ngx.shared.DICT.flush_all</h2>
|
||
<p><strong>syntax:</strong> <em>ngx.shared.DICT:flush_all()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Flushes out all the items in the dictionary. This method does not actuall free up all the memory blocks in the dictionary but just marks all the existing items as expired.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc17</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxshareddictflush_expired">ngx.shared.DICT.flush_expired</a> and <a href="#ngxshareddict">ngx.shared.DICT</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxshareddictflush_expired">ngx.shared.DICT.flush_expired</h2>
|
||
<p><strong>syntax:</strong> <em>flushed = ngx.shared.DICT:flush_expired(max_count?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Flushes out the expired items in the dictionary, up to the maximal number specified by the optional <code class="language-plaintext highlighter-rouge">max_count</code> argument. When the <code class="language-plaintext highlighter-rouge">max_count</code> argument is given <code class="language-plaintext highlighter-rouge">0</code> or not given at all, then it means unlimited. Returns the number of items that have actually been flushed.</p>
|
||
|
||
<p>Unlike the <a href="#ngxshareddictflush_all">flush_all</a> method, this method actually free up the memory used by the expired items.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.6.3</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxshareddictflush_all">ngx.shared.DICT.flush_all</a> and <a href="#ngxshareddict">ngx.shared.DICT</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxshareddictget_keys">ngx.shared.DICT.get_keys</h2>
|
||
<p><strong>syntax:</strong> <em>keys = ngx.shared.DICT:get_keys(max_count?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Fetch a list of the keys from the dictionary, up to <code class="language-plaintext highlighter-rouge"><max_count></code>.</p>
|
||
|
||
<p>By default, only the first 1024 keys (if any) are returned. When the <code class="language-plaintext highlighter-rouge"><max_count></code> argument is given the value <code class="language-plaintext highlighter-rouge">0</code>, then all the keys will be returned even there is more than 1024 keys in the dictionary.</p>
|
||
|
||
<p><strong>WARNING</strong> Be careful when calling this method on dictionaries with a really huge number of keys. This method may lock the dictionary for quite a while and block all the nginx worker processes that are trying to access the dictionary.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.7.3</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxsocketudp">ngx.socket.udp</h2>
|
||
<p><strong>syntax:</strong> <em>udpsock = ngx.socket.udp()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Creates and returns a UDP or datagram-oriented unix domain socket object (also known as one type of the “cosocket” objects). The following methods are supported on this object:</p>
|
||
|
||
<ul>
|
||
<li><a href="#udpsocksetpeername">setpeername</a></li>
|
||
<li><a href="#udpsocksend">send</a></li>
|
||
<li><a href="#udpsockreceive">receive</a></li>
|
||
<li><a href="#udpsockclose">close</a></li>
|
||
<li><a href="#udpsocksettimeout">settimeout</a></li>
|
||
</ul>
|
||
|
||
<p>It is intended to be compatible with the UDP API of the <a href="http://w3.impa.br/~diego/software/luasocket/udp.html">LuaSocket</a> library but is 100% nonblocking out of the box.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.7</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxsockettcp">ngx.socket.tcp</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="udpsocksetpeername">udpsock:setpeername</h2>
|
||
<p><strong>syntax:</strong> <em>ok, err = udpsock:setpeername(host, port)</em></p>
|
||
|
||
<p><strong>syntax:</strong> <em>ok, err = udpsock:setpeername(“unix:/path/to/unix-domain.socket”)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Attempts to connect a UDP socket object to a remote server or to a datagram unix domain socket file. Because the datagram protocol is actually connection-less, this method does not really establish a “connection”, but only just set the name of the remote peer for subsequent read/write operations.</p>
|
||
|
||
<p>Both IP addresses and domain names can be specified as the <code class="language-plaintext highlighter-rouge">host</code> argument. In case of domain names, this method will use Nginx core’s dynamic resolver to parse the domain name without blocking and it is required to configure the <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver">resolver</a> directive in the <code class="language-plaintext highlighter-rouge">nginx.conf</code> file like this:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">resolver</span> <span class="mf">8.8</span><span class="s">.8.8</span><span class="p">;</span> <span class="c1"># use Google's public DNS nameserver</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>If the nameserver returns multiple IP addresses for the host name, this method will pick up one randomly.</p>
|
||
|
||
<p>In case of error, the method returns <code class="language-plaintext highlighter-rouge">nil</code> followed by a string describing the error. In case of success, the method returns <code class="language-plaintext highlighter-rouge">1</code>.</p>
|
||
|
||
<p>Here is an example for connecting to a UDP (memcached) server:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/test</span> <span class="p">{</span>
|
||
<span class="kn">resolver</span> <span class="mf">8.8</span><span class="s">.8.8</span><span class="p">;</span>
|
||
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">sock</span> <span class="p">=</span> <span class="s">ngx.socket.udp()</span>
|
||
<span class="s">local</span> <span class="s">ok,</span> <span class="s">err</span> <span class="p">=</span> <span class="s">sock:setpeername("my.memcached.server.domain",</span> <span class="mi">11211</span><span class="s">)</span>
|
||
<span class="s">if</span> <span class="s">not</span> <span class="s">ok</span> <span class="s">then</span>
|
||
<span class="s">ngx.say("failed</span> <span class="s">to</span> <span class="s">connect</span> <span class="s">to</span> <span class="s">memcached:</span> <span class="s">",</span> <span class="s">err)</span>
|
||
<span class="s">return</span>
|
||
<span class="s">end</span>
|
||
<span class="s">ngx.say("successfully</span> <span class="s">connected</span> <span class="s">to</span> <span class="s">memcached!")</span>
|
||
<span class="s">sock:close()</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Since the <code class="language-plaintext highlighter-rouge">v0.7.18</code> release, connecting to a datagram unix domain socket file is also possible on Linux:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">sock</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">socket</span><span class="p">.</span><span class="n">udp</span><span class="p">()</span>
|
||
<span class="kd">local</span> <span class="n">ok</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">sock</span><span class="p">:</span><span class="n">setpeername</span><span class="p">(</span><span class="s2">"unix:/tmp/some-datagram-service.sock"</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">ok</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"failed to connect to the datagram unix domain socket: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>assuming the datagram service is listening on the unix domain socket file <code class="language-plaintext highlighter-rouge">/tmp/some-datagram-service.sock</code> and the client socket will use the “autobind” feature on Linux.</p>
|
||
|
||
<p>Calling this method on an already connected socket object will cause the original connection to be closed first.</p>
|
||
|
||
<p>This method was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.7</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="udpsocksend">udpsock:send</h2>
|
||
<p><strong>syntax:</strong> <em>ok, err = udpsock:send(data)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Sends data on the current UDP or datagram unix domain socket object.</p>
|
||
|
||
<p>In case of success, it returns <code class="language-plaintext highlighter-rouge">1</code>. Otherwise, it returns <code class="language-plaintext highlighter-rouge">nil</code> and a string describing the error.</p>
|
||
|
||
<p>The input argument <code class="language-plaintext highlighter-rouge">data</code> can either be a Lua string or a (nested) Lua table holding string fragments. In case of table arguments, this method will copy all the string elements piece by piece to the underlying Nginx socket send buffers, which is usually optimal than doing string concatenation operations on the Lua land.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.7</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="udpsockreceive">udpsock:receive</h2>
|
||
<p><strong>syntax:</strong> <em>data, err = udpsock:receive(size?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Receives data from the UDP or datagram unix domain socket object with an optional receive buffer size argument, <code class="language-plaintext highlighter-rouge">size</code>.</p>
|
||
|
||
<p>This method is a synchronous operation and is 100% nonblocking.</p>
|
||
|
||
<p>In case of success, it returns the data received; in case of error, it returns <code class="language-plaintext highlighter-rouge">nil</code> with a string describing the error.</p>
|
||
|
||
<p>If the <code class="language-plaintext highlighter-rouge">size</code> argument is specified, then this method will use this size as the receive buffer size. But when this size is greater than <code class="language-plaintext highlighter-rouge">8192</code>, then <code class="language-plaintext highlighter-rouge">8192</code> will be used instead.</p>
|
||
|
||
<p>If no argument is specified, then the maximal buffer size, <code class="language-plaintext highlighter-rouge">8192</code> is assumed.</p>
|
||
|
||
<p>Timeout for the reading operation is controlled by the <a href="#lua_socket_read_timeout">lua_socket_read_timeout</a> config directive and the <a href="#udpsocksettimeout">settimeout</a> method. And the latter takes priority. For example:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">sock</span><span class="p">:</span><span class="n">settimeout</span><span class="p">(</span><span class="mi">1000</span><span class="p">)</span> <span class="c1">-- one second timeout</span>
|
||
<span class="kd">local</span> <span class="n">data</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">sock</span><span class="p">:</span><span class="n">receive</span><span class="p">()</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">data</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"failed to read a packet: "</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"successfully read a packet: "</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>It is important here to call the <a href="#udpsocksettimeout">settimeout</a> method <em>before</em> calling this method.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.7</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="udpsockclose">udpsock:close</h2>
|
||
<p><strong>syntax:</strong> <em>ok, err = udpsock:close()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Closes the current UDP or datagram unix domain socket. It returns the <code class="language-plaintext highlighter-rouge">1</code> in case of success and returns <code class="language-plaintext highlighter-rouge">nil</code> with a string describing the error otherwise.</p>
|
||
|
||
<p>Socket objects that have not invoked this method (and associated connections) will be closed when the socket object is released by the Lua GC (Garbage Collector) or the current client HTTP request finishes processing.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.7</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="udpsocksettimeout">udpsock:settimeout</h2>
|
||
<p><strong>syntax:</strong> <em>udpsock:settimeout(time)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Set the timeout value in milliseconds for subsequent socket operations (like <a href="#udpsockreceive">receive</a>).</p>
|
||
|
||
<p>Settings done by this method takes priority over those config directives, like <a href="#lua_socket_read_timeout">lua_socket_read_timeout</a>.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.7</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxsockettcp">ngx.socket.tcp</h2>
|
||
<p><strong>syntax:</strong> <em>tcpsock = ngx.socket.tcp()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Creates and returns a TCP or stream-oriented unix domain socket object (also known as one type of the “cosocket” objects). The following methods are supported on this object:</p>
|
||
|
||
<ul>
|
||
<li><a href="#tcpsockconnect">connect</a></li>
|
||
<li><a href="#tcpsocksslhandshake">sslhandshake</a></li>
|
||
<li><a href="#tcpsocksend">send</a></li>
|
||
<li><a href="#tcpsockreceive">receive</a></li>
|
||
<li><a href="#tcpsockclose">close</a></li>
|
||
<li><a href="#tcpsocksettimeout">settimeout</a></li>
|
||
<li><a href="#tcpsocksetoption">setoption</a></li>
|
||
<li><a href="#tcpsockreceiveuntil">receiveuntil</a></li>
|
||
<li><a href="#tcpsocksetkeepalive">setkeepalive</a></li>
|
||
<li><a href="#tcpsockgetreusedtimes">getreusedtimes</a></li>
|
||
</ul>
|
||
|
||
<p>It is intended to be compatible with the TCP API of the <a href="http://w3.impa.br/~diego/software/luasocket/tcp.html">LuaSocket</a> library but is 100% nonblocking out of the box. Also, we introduce some new APIs to provide more functionalities.</p>
|
||
|
||
<p>The cosocket object created by this API function has exactly the same lifetime as the Lua handler creating it. So never pass the cosocket object to any other Lua handler (including ngx.timer callback functions) and never share the cosocket object between different NGINX requests.</p>
|
||
|
||
<p>For every cosocket object’s underlying connection, if you do not
|
||
explicitly close it (via <a href="#tcpsockclose">close</a>) or put it back to the connection
|
||
pool (via <a href="#tcpsocksetkeepalive">setkeepalive</a>), then it is automatically closed when one of
|
||
the following two events happens:</p>
|
||
|
||
<ul>
|
||
<li>the current request handler completes, or</li>
|
||
<li>the Lua cosocket object value gets collected by the Lua GC.</li>
|
||
</ul>
|
||
|
||
<p>Fatal errors in cosocket operations always automatically close the current
|
||
connection (note that, read timeout error is the only error that is
|
||
not fatal), and if you call <a href="#tcpsockclose">close</a> on a closed connection, you will get
|
||
the “closed” error.</p>
|
||
|
||
<p>Starting from the <code class="language-plaintext highlighter-rouge">0.9.9</code> release, the cosocket object here is full-duplex, that is, a reader “light thread” and a writer “light thread” can operate on a single cosocket object simultaneously (both “light threads” must belong to the same Lua handler though, see reasons above). But you cannot have two “light threads” both reading (or writing or connecting) the same cosocket, otherwise you might get an error like “socket busy reading” when calling the methods of the cosocket object.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p>See also <a href="#ngxsocketudp">ngx.socket.udp</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="tcpsockconnect">tcpsock:connect</h2>
|
||
<p><strong>syntax:</strong> <em>ok, err = tcpsock:connect(host, port, options_table?)</em></p>
|
||
|
||
<p><strong>syntax:</strong> <em>ok, err = tcpsock:connect(“unix:/path/to/unix-domain.socket”, options_table?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Attempts to connect a TCP socket object to a remote server or to a stream unix domain socket file without blocking.</p>
|
||
|
||
<p>Before actually resolving the host name and connecting to the remote backend, this method will always look up the connection pool for matched idle connections created by previous calls of this method (or the <a href="#ngxsocketconnect">ngx.socket.connect</a> function).</p>
|
||
|
||
<p>Both IP addresses and domain names can be specified as the <code class="language-plaintext highlighter-rouge">host</code> argument. In case of domain names, this method will use Nginx core’s dynamic resolver to parse the domain name without blocking and it is required to configure the <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver">resolver</a> directive in the <code class="language-plaintext highlighter-rouge">nginx.conf</code> file like this:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">resolver</span> <span class="mf">8.8</span><span class="s">.8.8</span><span class="p">;</span> <span class="c1"># use Google's public DNS nameserver</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>If the nameserver returns multiple IP addresses for the host name, this method will pick up one randomly.</p>
|
||
|
||
<p>In case of error, the method returns <code class="language-plaintext highlighter-rouge">nil</code> followed by a string describing the error. In case of success, the method returns <code class="language-plaintext highlighter-rouge">1</code>.</p>
|
||
|
||
<p>Here is an example for connecting to a TCP server:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/test</span> <span class="p">{</span>
|
||
<span class="kn">resolver</span> <span class="mf">8.8</span><span class="s">.8.8</span><span class="p">;</span>
|
||
|
||
<span class="kn">content_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">sock</span> <span class="p">=</span> <span class="s">ngx.socket.tcp()</span>
|
||
<span class="s">local</span> <span class="s">ok,</span> <span class="s">err</span> <span class="p">=</span> <span class="s">sock:connect("www.google.com",</span> <span class="mi">80</span><span class="s">)</span>
|
||
<span class="s">if</span> <span class="s">not</span> <span class="s">ok</span> <span class="s">then</span>
|
||
<span class="s">ngx.say("failed</span> <span class="s">to</span> <span class="s">connect</span> <span class="s">to</span> <span class="s">google:</span> <span class="s">",</span> <span class="s">err)</span>
|
||
<span class="s">return</span>
|
||
<span class="s">end</span>
|
||
<span class="s">ngx.say("successfully</span> <span class="s">connected</span> <span class="s">to</span> <span class="s">google!")</span>
|
||
<span class="s">sock:close()</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Connecting to a Unix Domain Socket file is also possible:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">sock</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">socket</span><span class="p">.</span><span class="n">tcp</span><span class="p">()</span>
|
||
<span class="kd">local</span> <span class="n">ok</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">sock</span><span class="p">:</span><span class="n">connect</span><span class="p">(</span><span class="s2">"unix:/tmp/memcached.sock"</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">ok</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"failed to connect to the memcached unix domain socket: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>assuming memcached (or something else) is listening on the unix domain socket file <code class="language-plaintext highlighter-rouge">/tmp/memcached.sock</code>.</p>
|
||
|
||
<p>Timeout for the connecting operation is controlled by the <a href="#lua_socket_connect_timeout">lua_socket_connect_timeout</a> config directive and the <a href="#tcpsocksettimeout">settimeout</a> method. And the latter takes priority. For example:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">sock</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">socket</span><span class="p">.</span><span class="n">tcp</span><span class="p">()</span>
|
||
<span class="n">sock</span><span class="p">:</span><span class="n">settimeout</span><span class="p">(</span><span class="mi">1000</span><span class="p">)</span> <span class="c1">-- one second timeout</span>
|
||
<span class="kd">local</span> <span class="n">ok</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">sock</span><span class="p">:</span><span class="n">connect</span><span class="p">(</span><span class="n">host</span><span class="p">,</span> <span class="n">port</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>It is important here to call the <a href="#tcpsocksettimeout">settimeout</a> method <em>before</em> calling this method.</p>
|
||
|
||
<p>Calling this method on an already connected socket object will cause the original connection to be closed first.</p>
|
||
|
||
<p>An optional Lua table can be specified as the last argument to this method to specify various connect options:</p>
|
||
|
||
<ul>
|
||
<li><code class="language-plaintext highlighter-rouge">pool</code>
|
||
specify a custom name for the connection pool being used. If omitted, then the connection pool name will be generated from the string template <code class="language-plaintext highlighter-rouge">"<host>:<port>"</code> or <code class="language-plaintext highlighter-rouge">"<unix-socket-path>"</code>.</li>
|
||
</ul>
|
||
|
||
<p>The support for the options table argument was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.7</code> release.</p>
|
||
|
||
<p>This method was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="tcpsocksslhandshake">tcpsock:sslhandshake</h2>
|
||
<p><strong>syntax:</strong> <em>session, err = tcpsock:sslhandshake(reused_session?, server_name?, ssl_verify?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Does SSL/TLS handshake on the currently established connection.</p>
|
||
|
||
<p>The optional <code class="language-plaintext highlighter-rouge">reused_session</code> argument can take a former SSL
|
||
session userdata returned by a previous <code class="language-plaintext highlighter-rouge">sslhandshake</code>
|
||
call for exactly the same target. For short-lived connections, reusing SSL
|
||
sessions can usually speed up the handshake by one order by magnitude but it
|
||
is not so useful if the connection pool is enabled. This argument defaults to
|
||
<code class="language-plaintext highlighter-rouge">nil</code>. If this argument takes the boolean <code class="language-plaintext highlighter-rouge">false</code> value, no SSL session
|
||
userdata would return by this call and only a Lua boolean will be returned as
|
||
the first return value; otherwise the current SSL session will
|
||
always be returned as the first argument in case of successes.</p>
|
||
|
||
<p>The optional <code class="language-plaintext highlighter-rouge">server_name</code> argument is used to specify the server
|
||
name for the new TLS extension Server Name Indication (SNI). Use of SNI can
|
||
make different servers share the same IP address on the server side. Also,
|
||
when SSL verification is enabled, this <code class="language-plaintext highlighter-rouge">server_name</code> argument is
|
||
also used to validate the server name specified in the server certificate sent from
|
||
the remote.</p>
|
||
|
||
<p>The optional <code class="language-plaintext highlighter-rouge">ssl_verify</code> argument takes a Lua boolean value to
|
||
control whether to perform SSL verification. When set to <code class="language-plaintext highlighter-rouge">true</code>, the server
|
||
certificate will be verified according to the CA certificates specified by
|
||
the <a href="#lua_ssl_trusted_certificate">lua_ssl_trusted_certificate</a> directive.
|
||
You may also need to adjust the <a href="#lua_ssl_verify_depth">lua_ssl_verify_depth</a>
|
||
directive to control how deep we should follow along the certificate chain.
|
||
Also, when the <code class="language-plaintext highlighter-rouge">ssl_verify</code> argument is true and the
|
||
<code class="language-plaintext highlighter-rouge">server_name</code> argument is also specified, the latter will be used
|
||
to validate the server name in the server certificate.</p>
|
||
|
||
<p>For connections that have already done SSL/TLS handshake, this method returns
|
||
immediately.</p>
|
||
|
||
<p>This method was first introduced in the <code class="language-plaintext highlighter-rouge">v0.9.11</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="tcpsocksend">tcpsock:send</h2>
|
||
<p><strong>syntax:</strong> <em>bytes, err = tcpsock:send(data)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Sends data without blocking on the current TCP or Unix Domain Socket connection.</p>
|
||
|
||
<p>This method is a synchronous operation that will not return until <em>all</em> the data has been flushed into the system socket send buffer or an error occurs.</p>
|
||
|
||
<p>In case of success, it returns the total number of bytes that have been sent. Otherwise, it returns <code class="language-plaintext highlighter-rouge">nil</code> and a string describing the error.</p>
|
||
|
||
<p>The input argument <code class="language-plaintext highlighter-rouge">data</code> can either be a Lua string or a (nested) Lua table holding string fragments. In case of table arguments, this method will copy all the string elements piece by piece to the underlying Nginx socket send buffers, which is usually optimal than doing string concatenation operations on the Lua land.</p>
|
||
|
||
<p>Timeout for the sending operation is controlled by the <a href="#lua_socket_send_timeout">lua_socket_send_timeout</a> config directive and the <a href="#tcpsocksettimeout">settimeout</a> method. And the latter takes priority. For example:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">sock</span><span class="p">:</span><span class="n">settimeout</span><span class="p">(</span><span class="mi">1000</span><span class="p">)</span> <span class="c1">-- one second timeout</span>
|
||
<span class="kd">local</span> <span class="n">bytes</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">sock</span><span class="p">:</span><span class="n">send</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>It is important here to call the <a href="#tcpsocksettimeout">settimeout</a> method <em>before</em> calling this method.</p>
|
||
|
||
<p>In case of any connection errors, this method always automatically closes the current connection.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="tcpsockreceive">tcpsock:receive</h2>
|
||
<p><strong>syntax:</strong> <em>data, err, partial = tcpsock:receive(size)</em></p>
|
||
|
||
<p><strong>syntax:</strong> <em>data, err, partial = tcpsock:receive(pattern?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Receives data from the connected socket according to the reading pattern or size.</p>
|
||
|
||
<p>This method is a synchronous operation just like the <a href="#tcpsocksend">send</a> method and is 100% nonblocking.</p>
|
||
|
||
<p>In case of success, it returns the data received; in case of error, it returns <code class="language-plaintext highlighter-rouge">nil</code> with a string describing the error and the partial data received so far.</p>
|
||
|
||
<p>If a number-like argument is specified (including strings that look like numbers), then it is interpreted as a size. This method will not return until it reads exactly this size of data or an error occurs.</p>
|
||
|
||
<p>If a non-number-like string argument is specified, then it is interpreted as a “pattern”. The following patterns are supported:</p>
|
||
|
||
<ul>
|
||
<li><code class="language-plaintext highlighter-rouge">'*a'</code>: reads from the socket until the connection is closed. No end-of-line translation is performed;</li>
|
||
<li><code class="language-plaintext highlighter-rouge">'*l'</code>: reads a line of text from the socket. The line is terminated by a <code class="language-plaintext highlighter-rouge">Line Feed</code> (LF) character (ASCII 10), optionally preceded by a <code class="language-plaintext highlighter-rouge">Carriage Return</code> (CR) character (ASCII 13). The CR and LF characters are not included in the returned line. In fact, all CR characters are ignored by the pattern.</li>
|
||
</ul>
|
||
|
||
<p>If no argument is specified, then it is assumed to be the pattern <code class="language-plaintext highlighter-rouge">'*l'</code>, that is, the line reading pattern.</p>
|
||
|
||
<p>Timeout for the reading operation is controlled by the <a href="#lua_socket_read_timeout">lua_socket_read_timeout</a> config directive and the <a href="#tcpsocksettimeout">settimeout</a> method. And the latter takes priority. For example:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="n">sock</span><span class="p">:</span><span class="n">settimeout</span><span class="p">(</span><span class="mi">1000</span><span class="p">)</span> <span class="c1">-- one second timeout</span>
|
||
<span class="kd">local</span> <span class="n">line</span><span class="p">,</span> <span class="n">err</span><span class="p">,</span> <span class="n">partial</span> <span class="o">=</span> <span class="n">sock</span><span class="p">:</span><span class="n">receive</span><span class="p">()</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">line</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"failed to read a line: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"successfully read a line: "</span><span class="p">,</span> <span class="n">line</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>It is important here to call the <a href="#tcpsocksettimeout">settimeout</a> method <em>before</em> calling this method.</p>
|
||
|
||
<p>Since the <code class="language-plaintext highlighter-rouge">v0.8.8</code> release, this method no longer automatically closes the current connection when the read timeout error happens. For other connection errors, this method always automatically closes the connection.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="tcpsockreceiveuntil">tcpsock:receiveuntil</h2>
|
||
<p><strong>syntax:</strong> <em>iterator = tcpsock:receiveuntil(pattern, options?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>This method returns an iterator Lua function that can be called to read the data stream until it sees the specified pattern or an error occurs.</p>
|
||
|
||
<p>Here is an example for using this method to read a data stream with the boundary sequence <code class="language-plaintext highlighter-rouge">--abcedhb</code>:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">reader</span> <span class="o">=</span> <span class="n">sock</span><span class="p">:</span><span class="n">receiveuntil</span><span class="p">(</span><span class="s2">"</span><span class="se">\r\n</span><span class="s2">--abcedhb"</span><span class="p">)</span>
|
||
<span class="kd">local</span> <span class="n">data</span><span class="p">,</span> <span class="n">err</span><span class="p">,</span> <span class="n">partial</span> <span class="o">=</span> <span class="n">reader</span><span class="p">()</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">data</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"failed to read the data stream: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">end</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"read the data stream: "</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>When called without any argument, the iterator function returns the received data right <em>before</em> the specified pattern string in the incoming data stream. So for the example above, if the incoming data stream is <code class="language-plaintext highlighter-rouge">'hello, world! -agentzh\r\n--abcedhb blah blah'</code>, then the string <code class="language-plaintext highlighter-rouge">'hello, world! -agentzh'</code> will be returned.</p>
|
||
|
||
<p>In case of error, the iterator function will return <code class="language-plaintext highlighter-rouge">nil</code> along with a string describing the error and the partial data bytes that have been read so far.</p>
|
||
|
||
<p>The iterator function can be called multiple times and can be mixed safely with other cosocket method calls or other iterator function calls.</p>
|
||
|
||
<p>The iterator function behaves differently (i.e., like a real iterator) when it is called with a <code class="language-plaintext highlighter-rouge">size</code> argument. That is, it will read that <code class="language-plaintext highlighter-rouge">size</code> of data on each invocation and will return <code class="language-plaintext highlighter-rouge">nil</code> at the last invocation (either sees the boundary pattern or meets an error). For the last successful invocation of the iterator function, the <code class="language-plaintext highlighter-rouge">err</code> return value will be <code class="language-plaintext highlighter-rouge">nil</code> too. The iterator function will be reset after the last successful invocation that returns <code class="language-plaintext highlighter-rouge">nil</code> data and <code class="language-plaintext highlighter-rouge">nil</code> error. Consider the following example:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">reader</span> <span class="o">=</span> <span class="n">sock</span><span class="p">:</span><span class="n">receiveuntil</span><span class="p">(</span><span class="s2">"</span><span class="se">\r\n</span><span class="s2">--abcedhb"</span><span class="p">)</span>
|
||
|
||
<span class="k">while</span> <span class="kc">true</span> <span class="k">do</span>
|
||
<span class="kd">local</span> <span class="n">data</span><span class="p">,</span> <span class="n">err</span><span class="p">,</span> <span class="n">partial</span> <span class="o">=</span> <span class="n">reader</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">data</span> <span class="k">then</span>
|
||
<span class="k">if</span> <span class="n">err</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"failed to read the data stream: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">break</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"read done"</span><span class="p">)</span>
|
||
<span class="k">break</span>
|
||
<span class="k">end</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"read chunk: ["</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="s2">"]"</span><span class="p">)</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Then for the incoming data stream <code class="language-plaintext highlighter-rouge">'hello, world! -agentzh\r\n--abcedhb blah blah'</code>, we shall get the following output from the sample code above:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>read chunk: [hell]
|
||
read chunk: [o, w]
|
||
read chunk: [orld]
|
||
read chunk: [! -a]
|
||
read chunk: [gent]
|
||
read chunk: [zh]
|
||
read done
|
||
</code></pre></div></div>
|
||
|
||
<p>Note that, the actual data returned <em>might</em> be a little longer than the size limit specified by the <code class="language-plaintext highlighter-rouge">size</code> argument when the boundary pattern has ambiguity for streaming parsing. Near the boundary of the data stream, the data string actually returned could also be shorter than the size limit.</p>
|
||
|
||
<p>Timeout for the iterator function’s reading operation is controlled by the <a href="#lua_socket_read_timeout">lua_socket_read_timeout</a> config directive and the <a href="#tcpsocksettimeout">settimeout</a> method. And the latter takes priority. For example:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">readline</span> <span class="o">=</span> <span class="n">sock</span><span class="p">:</span><span class="n">receiveuntil</span><span class="p">(</span><span class="s2">"</span><span class="se">\r\n</span><span class="s2">"</span><span class="p">)</span>
|
||
|
||
<span class="n">sock</span><span class="p">:</span><span class="n">settimeout</span><span class="p">(</span><span class="mi">1000</span><span class="p">)</span> <span class="c1">-- one second timeout</span>
|
||
<span class="n">line</span><span class="p">,</span> <span class="n">err</span><span class="p">,</span> <span class="n">partial</span> <span class="o">=</span> <span class="n">readline</span><span class="p">()</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">line</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"failed to read a line: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"successfully read a line: "</span><span class="p">,</span> <span class="n">line</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>It is important here to call the <a href="#tcpsocksettimeout">settimeout</a> method <em>before</em> calling the iterator function (note that the <code class="language-plaintext highlighter-rouge">receiveuntil</code> call is irrelevant here).</p>
|
||
|
||
<p>As from the <code class="language-plaintext highlighter-rouge">v0.5.1</code> release, this method also takes an optional <code class="language-plaintext highlighter-rouge">options</code> table argument to control the behavior. The following options are supported:</p>
|
||
|
||
<ul>
|
||
<li><code class="language-plaintext highlighter-rouge">inclusive</code></li>
|
||
</ul>
|
||
|
||
<p>The <code class="language-plaintext highlighter-rouge">inclusive</code> takes a boolean value to control whether to include the pattern string in the returned data string. Default to <code class="language-plaintext highlighter-rouge">false</code>. For example,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">reader</span> <span class="o">=</span> <span class="n">tcpsock</span><span class="p">:</span><span class="n">receiveuntil</span><span class="p">(</span><span class="s2">"_END_"</span><span class="p">,</span> <span class="p">{</span> <span class="n">inclusive</span> <span class="o">=</span> <span class="kc">true</span> <span class="p">})</span>
|
||
<span class="kd">local</span> <span class="n">data</span> <span class="o">=</span> <span class="n">reader</span><span class="p">()</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Then for the input data stream <code class="language-plaintext highlighter-rouge">"hello world _END_ blah blah blah"</code>, then the example above will output <code class="language-plaintext highlighter-rouge">hello world _END_</code>, including the pattern string <code class="language-plaintext highlighter-rouge">_END_</code> itself.</p>
|
||
|
||
<p>Since the <code class="language-plaintext highlighter-rouge">v0.8.8</code> release, this method no longer automatically closes the current connection when the read timeout error happens. For other connection errors, this method always automatically closes the connection.</p>
|
||
|
||
<p>This method was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="tcpsockclose">tcpsock:close</h2>
|
||
<p><strong>syntax:</strong> <em>ok, err = tcpsock:close()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Closes the current TCP or stream unix domain socket. It returns the <code class="language-plaintext highlighter-rouge">1</code> in case of success and returns <code class="language-plaintext highlighter-rouge">nil</code> with a string describing the error otherwise.</p>
|
||
|
||
<p>Note that there is no need to call this method on socket objects that have invoked the <a href="#tcpsocksetkeepalive">setkeepalive</a> method because the socket object is already closed (and the current connection is saved into the built-in connection pool).</p>
|
||
|
||
<p>Socket objects that have not invoked this method (and associated connections) will be closed when the socket object is released by the Lua GC (Garbage Collector) or the current client HTTP request finishes processing.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="tcpsocksettimeout">tcpsock:settimeout</h2>
|
||
<p><strong>syntax:</strong> <em>tcpsock:settimeout(time)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Set the timeout value in milliseconds for subsequent socket operations (<a href="#tcpsockconnect">connect</a>, <a href="#tcpsockreceive">receive</a>, and iterators returned from <a href="#tcpsockreceiveuntil">receiveuntil</a>).</p>
|
||
|
||
<p>Settings done by this method takes priority over those config directives, i.e., <a href="#lua_socket_connect_timeout">lua_socket_connect_timeout</a>, <a href="#lua_socket_send_timeout">lua_socket_send_timeout</a>, and <a href="#lua_socket_read_timeout">lua_socket_read_timeout</a>.</p>
|
||
|
||
<p>Note that this method does <em>not</em> affect the <a href="#lua_socket_keepalive_timeout">lua_socket_keepalive_timeout</a> setting; the <code class="language-plaintext highlighter-rouge">timeout</code> argument to the <a href="#tcpsocksetkeepalive">setkeepalive</a> method should be used for this purpose instead.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="tcpsocksetoption">tcpsock:setoption</h2>
|
||
<p><strong>syntax:</strong> <em>tcpsock:setoption(option, value?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>This function is added for <a href="http://w3.impa.br/~diego/software/luasocket/tcp.html">LuaSocket</a> API compatibility and does nothing for now. Its functionality will be implemented in future.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="tcpsocksetkeepalive">tcpsock:setkeepalive</h2>
|
||
<p><strong>syntax:</strong> <em>ok, err = tcpsock:setkeepalive(timeout?, size?)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Puts the current socket’s connection immediately into the cosocket built-in connection pool and keep it alive until other <a href="#tcpsockconnect">connect</a> method calls request it or the associated maximal idle timeout is expired.</p>
|
||
|
||
<p>The first optional argument, <code class="language-plaintext highlighter-rouge">timeout</code>, can be used to specify the maximal idle timeout (in milliseconds) for the current connection. If omitted, the default setting in the <a href="#lua_socket_keepalive_timeout">lua_socket_keepalive_timeout</a> config directive will be used. If the <code class="language-plaintext highlighter-rouge">0</code> value is given, then the timeout interval is unlimited.</p>
|
||
|
||
<p>The second optional argument, <code class="language-plaintext highlighter-rouge">size</code>, can be used to specify the maximal number of connections allowed in the connection pool for the current server (i.e., the current host-port pair or the unix domain socket file path). Note that the size of the connection pool cannot be changed once the pool is created. When this argument is omitted, the default setting in the <a href="#lua_socket_pool_size">lua_socket_pool_size</a> config directive will be used.</p>
|
||
|
||
<p>When the connection pool exceeds the available size limit, the least recently used (idle) connection already in the pool will be closed to make room for the current connection.</p>
|
||
|
||
<p>Note that the cosocket connection pool is per Nginx worker process rather than per Nginx server instance, so the size limit specified here also applies to every single Nginx worker process.</p>
|
||
|
||
<p>Idle connections in the pool will be monitored for any exceptional events like connection abortion or unexpected incoming data on the line, in which cases the connection in question will be closed and removed from the pool.</p>
|
||
|
||
<p>In case of success, this method returns <code class="language-plaintext highlighter-rouge">1</code>; otherwise, it returns <code class="language-plaintext highlighter-rouge">nil</code> and a string describing the error.</p>
|
||
|
||
<p>When the system receive buffer for the current connection has unread data, then this method will return the “connection in dubious state” error message (as the second return value) because the previous session has unread data left behind for the next session and the connection is not safe to be reused.</p>
|
||
|
||
<p>This method also makes the current cosocket object enter the “closed” state, so there is no need to manually call the <a href="#tcpsockclose">close</a> method on it afterwards.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="tcpsockgetreusedtimes">tcpsock:getreusedtimes</h2>
|
||
<p><strong>syntax:</strong> <em>count, err = tcpsock:getreusedtimes()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>This method returns the (successfully) reused times for the current connection. In case of error, it returns <code class="language-plaintext highlighter-rouge">nil</code> and a string describing the error.</p>
|
||
|
||
<p>If the current connection does not come from the built-in connection pool, then this method always returns <code class="language-plaintext highlighter-rouge">0</code>, that is, the connection has never been reused (yet). If the connection comes from the connection pool, then the return value is always non-zero. So this method can also be used to determine if the current connection comes from the pool.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxsocketconnect">ngx.socket.connect</h2>
|
||
<p><strong>syntax:</strong> <em>tcpsock, err = ngx.socket.connect(host, port)</em></p>
|
||
|
||
<p><strong>syntax:</strong> <em>tcpsock, err = ngx.socket.connect(“unix:/path/to/unix-domain.socket”)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>This function is a shortcut for combining <a href="#ngxsockettcp">ngx.socket.tcp()</a> and the <a href="#tcpsockconnect">connect()</a> method call in a single operation. It is actually implemented like this:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">sock</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">socket</span><span class="p">.</span><span class="n">tcp</span><span class="p">()</span>
|
||
<span class="kd">local</span> <span class="n">ok</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">sock</span><span class="p">:</span><span class="n">connect</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">ok</span> <span class="k">then</span>
|
||
<span class="k">return</span> <span class="kc">nil</span><span class="p">,</span> <span class="n">err</span>
|
||
<span class="k">end</span>
|
||
<span class="k">return</span> <span class="n">sock</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>There is no way to use the <a href="#tcpsocksettimeout">settimeout</a> method to specify connecting timeout for this method and the <a href="#lua_socket_connect_timeout">lua_socket_connect_timeout</a> directive must be set at configure time instead.</p>
|
||
|
||
<p>This feature was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.0rc1</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxget_phase">ngx.get_phase</h2>
|
||
<p><strong>syntax:</strong> <em>str = ngx.get_phase()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_by_lua</em>, init_worker_by_lua<em>, set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Retrieves the current running phase name. Possible return values are</p>
|
||
|
||
<ul>
|
||
<li><code class="language-plaintext highlighter-rouge">init</code>
|
||
for the context of <a href="#init_by_lua">init_by_lua</a> or <a href="#init_by_lua_file">init_by_lua_file</a>.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">init_worker</code>
|
||
for the context of <a href="#init_worker_by_lua">init_worker_by_lua</a> or <a href="#init_worker_by_lua_file">init_worker_by_lua_file</a>.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">set</code>
|
||
for the context of <a href="#set_by_lua">set_by_lua</a> or <a href="#set_by_lua_file">set_by_lua_file</a>.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">rewrite</code>
|
||
for the context of <a href="#rewrite_by_lua">rewrite_by_lua</a> or <a href="#rewrite_by_lua_file">rewrite_by_lua_file</a>.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">access</code>
|
||
for the context of <a href="#access_by_lua">access_by_lua</a> or <a href="#access_by_lua_file">access_by_lua_file</a>.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">content</code>
|
||
for the context of <a href="#content_by_lua">content_by_lua</a> or <a href="#content_by_lua_file">content_by_lua_file</a>.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">header_filter</code>
|
||
for the context of <a href="#header_filter_by_lua">header_filter_by_lua</a> or <a href="#header_filter_by_lua_file">header_filter_by_lua_file</a>.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">body_filter</code>
|
||
for the context of <a href="#body_filter_by_lua">body_filter_by_lua</a> or <a href="#body_filter_by_lua_file">body_filter_by_lua_file</a>.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">log</code>
|
||
for the context of <a href="#log_by_lua">log_by_lua</a> or <a href="#log_by_lua_file">log_by_lua_file</a>.</li>
|
||
<li><code class="language-plaintext highlighter-rouge">timer</code>
|
||
for the context of user callback functions for <a href="#ngxtimerat">ngx.timer.*</a>.</li>
|
||
</ul>
|
||
|
||
<p>This API was first introduced in the <code class="language-plaintext highlighter-rouge">v0.5.10</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxthreadspawn">ngx.thread.spawn</h2>
|
||
<p><strong>syntax:</strong> <em>co = ngx.thread.spawn(func, arg1, arg2, …)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Spawns a new user “light thread” with the Lua function <code class="language-plaintext highlighter-rouge">func</code> as well as those optional arguments <code class="language-plaintext highlighter-rouge">arg1</code>, <code class="language-plaintext highlighter-rouge">arg2</code>, and etc. Returns a Lua thread (or Lua coroutine) object represents this “light thread”.</p>
|
||
|
||
<p>“Light threads” are just a special kind of Lua coroutines that are scheduled by the ngx_lua module.</p>
|
||
|
||
<p>Before <code class="language-plaintext highlighter-rouge">ngx.thread.spawn</code> returns, the <code class="language-plaintext highlighter-rouge">func</code> will be called with those optional arguments until it returns, aborts with an error, or gets yielded due to I/O operations via the <a href="#nginx-api-for-lua">Nginx API for Lua</a> (like <a href="#tcpsockreceive">tcpsock:receive</a>).</p>
|
||
|
||
<p>After <code class="language-plaintext highlighter-rouge">ngx.thread.spawn</code> returns, the newly-created “light thread” will keep running asynchronously usually at various I/O events.</p>
|
||
|
||
<p>All the Lua code chunks running by <a href="#rewrite_by_lua">rewrite_by_lua</a>, <a href="#access_by_lua">access_by_lua</a>, and <a href="#content_by_lua">content_by_lua</a> are in a boilerplate “light thread” created automatically by ngx_lua. Such boilerplate “light thread” are also called “entry threads”.</p>
|
||
|
||
<p>By default, the corresponding Nginx handler (e.g., <a href="#rewrite_by_lua">rewrite_by_lua</a> handler) will not terminate until</p>
|
||
|
||
<ol>
|
||
<li>both the “entry thread” and all the user “light threads” terminates,</li>
|
||
<li>a “light thread” (either the “entry thread” or a user “light thread” aborts by calling <a href="#ngxexit">ngx.exit</a>, <a href="#ngxexec">ngx.exec</a>, <a href="#ngxredirect">ngx.redirect</a>, or <a href="#ngxreqset_uri">ngx.req.set_uri(uri, true)</a>, or</li>
|
||
<li>the “entry thread” terminates with a Lua error.</li>
|
||
</ol>
|
||
|
||
<p>When the user “light thread” terminates with a Lua error, however, it will not abort other running “light threads” like the “entry thread” does.</p>
|
||
|
||
<p>Due to the limitation in the Nginx subrequest model, it is not allowed to abort a running Nginx subrequest in general. So it is also prohibited to abort a running “light thread” that is pending on one ore more Nginx subrequests. You must call <a href="#ngxthreadwait">ngx.thread.wait</a> to wait for those “light thread” to terminate before quitting the “world”. A notable exception here is that you can abort pending subrequests by calling <a href="#ngxexit">ngx.exit</a> with and only with the status code <code class="language-plaintext highlighter-rouge">ngx.ERROR</code> (-1), <code class="language-plaintext highlighter-rouge">408</code>, <code class="language-plaintext highlighter-rouge">444</code>, or <code class="language-plaintext highlighter-rouge">499</code>.</p>
|
||
|
||
<p>The “light threads” are not scheduled in a pre-emptive way. In other words, no time-slicing is performed automatically. A “light thread” will keep running exclusively on the CPU until</p>
|
||
|
||
<ol>
|
||
<li>a (nonblocking) I/O operation cannot be completed in a single run,</li>
|
||
<li>it calls <a href="#coroutineyield">coroutine.yield</a> to actively give up execution, or</li>
|
||
<li>it is aborted by a Lua error or an invocation of <a href="#ngxexit">ngx.exit</a>, <a href="#ngxexec">ngx.exec</a>, <a href="#ngxredirect">ngx.redirect</a>, or <a href="#ngxreqset_uri">ngx.req.set_uri(uri, true)</a>.</li>
|
||
</ol>
|
||
|
||
<p>For the first two cases, the “light thread” will usually be resumed later by the ngx_lua scheduler unless a “stop-the-world” event happens.</p>
|
||
|
||
<p>User “light threads” can create “light threads” themselves. And normal user coroutines created by <a href="#coroutinecreate">coroutine.create</a> can also create “light threads”. The coroutine (be it a normal Lua coroutine or a “light thread”) that directly spawns the “light thread” is called the “parent coroutine” for the “light thread” newly spawned.</p>
|
||
|
||
<p>The “parent coroutine” can call <a href="#ngxthreadwait">ngx.thread.wait</a> to wait on the termination of its child “light thread”.</p>
|
||
|
||
<p>You can call coroutine.status() and coroutine.yield() on the “light thread” coroutines.</p>
|
||
|
||
<p>The status of the “light thread” coroutine can be “zombie” if</p>
|
||
|
||
<ol>
|
||
<li>the current “light thread” already terminates (either successfully or with an error),</li>
|
||
<li>its parent coroutine is still alive, and</li>
|
||
<li>its parent coroutine is not waiting on it with <a href="#ngxthreadwait">ngx.thread.wait</a>.</li>
|
||
</ol>
|
||
|
||
<p>The following example demonstrates the use of coroutine.yield() in the “light thread” coroutines
|
||
to do manual time-slicing:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">yield</span> <span class="o">=</span> <span class="nb">coroutine.yield</span>
|
||
|
||
<span class="k">function</span> <span class="nf">f</span><span class="p">()</span>
|
||
<span class="kd">local</span> <span class="n">self</span> <span class="o">=</span> <span class="nb">coroutine.running</span><span class="p">()</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"f 1"</span><span class="p">)</span>
|
||
<span class="n">yield</span><span class="p">(</span><span class="n">self</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"f 2"</span><span class="p">)</span>
|
||
<span class="n">yield</span><span class="p">(</span><span class="n">self</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"f 3"</span><span class="p">)</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="kd">local</span> <span class="n">self</span> <span class="o">=</span> <span class="nb">coroutine.running</span><span class="p">()</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"0"</span><span class="p">)</span>
|
||
<span class="n">yield</span><span class="p">(</span><span class="n">self</span><span class="p">)</span>
|
||
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"1"</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">thread</span><span class="p">.</span><span class="n">spawn</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
|
||
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"2"</span><span class="p">)</span>
|
||
<span class="n">yield</span><span class="p">(</span><span class="n">self</span><span class="p">)</span>
|
||
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"3"</span><span class="p">)</span>
|
||
<span class="n">yield</span><span class="p">(</span><span class="n">self</span><span class="p">)</span>
|
||
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"4"</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Then it will generate the output</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>0
|
||
1
|
||
f 1
|
||
2
|
||
f 2
|
||
3
|
||
f 3
|
||
4
|
||
</code></pre></div></div>
|
||
|
||
<p>“Light threads” are mostly useful for doing concurrent upstream requests in a single Nginx request handler, kinda like a generalized version of <a href="#ngxlocationcapture_multi">ngx.location.capture_multi</a> that can work with all the <a href="#nginx-api-for-lua">Nginx API for Lua</a>. The following example demonstrates parallel requests to MySQL, Memcached, and upstream HTTP services in a single Lua handler, and outputting the results in the order that they actually return (very much like the Facebook BigPipe model):</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="c1">-- query mysql, memcached, and a remote http service at the same time,</span>
|
||
<span class="c1">-- output the results in the order that they</span>
|
||
<span class="c1">-- actually return the results.</span>
|
||
|
||
<span class="kd">local</span> <span class="n">mysql</span> <span class="o">=</span> <span class="nb">require</span> <span class="s2">"resty.mysql"</span>
|
||
<span class="kd">local</span> <span class="n">memcached</span> <span class="o">=</span> <span class="nb">require</span> <span class="s2">"resty.memcached"</span>
|
||
|
||
<span class="kd">local</span> <span class="k">function</span> <span class="nf">query_mysql</span><span class="p">()</span>
|
||
<span class="kd">local</span> <span class="n">db</span> <span class="o">=</span> <span class="n">mysql</span><span class="p">:</span><span class="n">new</span><span class="p">()</span>
|
||
<span class="n">db</span><span class="p">:</span><span class="n">connect</span><span class="p">{</span>
|
||
<span class="n">host</span> <span class="o">=</span> <span class="s2">"127.0.0.1"</span><span class="p">,</span>
|
||
<span class="n">port</span> <span class="o">=</span> <span class="mi">3306</span><span class="p">,</span>
|
||
<span class="n">database</span> <span class="o">=</span> <span class="s2">"test"</span><span class="p">,</span>
|
||
<span class="n">user</span> <span class="o">=</span> <span class="s2">"monty"</span><span class="p">,</span>
|
||
<span class="n">password</span> <span class="o">=</span> <span class="s2">"mypass"</span>
|
||
<span class="p">}</span>
|
||
<span class="kd">local</span> <span class="n">res</span><span class="p">,</span> <span class="n">err</span><span class="p">,</span> <span class="n">errno</span><span class="p">,</span> <span class="n">sqlstate</span> <span class="o">=</span>
|
||
<span class="n">db</span><span class="p">:</span><span class="n">query</span><span class="p">(</span><span class="s2">"select * from cats order by id asc"</span><span class="p">)</span>
|
||
<span class="n">db</span><span class="p">:</span><span class="n">set_keepalive</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"mysql done: "</span><span class="p">,</span> <span class="n">cjson</span><span class="p">.</span><span class="n">encode</span><span class="p">(</span><span class="n">res</span><span class="p">))</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="kd">local</span> <span class="k">function</span> <span class="nf">query_memcached</span><span class="p">()</span>
|
||
<span class="kd">local</span> <span class="n">memc</span> <span class="o">=</span> <span class="n">memcached</span><span class="p">:</span><span class="n">new</span><span class="p">()</span>
|
||
<span class="n">memc</span><span class="p">:</span><span class="n">connect</span><span class="p">(</span><span class="s2">"127.0.0.1"</span><span class="p">,</span> <span class="mi">11211</span><span class="p">)</span>
|
||
<span class="kd">local</span> <span class="n">res</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">memc</span><span class="p">:</span><span class="n">get</span><span class="p">(</span><span class="s2">"some_key"</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"memcached done: "</span><span class="p">,</span> <span class="n">res</span><span class="p">)</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="kd">local</span> <span class="k">function</span> <span class="nf">query_http</span><span class="p">()</span>
|
||
<span class="kd">local</span> <span class="n">res</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">location</span><span class="p">.</span><span class="n">capture</span><span class="p">(</span><span class="s2">"/my-http-proxy"</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"http done: "</span><span class="p">,</span> <span class="n">res</span><span class="p">.</span><span class="n">body</span><span class="p">)</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">thread</span><span class="p">.</span><span class="n">spawn</span><span class="p">(</span><span class="n">query_mysql</span><span class="p">)</span> <span class="c1">-- create thread 1</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">thread</span><span class="p">.</span><span class="n">spawn</span><span class="p">(</span><span class="n">query_memcached</span><span class="p">)</span> <span class="c1">-- create thread 2</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">thread</span><span class="p">.</span><span class="n">spawn</span><span class="p">(</span><span class="n">query_http</span><span class="p">)</span> <span class="c1">-- create thread 3</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>This API was first enabled in the <code class="language-plaintext highlighter-rouge">v0.7.0</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxthreadwait">ngx.thread.wait</h2>
|
||
<p><strong>syntax:</strong> <em>ok, res1, res2, … = ngx.thread.wait(thread1, thread2, …)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Waits on one or more child “light threads” and returns the results of the first “light thread” that terminates (either successfully or with an error).</p>
|
||
|
||
<p>The arguments <code class="language-plaintext highlighter-rouge">thread1</code>, <code class="language-plaintext highlighter-rouge">thread2</code>, and etc are the Lua thread objects returned by earlier calls of <a href="#ngxthreadspawn">ngx.thread.spawn</a>.</p>
|
||
|
||
<p>The return values have exactly the same meaning as <a href="#coroutineresume">coroutine.resume</a>, that is, the first value returned is a boolean value indicating whether the “light thread” terminates successfully or not, and subsequent values returned are the return values of the user Lua function that was used to spawn the “light thread” (in case of success) or the error object (in case of failure).</p>
|
||
|
||
<p>Only the direct “parent coroutine” can wait on its child “light thread”, otherwise a Lua exception will be raised.</p>
|
||
|
||
<p>The following example demonstrates the use of <code class="language-plaintext highlighter-rouge">ngx.thread.wait</code> and <a href="#ngxlocationcapture">ngx.location.capture</a> to emulate <a href="#ngxlocationcapture_multi">ngx.location.capture_multi</a>:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">capture</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">location</span><span class="p">.</span><span class="n">capture</span>
|
||
<span class="kd">local</span> <span class="n">spawn</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">thread</span><span class="p">.</span><span class="n">spawn</span>
|
||
<span class="kd">local</span> <span class="n">wait</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">thread</span><span class="p">.</span><span class="n">wait</span>
|
||
<span class="kd">local</span> <span class="n">say</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">say</span>
|
||
|
||
<span class="kd">local</span> <span class="k">function</span> <span class="nf">fetch</span><span class="p">(</span><span class="n">uri</span><span class="p">)</span>
|
||
<span class="k">return</span> <span class="n">capture</span><span class="p">(</span><span class="n">uri</span><span class="p">)</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="kd">local</span> <span class="n">threads</span> <span class="o">=</span> <span class="p">{</span>
|
||
<span class="n">spawn</span><span class="p">(</span><span class="n">fetch</span><span class="p">,</span> <span class="s2">"/foo"</span><span class="p">),</span>
|
||
<span class="n">spawn</span><span class="p">(</span><span class="n">fetch</span><span class="p">,</span> <span class="s2">"/bar"</span><span class="p">),</span>
|
||
<span class="n">spawn</span><span class="p">(</span><span class="n">fetch</span><span class="p">,</span> <span class="s2">"/baz"</span><span class="p">)</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="k">for</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="o">#</span><span class="n">threads</span> <span class="k">do</span>
|
||
<span class="kd">local</span> <span class="n">ok</span><span class="p">,</span> <span class="n">res</span> <span class="o">=</span> <span class="n">wait</span><span class="p">(</span><span class="n">threads</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">ok</span> <span class="k">then</span>
|
||
<span class="n">say</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="s2">": failed to run: "</span><span class="p">,</span> <span class="n">res</span><span class="p">)</span>
|
||
<span class="k">else</span>
|
||
<span class="n">say</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="s2">": status: "</span><span class="p">,</span> <span class="n">res</span><span class="p">.</span><span class="n">status</span><span class="p">)</span>
|
||
<span class="n">say</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="s2">": body: "</span><span class="p">,</span> <span class="n">res</span><span class="p">.</span><span class="n">body</span><span class="p">)</span>
|
||
<span class="k">end</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Here it essentially implements the “wait all” model.</p>
|
||
|
||
<p>And below is an example demonstrating the “wait any” model:</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">function</span> <span class="nf">f</span><span class="p">()</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">0</span><span class="p">.</span><span class="mi">2</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"f: hello"</span><span class="p">)</span>
|
||
<span class="k">return</span> <span class="s2">"f done"</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="k">function</span> <span class="nf">g</span><span class="p">()</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">0</span><span class="p">.</span><span class="mi">1</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"g: hello"</span><span class="p">)</span>
|
||
<span class="k">return</span> <span class="s2">"g done"</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="kd">local</span> <span class="n">tf</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">thread</span><span class="p">.</span><span class="n">spawn</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">tf</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"failed to spawn thread f: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"f thread created: "</span><span class="p">,</span> <span class="nb">coroutine.status</span><span class="p">(</span><span class="n">tf</span><span class="p">))</span>
|
||
|
||
<span class="kd">local</span> <span class="n">tg</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">thread</span><span class="p">.</span><span class="n">spawn</span><span class="p">(</span><span class="n">g</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">tg</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"failed to spawn thread g: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"g thread created: "</span><span class="p">,</span> <span class="nb">coroutine.status</span><span class="p">(</span><span class="n">tg</span><span class="p">))</span>
|
||
|
||
<span class="n">ok</span><span class="p">,</span> <span class="n">res</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">thread</span><span class="p">.</span><span class="n">wait</span><span class="p">(</span><span class="n">tf</span><span class="p">,</span> <span class="n">tg</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">ok</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"failed to wait: "</span><span class="p">,</span> <span class="n">res</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">say</span><span class="p">(</span><span class="s2">"res: "</span><span class="p">,</span> <span class="n">res</span><span class="p">)</span>
|
||
|
||
<span class="c1">-- stop the "world", aborting other running threads</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">exit</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">OK</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>And it will generate the following output:</p>
|
||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>f thread created: running
|
||
g thread created: running
|
||
g: hello
|
||
res: g done
|
||
</code></pre></div></div>
|
||
|
||
<p>This API was first enabled in the <code class="language-plaintext highlighter-rouge">v0.7.0</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxthreadkill">ngx.thread.kill</h2>
|
||
<p><strong>syntax:</strong> <em>ok, err = ngx.thread.kill(thread)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, ngx.timer.**</p>
|
||
|
||
<p>Kills a running “light thread” created by <a href="#ngxthreadspawn">ngx.thread.spawn</a>. Returns a true value when successful or <code class="language-plaintext highlighter-rouge">nil</code> and a string describing the error otherwise.</p>
|
||
|
||
<p>According to the current implementation, only the parent coroutine (or “light thread”) can kill a thread. Also, a running “light thread” with pending NGINX subrequests (initiated by <a href="#ngxlocationcapture">ngx.location.capture</a> for example) cannot be killed due to a limitation in the NGINX core.</p>
|
||
|
||
<p>This API was first enabled in the <code class="language-plaintext highlighter-rouge">v0.9.9</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxon_abort">ngx.on_abort</h2>
|
||
<p><strong>syntax:</strong> <em>ok, err = ngx.on_abort(callback)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua*, content_by_lua**</p>
|
||
|
||
<p>Registers a user Lua function as the callback which gets called automatically when the client closes the (downstream) connection prematurely.</p>
|
||
|
||
<p>Returns <code class="language-plaintext highlighter-rouge">1</code> if the callback is registered successfully or returns <code class="language-plaintext highlighter-rouge">nil</code> and a string describing the error otherwise.</p>
|
||
|
||
<p>All the <a href="#nginx-api-for-lua">Nginx API for Lua</a> can be used in the callback function because the function is run in a special “light thread”, just as those “light threads” created by <a href="#ngxthreadspawn">ngx.thread.spawn</a>.</p>
|
||
|
||
<p>The callback function can decide what to do with the client abortion event all by itself. For example, it can simply ignore the event by doing nothing and the current Lua request handler will continue executing without interruptions. And the callback function can also decide to terminate everything by calling <a href="#ngxexit">ngx.exit</a>, for example,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="k">function</span> <span class="nf">my_cleanup</span><span class="p">()</span>
|
||
<span class="c1">-- custom cleanup work goes here, like cancelling a pending DB transaction</span>
|
||
|
||
<span class="c1">-- now abort all the "light threads" running in the current request handler</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">499</span><span class="p">)</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="kd">local</span> <span class="n">ok</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">on_abort</span><span class="p">(</span><span class="n">my_cleanup</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">ok</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">log</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">ERR</span><span class="p">,</span> <span class="s2">"failed to register the on_abort callback: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">500</span><span class="p">)</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>When <a href="#lua_check_client_abort">lua_check_client_abort</a> is set to <code class="language-plaintext highlighter-rouge">off</code> (which is the default), then this function call will always return the error message “lua_check_client_abort is off”.</p>
|
||
|
||
<p>According to the current implementation, this function can only be called once in a single request handler; subsequent calls will return the error message “duplicate call”.</p>
|
||
|
||
<p>This API was first introduced in the <code class="language-plaintext highlighter-rouge">v0.7.4</code> release.</p>
|
||
|
||
<p>See also <a href="#lua_check_client_abort">lua_check_client_abort</a>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxtimerat">ngx.timer.at</h2>
|
||
<p><strong>syntax:</strong> <em>ok, err = ngx.timer.at(delay, callback, user_arg1, user_arg2, …)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>Creates an Nginx timer with a user callback function as well as optional user arguments.</p>
|
||
|
||
<p>The first argument, <code class="language-plaintext highlighter-rouge">delay</code>, specifies the delay for the timer,
|
||
in seconds. One can specify fractional seconds like <code class="language-plaintext highlighter-rouge">0.001</code> to mean 1
|
||
millisecond here. <code class="language-plaintext highlighter-rouge">0</code> delay can also be specified, in which case the
|
||
timer will immediately expire when the current handler yields
|
||
execution.</p>
|
||
|
||
<p>The second argument, <code class="language-plaintext highlighter-rouge">callback</code>, can
|
||
be any Lua function, which will be invoked later in a background
|
||
“light thread” after the delay specified. The user callback will be
|
||
called automatically by the Nginx core with the arguments <code class="language-plaintext highlighter-rouge">premature</code>,
|
||
<code class="language-plaintext highlighter-rouge">user_arg1</code>, <code class="language-plaintext highlighter-rouge">user_arg2</code>, and etc, where the <code class="language-plaintext highlighter-rouge">premature</code>
|
||
argument takes a boolean value indicating whether it is a premature timer
|
||
expiration or not, and <code class="language-plaintext highlighter-rouge">user_arg1</code>, <code class="language-plaintext highlighter-rouge">user_arg2</code>, and etc, are
|
||
those (extra) user arguments specified when calling <code class="language-plaintext highlighter-rouge">ngx.timer.at</code>
|
||
as the remaining arguments.</p>
|
||
|
||
<p>Premature timer expiration happens when the Nginx worker process is
|
||
trying to shut down, as in an Nginx configuration reload triggered by
|
||
the <code class="language-plaintext highlighter-rouge">HUP</code> signal or in an Nginx server shutdown. When the Nginx worker
|
||
is trying to shut down, one can no longer call <code class="language-plaintext highlighter-rouge">ngx.timer.at</code> to
|
||
create new timers with nonzero delays and in that case <code class="language-plaintext highlighter-rouge">ngx.timer.at</code> will return <code class="language-plaintext highlighter-rouge">nil</code> and
|
||
a string describing the error, that is, “process exiting”.</p>
|
||
|
||
<p>Starting from the <code class="language-plaintext highlighter-rouge">v0.9.3</code> release, it is allowed to create zero-delay timers even when the Nginx worker process starts shutting down.</p>
|
||
|
||
<p>When a timer expires, the user Lua code in the timer callback is
|
||
running in a “light thread” detached completely from the original
|
||
request creating the timer. So objects with the same lifetime as the
|
||
request creating them, like <a href="#ngxsockettcp">cosockets</a>, cannot be shared between the
|
||
original request and the timer user callback function.</p>
|
||
|
||
<p>Here is a simple example:</p>
|
||
|
||
<div class="language-nginx highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="k">location</span> <span class="n">/</span> <span class="p">{</span>
|
||
<span class="kn">...</span>
|
||
<span class="s">log_by_lua</span> <span class="s">'</span>
|
||
<span class="s">local</span> <span class="s">function</span> <span class="s">push_data(premature,</span> <span class="s">uri,</span> <span class="s">args,</span> <span class="s">status)</span>
|
||
<span class="s">--</span> <span class="s">push</span> <span class="s">the</span> <span class="s">data</span> <span class="s">uri,</span> <span class="s">args,</span> <span class="s">and</span> <span class="s">status</span> <span class="s">to</span> <span class="s">the</span> <span class="s">remote</span>
|
||
<span class="s">--</span> <span class="s">via</span> <span class="s">ngx.socket.tcp</span> <span class="s">or</span> <span class="s">ngx.socket.udp</span>
|
||
<span class="s">--</span> <span class="s">(one</span> <span class="s">may</span> <span class="s">want</span> <span class="s">to</span> <span class="s">buffer</span> <span class="s">the</span> <span class="s">data</span> <span class="s">in</span> <span class="s">Lua</span> <span class="s">a</span> <span class="s">bit</span> <span class="s">to</span>
|
||
<span class="s">--</span> <span class="s">save</span> <span class="nc">I/O</span> <span class="s">operations)</span>
|
||
<span class="s">end</span>
|
||
<span class="s">local</span> <span class="s">ok,</span> <span class="s">err</span> <span class="p">=</span> <span class="s">ngx.timer.at(0,</span> <span class="s">push_data,</span>
|
||
<span class="s">ngx.var.uri,</span> <span class="s">ngx.var.args,</span> <span class="s">ngx.header.status)</span>
|
||
<span class="s">if</span> <span class="s">not</span> <span class="s">ok</span> <span class="s">then</span>
|
||
<span class="s">ngx.log(ngx.ERR,</span> <span class="s">"failed</span> <span class="s">to</span> <span class="s">create</span> <span class="s">timer:</span> <span class="s">",</span> <span class="s">err)</span>
|
||
<span class="s">return</span>
|
||
<span class="s">end</span>
|
||
<span class="s">'</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>One can also create infinite re-occuring timers, for instance, a timer getting triggered every <code class="language-plaintext highlighter-rouge">5</code> seconds, by calling <code class="language-plaintext highlighter-rouge">ngx.timer.at</code> recursively in the timer callback function. Here is such an example,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">delay</span> <span class="o">=</span> <span class="mi">5</span>
|
||
<span class="kd">local</span> <span class="n">handler</span>
|
||
<span class="n">handler</span> <span class="o">=</span> <span class="k">function</span> <span class="p">(</span><span class="n">premature</span><span class="p">)</span>
|
||
<span class="c1">-- do some routine job in Lua just like a cron job</span>
|
||
<span class="k">if</span> <span class="n">premature</span> <span class="k">then</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
<span class="kd">local</span> <span class="n">ok</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">timer</span><span class="p">.</span><span class="n">at</span><span class="p">(</span><span class="n">delay</span><span class="p">,</span> <span class="n">handler</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">ok</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">log</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">ERR</span><span class="p">,</span> <span class="s2">"failed to create the timer: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
<span class="k">end</span>
|
||
|
||
<span class="kd">local</span> <span class="n">ok</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">ngx</span><span class="p">.</span><span class="n">timer</span><span class="p">.</span><span class="n">at</span><span class="p">(</span><span class="n">delay</span><span class="p">,</span> <span class="n">handler</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">ok</span> <span class="k">then</span>
|
||
<span class="n">ngx</span><span class="p">.</span><span class="n">log</span><span class="p">(</span><span class="n">ngx</span><span class="p">.</span><span class="n">ERR</span><span class="p">,</span> <span class="s2">"failed to create the timer: "</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
<span class="k">end</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Because timer callbacks run in the background and their running time
|
||
will not add to any client request’s response time, they can easily
|
||
accumulate in the server and exhaust system resources due to either
|
||
Lua programming mistakes or just too much client traffic. To prevent
|
||
extreme consequences like crashing the Nginx server, there are
|
||
built-in limitations on both the number of “pending timers” and the
|
||
number of “running timers” in an Nginx worker process. The “pending
|
||
timers” here mean timers that have not yet been expired and “running
|
||
timers” are those whose user callbacks are currently running.</p>
|
||
|
||
<p>The maximal number of pending timers allowed in an Nginx
|
||
worker is constrolled by the <a href="#lua_max_pending_timers">lua_max_pending_timers</a>
|
||
directive. The maximal number of running timers is controlled by the
|
||
<a href="#lua_max_running_timers">lua_max_running_timers</a> directive.</p>
|
||
|
||
<p>According to the current implementation, each “running timer” will
|
||
take one (fake) connection record from the global connection record
|
||
list configured by the standard <a href="http://nginx.org/en/docs/ngx_core_module.html#worker_connections">worker_connections</a> directive in
|
||
<code class="language-plaintext highlighter-rouge">nginx.conf</code>. So ensure that the
|
||
<a href="http://nginx.org/en/docs/ngx_core_module.html#worker_connections">worker_connections</a> directive is set to
|
||
a large enough value that takes into account both the real connections
|
||
and fake connections required by timer callbacks (as limited by the
|
||
<a href="#lua_max_running_timers">lua_max_running_timers</a> directive).</p>
|
||
|
||
<p>A lot of the Lua APIs for Nginx are enabled in the context of the timer
|
||
callbacks, like stream/datagram cosockets (<a href="#ngxsockettcp">ngx.socket.tcp</a> and <a href="#ngxsocketudp">ngx.socket.udp</a>), shared
|
||
memory dictionaries (<a href="#ngxshareddict">ngx.shared.DICT</a>), user coroutines (<a href="#ngxthreadspawn">coroutine.<em>](#coroutinecreate)),
|
||
user “light threads” ([ngx.thread.</em></a>), <a href="#ngxexit">ngx.exit</a>, <a href="#ngxnow">ngx.now</a>/<a href="#ngxtime">ngx.time</a>,
|
||
<a href="#ngxmd5">ngx.md5</a>/<a href="#ngxsha1_bin">ngx.sha1_bin</a>, are all allowed. But the subrequest API (like
|
||
<a href="#ngxlocationcapture">ngx.location.capture</a>), the <a href="#ngxreqstart_time">ngx.req.*</a> API, the downstream output API
|
||
(like <a href="#ngxsay">ngx.say</a>, <a href="#ngxprint">ngx.print</a>, and <a href="#ngxflush">ngx.flush</a>) are explicitly disabled in
|
||
this context.</p>
|
||
|
||
<p>You can pass most of the standard Lua values (nils, booleans, numbers, strings, tables, closures, file handles, and etc) into the timer callback, either explicitly as user arguments or implicitly as upvalues for the callback closure. There are several exceptions, however: you <em>cannot</em> pass any thread objects returned by <a href="#coroutinecreate">coroutine.create</a> and <a href="#ngxthreadspawn">ngx.thread.spawn</a> or any cosocket objects returned by <a href="#ngxsockettcp">ngx.socket.tcp</a>, <a href="#ngxsocketudp">ngx.socket.udp</a>, and <a href="#ngxreqsocket">ngx.req.socket</a> because these objects’ lifetime is bound to the request context creating them while the timer callback is detached from the creating request’s context (by design) and runs in its own (fake) request context. If you try to share the thread or cosocket objects across the boundary of the creating request, then you will get the “no co ctx found” error (for threads) or “bad request” (for cosockets). It is fine, however, to create all these objects inside your timer callback.</p>
|
||
|
||
<p>This API was first introduced in the <code class="language-plaintext highlighter-rouge">v0.8.0</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxconfigdebug">ngx.config.debug</h2>
|
||
<p><strong>syntax:</strong> <em>debug = ngx.config.debug</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.<em>, init_by_lua</em>, init_worker_by_lua**</p>
|
||
|
||
<p>This boolean field indicates whether the current Nginx is a debug build, i.e., being built by the <code class="language-plaintext highlighter-rouge">./configure</code> option <code class="language-plaintext highlighter-rouge">--with-debug</code>.</p>
|
||
|
||
<p>This field was first introduced in the <code class="language-plaintext highlighter-rouge">0.8.7</code>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxconfigprefix">ngx.config.prefix</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>prefix = ngx.config.prefix()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.<em>, init_by_lua</em>, init_worker_by_lua**</p>
|
||
|
||
<p>Returns the Nginx server “prefix” path, as determined by the <code class="language-plaintext highlighter-rouge">-p</code> command-line option when running the nginx executable, or the path specified by the <code class="language-plaintext highlighter-rouge">--prefix</code> command-line option when building Nginx with the <code class="language-plaintext highlighter-rouge">./configure</code> script.</p>
|
||
|
||
<p>This function was first introduced in the <code class="language-plaintext highlighter-rouge">0.9.2</code>.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxconfignginx_version">ngx.config.nginx_version</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>ver = ngx.config.nginx_version</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.<em>, init_by_lua</em>, init_worker_by_lua**</p>
|
||
|
||
<p>This field take an integral value indicating the version number of the current Nginx core being used. For example, the version number <code class="language-plaintext highlighter-rouge">1.4.3</code> results in the Lua number 1004003.</p>
|
||
|
||
<p>This API was first introduced in the <code class="language-plaintext highlighter-rouge">0.9.3</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxconfignginx_configure">ngx.config.nginx_configure</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>str = ngx.config.nginx_configure()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.*, init_by_lua**</p>
|
||
|
||
<p>This function returns a string for the NGINX <code class="language-plaintext highlighter-rouge">./configure</code> command’s arguments string.</p>
|
||
|
||
<p>This API was first introduced in the <code class="language-plaintext highlighter-rouge">0.9.5</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxconfigngx_lua_version">ngx.config.ngx_lua_version</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>ver = ngx.config.ngx_lua_version</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.*, init_by_lua**</p>
|
||
|
||
<p>This field take an integral value indicating the version number of the current <code class="language-plaintext highlighter-rouge">ngx_lua</code> module being used. For example, the version number <code class="language-plaintext highlighter-rouge">0.9.3</code> results in the Lua number 9003.</p>
|
||
|
||
<p>This API was first introduced in the <code class="language-plaintext highlighter-rouge">0.9.3</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxworkerexiting">ngx.worker.exiting</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>exiting = ngx.worker.exiting()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.<em>, init_by_lua</em>, init_worker_by_lua**</p>
|
||
|
||
<p>This function returns a boolean value indicating whether the current Nginx worker process already starts exiting. Nginx worker process exiting happens on Nginx server quit or configuration reload (aka HUP reload).</p>
|
||
|
||
<p>This API was first introduced in the <code class="language-plaintext highlighter-rouge">0.9.3</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ngxworkerpid">ngx.worker.pid</h2>
|
||
|
||
<p><strong>syntax:</strong> <em>pid = ngx.worker.pid()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>set_by_lua</em>, rewrite_by_lua<em>, access_by_lua</em>, content_by_lua<em>, header_filter_by_lua</em>, body_filter_by_lua<em>, log_by_lua</em>, ngx.timer.<em>, init_by_lua</em>, init_worker_by_lua**</p>
|
||
|
||
<p>This function returns a Lua number for the process ID (PID) of the current Nginx worker process. This API is more efficient than <code class="language-plaintext highlighter-rouge">ngx.var.pid</code> and can be used in contexts where the <a href="#ngxvarvariable">ngx.var.VARIABLE</a> API cannot be used (like <a href="#init_worker_by_lua">init_worker_by_lua</a>).</p>
|
||
|
||
<p>This API was first introduced in the <code class="language-plaintext highlighter-rouge">0.9.5</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="ndkset_vardirective">ndk.set_var.DIRECTIVE</h2>
|
||
<p><strong>syntax:</strong> <em>res = ndk.set_var.DIRECTIVE_NAME</em></p>
|
||
|
||
<p><strong>context:</strong> <em>init_worker_by_lua</em>, set_by_lua<em>, rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, header_filter_by_lua<em>, body_filter_by_lua</em>, log_by_lua*, ngx.timer.**</p>
|
||
|
||
<p>This mechanism allows calling other nginx C modules’ directives that are implemented by <a href="https://github.com/simpl/ngx_devel_kit">Nginx Devel Kit</a> (NDK)’s set_var submodule’s <code class="language-plaintext highlighter-rouge">ndk_set_var_value</code>.</p>
|
||
|
||
<p>For example, the following <a href="http://github.com/openresty/set-misc-nginx-module">set-misc-nginx-module</a> directives can be invoked this way:</p>
|
||
|
||
<ul>
|
||
<li><a href="http://github.com/openresty/set-misc-nginx-module#set_quote_sql_str">set_quote_sql_str</a></li>
|
||
<li><a href="http://github.com/openresty/set-misc-nginx-module#set_quote_pgsql_str">set_quote_pgsql_str</a></li>
|
||
<li><a href="http://github.com/openresty/set-misc-nginx-module#set_quote_json_str">set_quote_json_str</a></li>
|
||
<li><a href="http://github.com/openresty/set-misc-nginx-module#set_unescape_uri">set_unescape_uri</a></li>
|
||
<li><a href="http://github.com/openresty/set-misc-nginx-module#set_escape_uri">set_escape_uri</a></li>
|
||
<li><a href="http://github.com/openresty/set-misc-nginx-module#set_encode_base32">set_encode_base32</a></li>
|
||
<li><a href="http://github.com/openresty/set-misc-nginx-module#set_decode_base32">set_decode_base32</a></li>
|
||
<li><a href="http://github.com/openresty/set-misc-nginx-module#set_encode_base64">set_encode_base64</a></li>
|
||
<li><a href="http://github.com/openresty/set-misc-nginx-module#set_decode_base64">set_decode_base64</a></li>
|
||
<li><a href="http://github.com/openresty/set-misc-nginx-module#set_encode_base64">set_encode_hex</a></li>
|
||
<li><a href="http://github.com/openresty/set-misc-nginx-module#set_decode_base64">set_decode_hex</a></li>
|
||
<li><a href="http://github.com/openresty/set-misc-nginx-module#set_encode_base64">set_sha1</a></li>
|
||
<li><a href="http://github.com/openresty/set-misc-nginx-module#set_decode_base64">set_md5</a></li>
|
||
</ul>
|
||
|
||
<p>For instance,</p>
|
||
|
||
<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
|
||
<span class="kd">local</span> <span class="n">res</span> <span class="o">=</span> <span class="n">ndk</span><span class="p">.</span><span class="n">set_var</span><span class="p">.</span><span class="n">set_escape_uri</span><span class="p">(</span><span class="s1">'a/b'</span><span class="p">);</span>
|
||
<span class="c1">-- now res == 'a%2fb'</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Similarly, the following directives provided by <a href="http://github.com/openresty/encrypted-session-nginx-module">encrypted-session-nginx-module</a> can be invoked from within Lua too:</p>
|
||
|
||
<ul>
|
||
<li><a href="http://github.com/openresty/encrypted-session-nginx-module#set_encrypt_session">set_encrypt_session</a></li>
|
||
<li><a href="http://github.com/openresty/encrypted-session-nginx-module#set_decrypt_session">set_decrypt_session</a></li>
|
||
</ul>
|
||
|
||
<p>This feature requires the <a href="https://github.com/simpl/ngx_devel_kit">ngx_devel_kit</a> module.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="coroutinecreate">coroutine.create</h2>
|
||
<p><strong>syntax:</strong> <em>co = coroutine.create(f)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, init_by_lua<em>, ngx.timer.</em>, header_filter_by_lua*, body_filter_by_lua**</p>
|
||
|
||
<p>Creates a user Lua coroutines with a Lua function, and returns a coroutine object.</p>
|
||
|
||
<p>Similar to the standard Lua <a href="http://www.lua.org/manual/5.1/manual.html#pdf-coroutine.create">coroutine.create</a> API, but works in the context of the Lua coroutines created by ngx_lua.</p>
|
||
|
||
<p>This API was first usable in the context of <a href="#init_by_lua">init_by_lua*</a> since the <code class="language-plaintext highlighter-rouge">0.9.2</code>.</p>
|
||
|
||
<p>This API was first introduced in the <code class="language-plaintext highlighter-rouge">v0.6.0</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="coroutineresume">coroutine.resume</h2>
|
||
<p><strong>syntax:</strong> <em>ok, … = coroutine.resume(co, …)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, init_by_lua<em>, ngx.timer.</em>, header_filter_by_lua*, body_filter_by_lua**</p>
|
||
|
||
<p>Resumes the executation of a user Lua coroutine object previously yielded or just created.</p>
|
||
|
||
<p>Similar to the standard Lua <a href="http://www.lua.org/manual/5.1/manual.html#pdf-coroutine.resume">coroutine.resume</a> API, but works in the context of the Lua coroutines created by ngx_lua.</p>
|
||
|
||
<p>This API was first usable in the context of <a href="#init_by_lua">init_by_lua*</a> since the <code class="language-plaintext highlighter-rouge">0.9.2</code>.</p>
|
||
|
||
<p>This API was first introduced in the <code class="language-plaintext highlighter-rouge">v0.6.0</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="coroutineyield">coroutine.yield</h2>
|
||
<p><strong>syntax:</strong> <em>… = coroutine.yield(…)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, init_by_lua<em>, ngx.timer.</em>, header_filter_by_lua*, body_filter_by_lua**</p>
|
||
|
||
<p>Yields the executation of the current user Lua coroutine.</p>
|
||
|
||
<p>Similar to the standard Lua <a href="http://www.lua.org/manual/5.1/manual.html#pdf-coroutine.yield">coroutine.yield</a> API, but works in the context of the Lua coroutines created by ngx_lua.</p>
|
||
|
||
<p>This API was first usable in the context of <a href="#init_by_lua">init_by_lua*</a> since the <code class="language-plaintext highlighter-rouge">0.9.2</code>.</p>
|
||
|
||
<p>This API was first introduced in the <code class="language-plaintext highlighter-rouge">v0.6.0</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="coroutinewrap">coroutine.wrap</h2>
|
||
<p><strong>syntax:</strong> <em>co = coroutine.wrap(f)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, init_by_lua<em>, ngx.timer.</em>, header_filter_by_lua*, body_filter_by_lua**</p>
|
||
|
||
<p>Similar to the standard Lua <a href="http://www.lua.org/manual/5.1/manual.html#pdf-coroutine.wrap">coroutine.wrap</a> API, but works in the context of the Lua coroutines created by ngx_lua.</p>
|
||
|
||
<p>This API was first usable in the context of <a href="#init_by_lua">init_by_lua*</a> since the <code class="language-plaintext highlighter-rouge">0.9.2</code>.</p>
|
||
|
||
<p>This API was first introduced in the <code class="language-plaintext highlighter-rouge">v0.6.0</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="coroutinerunning">coroutine.running</h2>
|
||
<p><strong>syntax:</strong> <em>co = coroutine.running()</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, init_by_lua<em>, ngx.timer.</em>, header_filter_by_lua*, body_filter_by_lua**</p>
|
||
|
||
<p>Identical to the standard Lua <a href="http://www.lua.org/manual/5.1/manual.html#pdf-coroutine.running">coroutine.running</a> API.</p>
|
||
|
||
<p>This API was first usable in the context of <a href="#init_by_lua">init_by_lua*</a> since the <code class="language-plaintext highlighter-rouge">0.9.2</code>.</p>
|
||
|
||
<p>This API was first enabled in the <code class="language-plaintext highlighter-rouge">v0.6.0</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h2 id="coroutinestatus">coroutine.status</h2>
|
||
<p><strong>syntax:</strong> <em>status = coroutine.status(co)</em></p>
|
||
|
||
<p><strong>context:</strong> <em>rewrite_by_lua</em>, access_by_lua<em>, content_by_lua</em>, init_by_lua<em>, ngx.timer.</em>, header_filter_by_lua*, body_filter_by_lua**</p>
|
||
|
||
<p>Identical to the standard Lua <a href="http://www.lua.org/manual/5.1/manual.html#pdf-coroutine.status">coroutine.status</a> API.</p>
|
||
|
||
<p>This API was first usable in the context of <a href="#init_by_lua">init_by_lua*</a> since the <code class="language-plaintext highlighter-rouge">0.9.2</code>.</p>
|
||
|
||
<p>This API was first enabled in the <code class="language-plaintext highlighter-rouge">v0.6.0</code> release.</p>
|
||
|
||
<p><a href="#nginx-api-for-lua">Back to TOC</a></p>
|
||
|
||
<h1 id="obsolete-sections">Obsolete Sections</h1>
|
||
|
||
<p>This section is just holding obsolete documentation sections that have been either renamed or removed so that existing links over the web are still valid.</p>
|
||
|
||
<p><a href="#table-of-contents">Back to TOC</a></p>
|
||
|
||
<h2 id="special-pcre-sequences">Special PCRE Sequences</h2>
|
||
|
||
<p>This section has been renamed to <a href="#special-escaping-sequences">Special Escaping Sequences</a>.</p>
|
||
|
||
|
||
</div>
|
||
|
||
|
||
|
||
<div class="d-print-none"><footer class="article__footer"><meta itemprop="dateModified" content="2019-12-25T00:00:00+01:00"><!-- start custom article footer snippet -->
|
||
|
||
<!-- end custom article footer snippet -->
|
||
<!--
|
||
<div align="right"><a type="application/rss+xml" href="/feed.xml" title="S'abonner"><i class="fa fa-rss fa-2x"></i></a>
|
||
|
||
 </div>
|
||
-->
|
||
</footer>
|
||
<div class="article__section-navigator clearfix"><div class="previous"><span>PRÉCÉDENT</span><a href="/2019/12/25/nginx-authentification-base-mysql.html">nginx-authentification-base-mysql</a></div><div class="next"><span>SUIVANT</span><a href="/2019/12/25/nmap.html">nmap</a></div></div></div>
|
||
|
||
</div>
|
||
|
||
<script>(function() {
|
||
var SOURCES = window.TEXT_VARIABLES.sources;
|
||
window.Lazyload.js(SOURCES.jquery, function() {
|
||
$(function() {
|
||
var $this ,$scroll;
|
||
var $articleContent = $('.js-article-content');
|
||
var hasSidebar = $('.js-page-root').hasClass('layout--page--sidebar');
|
||
var scroll = hasSidebar ? '.js-page-main' : 'html, body';
|
||
$scroll = $(scroll);
|
||
|
||
$articleContent.find('.highlight').each(function() {
|
||
$this = $(this);
|
||
$this.attr('data-lang', $this.find('code').attr('data-lang'));
|
||
});
|
||
$articleContent.find('h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]').each(function() {
|
||
$this = $(this);
|
||
$this.append($('<a class="anchor d-print-none" aria-hidden="true"></a>').html('<i class="fas fa-anchor"></i>'));
|
||
});
|
||
$articleContent.on('click', '.anchor', function() {
|
||
$scroll.scrollToAnchor('#' + $(this).parent().attr('id'), 400);
|
||
});
|
||
});
|
||
});
|
||
})();
|
||
</script>
|
||
|
||
</div><section class="page__comments d-print-none"></section></article><!-- start custom main bottom snippet -->
|
||
<!-- end custom main bottom snippet -->
|
||
</div>
|
||
</div></div></div></div>
|
||
</div><script>(function() {
|
||
var SOURCES = window.TEXT_VARIABLES.sources;
|
||
window.Lazyload.js(SOURCES.jquery, function() {
|
||
var $body = $('body'), $window = $(window);
|
||
var $pageRoot = $('.js-page-root'), $pageMain = $('.js-page-main');
|
||
var activeCount = 0;
|
||
function modal(options) {
|
||
var $root = this, visible, onChange, hideWhenWindowScroll = false;
|
||
var scrollTop;
|
||
function setOptions(options) {
|
||
var _options = options || {};
|
||
visible = _options.initialVisible === undefined ? false : show;
|
||
onChange = _options.onChange;
|
||
hideWhenWindowScroll = _options.hideWhenWindowScroll;
|
||
}
|
||
function init() {
|
||
setState(visible);
|
||
}
|
||
function setState(isShow) {
|
||
if (isShow === visible) {
|
||
return;
|
||
}
|
||
visible = isShow;
|
||
if (visible) {
|
||
activeCount++;
|
||
scrollTop = $(window).scrollTop() || $pageMain.scrollTop();
|
||
$root.addClass('modal--show');
|
||
$pageMain.scrollTop(scrollTop);
|
||
activeCount === 1 && ($pageRoot.addClass('show-modal'), $body.addClass('of-hidden'));
|
||
hideWhenWindowScroll && window.hasEvent('touchstart') && $window.on('scroll', hide);
|
||
$window.on('keyup', handleKeyup);
|
||
} else {
|
||
activeCount > 0 && activeCount--;
|
||
$root.removeClass('modal--show');
|
||
$window.scrollTop(scrollTop);
|
||
activeCount === 0 && ($pageRoot.removeClass('show-modal'), $body.removeClass('of-hidden'));
|
||
hideWhenWindowScroll && window.hasEvent('touchstart') && $window.off('scroll', hide);
|
||
$window.off('keyup', handleKeyup);
|
||
}
|
||
onChange && onChange(visible);
|
||
}
|
||
function show() {
|
||
setState(true);
|
||
}
|
||
function hide() {
|
||
setState(false);
|
||
}
|
||
function handleKeyup(e) {
|
||
// Char Code: 27 ESC
|
||
if (e.which === 27) {
|
||
hide();
|
||
}
|
||
}
|
||
setOptions(options);
|
||
init();
|
||
return {
|
||
show: show,
|
||
hide: hide,
|
||
$el: $root
|
||
};
|
||
}
|
||
$.fn.modal = modal;
|
||
});
|
||
})();
|
||
</script><div class="modal modal--overflow page__search-modal d-print-none js-page-search-modal"><script>
|
||
(function () {
|
||
var SOURCES = window.TEXT_VARIABLES.sources;
|
||
window.Lazyload.js(SOURCES.jquery, function() {
|
||
// search panel
|
||
var search = (window.search || (window.search = {}));
|
||
var useDefaultSearchBox = window.useDefaultSearchBox === undefined ?
|
||
true : window.useDefaultSearchBox ;
|
||
|
||
var $searchModal = $('.js-page-search-modal');
|
||
var $searchToggle = $('.js-search-toggle');
|
||
var searchModal = $searchModal.modal({ onChange: handleModalChange, hideWhenWindowScroll: true });
|
||
var modalVisible = false;
|
||
search.searchModal = searchModal;
|
||
|
||
var $searchBox = null;
|
||
var $searchInput = null;
|
||
var $searchClear = null;
|
||
|
||
function getModalVisible() {
|
||
return modalVisible;
|
||
}
|
||
search.getModalVisible = getModalVisible;
|
||
|
||
function handleModalChange(visible) {
|
||
modalVisible = visible;
|
||
if (visible) {
|
||
search.onShow && search.onShow();
|
||
useDefaultSearchBox && $searchInput[0] && $searchInput[0].focus();
|
||
} else {
|
||
search.onShow && search.onHide();
|
||
useDefaultSearchBox && $searchInput[0] && $searchInput[0].blur();
|
||
setTimeout(function() {
|
||
useDefaultSearchBox && ($searchInput.val(''), $searchBox.removeClass('not-empty'));
|
||
search.clear && search.clear();
|
||
window.pageAsideAffix && window.pageAsideAffix.refresh();
|
||
}, 400);
|
||
}
|
||
}
|
||
|
||
$searchToggle.on('click', function() {
|
||
modalVisible ? searchModal.hide() : searchModal.show();
|
||
});
|
||
// Char Code: 83 S, 191 /
|
||
$(window).on('keyup', function(e) {
|
||
if (!modalVisible && !window.isFormElement(e.target || e.srcElement) && (e.which === 83 || e.which === 191)) {
|
||
modalVisible || searchModal.show();
|
||
}
|
||
});
|
||
|
||
if (useDefaultSearchBox) {
|
||
$searchBox = $('.js-search-box');
|
||
$searchInput = $searchBox.children('input');
|
||
$searchClear = $searchBox.children('.js-icon-clear');
|
||
search.getSearchInput = function() {
|
||
return $searchInput.get(0);
|
||
};
|
||
search.getVal = function() {
|
||
return $searchInput.val();
|
||
};
|
||
search.setVal = function(val) {
|
||
$searchInput.val(val);
|
||
};
|
||
|
||
$searchInput.on('focus', function() {
|
||
$(this).addClass('focus');
|
||
});
|
||
$searchInput.on('blur', function() {
|
||
$(this).removeClass('focus');
|
||
});
|
||
$searchInput.on('input', window.throttle(function() {
|
||
var val = $(this).val();
|
||
if (val === '' || typeof val !== 'string') {
|
||
search.clear && search.clear();
|
||
} else {
|
||
$searchBox.addClass('not-empty');
|
||
search.onInputNotEmpty && search.onInputNotEmpty(val);
|
||
}
|
||
}, 400));
|
||
$searchClear.on('click', function() {
|
||
$searchInput.val(''); $searchBox.removeClass('not-empty');
|
||
search.clear && search.clear();
|
||
});
|
||
}
|
||
});
|
||
})();
|
||
</script><div class="search search--dark">
|
||
<div class="main">
|
||
<div class="search__header">Recherche</div>
|
||
<div class="search-bar">
|
||
<div class="search-box js-search-box">
|
||
<div class="search-box__icon-search"><i class="fas fa-search"></i></div>
|
||
<input id="search-input" type="text" />
|
||
<div class="search-box__icon-clear js-icon-clear">
|
||
<a><i class="fas fa-times"></i></a>
|
||
</div>
|
||
</div>
|
||
<button class="button button--theme-dark button--pill search__cancel js-search-toggle">
|
||
Annuler</button>
|
||
</div>
|
||
<div id="results-container" class="search-result js-search-result"></div>
|
||
</div>
|
||
</div>
|
||
<!-- Script pointing to search-script.js -->
|
||
<script>/*!
|
||
* Simple-Jekyll-Search
|
||
* Copyright 2015-2020, Christian Fei
|
||
* Licensed under the MIT License.
|
||
*/
|
||
|
||
(function(){
|
||
'use strict'
|
||
|
||
var _$Templater_7 = {
|
||
compile: compile,
|
||
setOptions: setOptions
|
||
}
|
||
|
||
const options = {}
|
||
options.pattern = /\{(.*?)\}/g
|
||
options.template = ''
|
||
options.middleware = function () {}
|
||
|
||
function setOptions (_options) {
|
||
options.pattern = _options.pattern || options.pattern
|
||
options.template = _options.template || options.template
|
||
if (typeof _options.middleware === 'function') {
|
||
options.middleware = _options.middleware
|
||
}
|
||
}
|
||
|
||
function compile (data) {
|
||
return options.template.replace(options.pattern, function (match, prop) {
|
||
const value = options.middleware(prop, data[prop], options.template)
|
||
if (typeof value !== 'undefined') {
|
||
return value
|
||
}
|
||
return data[prop] || match
|
||
})
|
||
}
|
||
|
||
'use strict';
|
||
|
||
function fuzzysearch (needle, haystack) {
|
||
var tlen = haystack.length;
|
||
var qlen = needle.length;
|
||
if (qlen > tlen) {
|
||
return false;
|
||
}
|
||
if (qlen === tlen) {
|
||
return needle === haystack;
|
||
}
|
||
outer: for (var i = 0, j = 0; i < qlen; i++) {
|
||
var nch = needle.charCodeAt(i);
|
||
while (j < tlen) {
|
||
if (haystack.charCodeAt(j++) === nch) {
|
||
continue outer;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
var _$fuzzysearch_1 = fuzzysearch;
|
||
|
||
'use strict'
|
||
|
||
/* removed: const _$fuzzysearch_1 = require('fuzzysearch') */;
|
||
|
||
var _$FuzzySearchStrategy_5 = new FuzzySearchStrategy()
|
||
|
||
function FuzzySearchStrategy () {
|
||
this.matches = function (string, crit) {
|
||
return _$fuzzysearch_1(crit.toLowerCase(), string.toLowerCase())
|
||
}
|
||
}
|
||
|
||
'use strict'
|
||
|
||
var _$LiteralSearchStrategy_6 = new LiteralSearchStrategy()
|
||
|
||
function LiteralSearchStrategy () {
|
||
this.matches = function (str, crit) {
|
||
if (!str) return false
|
||
|
||
str = str.trim().toLowerCase()
|
||
crit = crit.trim().toLowerCase()
|
||
|
||
return crit.split(' ').filter(function (word) {
|
||
return str.indexOf(word) >= 0
|
||
}).length === crit.split(' ').length
|
||
}
|
||
}
|
||
|
||
'use strict'
|
||
|
||
var _$Repository_4 = {
|
||
put: put,
|
||
clear: clear,
|
||
search: search,
|
||
setOptions: __setOptions_4
|
||
}
|
||
|
||
/* removed: const _$FuzzySearchStrategy_5 = require('./SearchStrategies/FuzzySearchStrategy') */;
|
||
/* removed: const _$LiteralSearchStrategy_6 = require('./SearchStrategies/LiteralSearchStrategy') */;
|
||
|
||
function NoSort () {
|
||
return 0
|
||
}
|
||
|
||
const data = []
|
||
let opt = {}
|
||
|
||
opt.fuzzy = false
|
||
opt.limit = 10
|
||
opt.searchStrategy = opt.fuzzy ? _$FuzzySearchStrategy_5 : _$LiteralSearchStrategy_6
|
||
opt.sort = NoSort
|
||
opt.exclude = []
|
||
|
||
function put (data) {
|
||
if (isObject(data)) {
|
||
return addObject(data)
|
||
}
|
||
if (isArray(data)) {
|
||
return addArray(data)
|
||
}
|
||
return undefined
|
||
}
|
||
function clear () {
|
||
data.length = 0
|
||
return data
|
||
}
|
||
|
||
function isObject (obj) {
|
||
return Boolean(obj) && Object.prototype.toString.call(obj) === '[object Object]'
|
||
}
|
||
|
||
function isArray (obj) {
|
||
return Boolean(obj) && Object.prototype.toString.call(obj) === '[object Array]'
|
||
}
|
||
|
||
function addObject (_data) {
|
||
data.push(_data)
|
||
return data
|
||
}
|
||
|
||
function addArray (_data) {
|
||
const added = []
|
||
clear()
|
||
for (let i = 0, len = _data.length; i < len; i++) {
|
||
if (isObject(_data[i])) {
|
||
added.push(addObject(_data[i]))
|
||
}
|
||
}
|
||
return added
|
||
}
|
||
|
||
function search (crit) {
|
||
if (!crit) {
|
||
return []
|
||
}
|
||
return findMatches(data, crit, opt.searchStrategy, opt).sort(opt.sort)
|
||
}
|
||
|
||
function __setOptions_4 (_opt) {
|
||
opt = _opt || {}
|
||
|
||
opt.fuzzy = _opt.fuzzy || false
|
||
opt.limit = _opt.limit || 10
|
||
opt.searchStrategy = _opt.fuzzy ? _$FuzzySearchStrategy_5 : _$LiteralSearchStrategy_6
|
||
opt.sort = _opt.sort || NoSort
|
||
opt.exclude = _opt.exclude || []
|
||
}
|
||
|
||
function findMatches (data, crit, strategy, opt) {
|
||
const matches = []
|
||
for (let i = 0; i < data.length && matches.length < opt.limit; i++) {
|
||
const match = findMatchesInObject(data[i], crit, strategy, opt)
|
||
if (match) {
|
||
matches.push(match)
|
||
}
|
||
}
|
||
return matches
|
||
}
|
||
|
||
function findMatchesInObject (obj, crit, strategy, opt) {
|
||
for (const key in obj) {
|
||
if (!isExcluded(obj[key], opt.exclude) && strategy.matches(obj[key], crit)) {
|
||
return obj
|
||
}
|
||
}
|
||
}
|
||
|
||
function isExcluded (term, excludedTerms) {
|
||
for (let i = 0, len = excludedTerms.length; i < len; i++) {
|
||
const excludedTerm = excludedTerms[i]
|
||
if (new RegExp(excludedTerm).test(term)) {
|
||
return true
|
||
}
|
||
}
|
||
return false
|
||
}
|
||
|
||
/* globals ActiveXObject:false */
|
||
|
||
'use strict'
|
||
|
||
var _$JSONLoader_2 = {
|
||
load: load
|
||
}
|
||
|
||
function load (location, callback) {
|
||
const xhr = getXHR()
|
||
xhr.open('GET', location, true)
|
||
xhr.onreadystatechange = createStateChangeListener(xhr, callback)
|
||
xhr.send()
|
||
}
|
||
|
||
function createStateChangeListener (xhr, callback) {
|
||
return function () {
|
||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||
try {
|
||
callback(null, JSON.parse(xhr.responseText))
|
||
} catch (err) {
|
||
callback(err, null)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
function getXHR () {
|
||
return window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP')
|
||
}
|
||
|
||
'use strict'
|
||
|
||
var _$OptionsValidator_3 = function OptionsValidator (params) {
|
||
if (!validateParams(params)) {
|
||
throw new Error('-- OptionsValidator: required options missing')
|
||
}
|
||
|
||
if (!(this instanceof OptionsValidator)) {
|
||
return new OptionsValidator(params)
|
||
}
|
||
|
||
const requiredOptions = params.required
|
||
|
||
this.getRequiredOptions = function () {
|
||
return requiredOptions
|
||
}
|
||
|
||
this.validate = function (parameters) {
|
||
const errors = []
|
||
requiredOptions.forEach(function (requiredOptionName) {
|
||
if (typeof parameters[requiredOptionName] === 'undefined') {
|
||
errors.push(requiredOptionName)
|
||
}
|
||
})
|
||
return errors
|
||
}
|
||
|
||
function validateParams (params) {
|
||
if (!params) {
|
||
return false
|
||
}
|
||
return typeof params.required !== 'undefined' && params.required instanceof Array
|
||
}
|
||
}
|
||
|
||
'use strict'
|
||
|
||
var _$utils_9 = {
|
||
merge: merge,
|
||
isJSON: isJSON
|
||
}
|
||
|
||
function merge (defaultParams, mergeParams) {
|
||
const mergedOptions = {}
|
||
for (const option in defaultParams) {
|
||
mergedOptions[option] = defaultParams[option]
|
||
if (typeof mergeParams[option] !== 'undefined') {
|
||
mergedOptions[option] = mergeParams[option]
|
||
}
|
||
}
|
||
return mergedOptions
|
||
}
|
||
|
||
function isJSON (json) {
|
||
try {
|
||
if (json instanceof Object && JSON.parse(JSON.stringify(json))) {
|
||
return true
|
||
}
|
||
return false
|
||
} catch (err) {
|
||
return false
|
||
}
|
||
}
|
||
|
||
var _$src_8 = {};
|
||
(function (window) {
|
||
'use strict'
|
||
|
||
let options = {
|
||
searchInput: null,
|
||
resultsContainer: null,
|
||
json: [],
|
||
success: Function.prototype,
|
||
searchResultTemplate: '<li><a href="{url}" title="{desc}">{title}</a></li>',
|
||
templateMiddleware: Function.prototype,
|
||
sortMiddleware: function () {
|
||
return 0
|
||
},
|
||
noResultsText: 'No results found',
|
||
limit: 10,
|
||
fuzzy: false,
|
||
debounceTime: null,
|
||
exclude: []
|
||
}
|
||
|
||
let debounceTimerHandle
|
||
const debounce = function (func, delayMillis) {
|
||
if (delayMillis) {
|
||
clearTimeout(debounceTimerHandle)
|
||
debounceTimerHandle = setTimeout(func, delayMillis)
|
||
} else {
|
||
func.call()
|
||
}
|
||
}
|
||
|
||
const requiredOptions = ['searchInput', 'resultsContainer', 'json']
|
||
|
||
/* removed: const _$Templater_7 = require('./Templater') */;
|
||
/* removed: const _$Repository_4 = require('./Repository') */;
|
||
/* removed: const _$JSONLoader_2 = require('./JSONLoader') */;
|
||
const optionsValidator = _$OptionsValidator_3({
|
||
required: requiredOptions
|
||
})
|
||
/* removed: const _$utils_9 = require('./utils') */;
|
||
|
||
window.SimpleJekyllSearch = function (_options) {
|
||
const errors = optionsValidator.validate(_options)
|
||
if (errors.length > 0) {
|
||
throwError('You must specify the following required options: ' + requiredOptions)
|
||
}
|
||
|
||
options = _$utils_9.merge(options, _options)
|
||
|
||
_$Templater_7.setOptions({
|
||
template: options.searchResultTemplate,
|
||
middleware: options.templateMiddleware
|
||
})
|
||
|
||
_$Repository_4.setOptions({
|
||
fuzzy: options.fuzzy,
|
||
limit: options.limit,
|
||
sort: options.sortMiddleware,
|
||
exclude: options.exclude
|
||
})
|
||
|
||
if (_$utils_9.isJSON(options.json)) {
|
||
initWithJSON(options.json)
|
||
} else {
|
||
initWithURL(options.json)
|
||
}
|
||
|
||
const rv = {
|
||
search: search
|
||
}
|
||
|
||
typeof options.success === 'function' && options.success.call(rv)
|
||
return rv
|
||
}
|
||
|
||
function initWithJSON (json) {
|
||
_$Repository_4.put(json)
|
||
registerInput()
|
||
}
|
||
|
||
function initWithURL (url) {
|
||
_$JSONLoader_2.load(url, function (err, json) {
|
||
if (err) {
|
||
throwError('failed to get JSON (' + url + ')')
|
||
}
|
||
initWithJSON(json)
|
||
})
|
||
}
|
||
|
||
function emptyResultsContainer () {
|
||
options.resultsContainer.innerHTML = ''
|
||
}
|
||
|
||
function appendToResultsContainer (text) {
|
||
options.resultsContainer.innerHTML += text
|
||
}
|
||
|
||
function registerInput () {
|
||
options.searchInput.addEventListener('input', function (e) {
|
||
if (isWhitelistedKey(e.which)) {
|
||
emptyResultsContainer()
|
||
debounce(function () { search(e.target.value) }, options.debounceTime)
|
||
}
|
||
})
|
||
}
|
||
|
||
function search (query) {
|
||
if (isValidQuery(query)) {
|
||
emptyResultsContainer()
|
||
render(_$Repository_4.search(query), query)
|
||
}
|
||
}
|
||
|
||
function render (results, query) {
|
||
const len = results.length
|
||
if (len === 0) {
|
||
return appendToResultsContainer(options.noResultsText)
|
||
}
|
||
for (let i = 0; i < len; i++) {
|
||
results[i].query = query
|
||
appendToResultsContainer(_$Templater_7.compile(results[i]))
|
||
}
|
||
}
|
||
|
||
function isValidQuery (query) {
|
||
return query && query.length > 0
|
||
}
|
||
|
||
function isWhitelistedKey (key) {
|
||
return [13, 16, 20, 37, 38, 39, 40, 91].indexOf(key) === -1
|
||
}
|
||
|
||
function throwError (message) {
|
||
throw new Error('SimpleJekyllSearch --- ' + message)
|
||
}
|
||
})(window)
|
||
|
||
}());
|
||
</script>
|
||
|
||
<!-- Configuration -->
|
||
<script>
|
||
SimpleJekyllSearch({
|
||
searchInput: document.getElementById('search-input'),
|
||
resultsContainer: document.getElementById('results-container'),
|
||
noResultsText: '<p>Aucun résultat!</p>',
|
||
json: '/search.json',
|
||
searchResultTemplate: '<li><a href="{url}">{date} {title}</a> (Création {create})</li>'
|
||
})
|
||
</script>
|
||
|
||
</div></div>
|
||
|
||
|
||
<script>(function() {
|
||
var SOURCES = window.TEXT_VARIABLES.sources;
|
||
window.Lazyload.js(SOURCES.jquery, function() {
|
||
function scrollToAnchor(anchor, duration, callback) {
|
||
var $root = this;
|
||
$root.animate({ scrollTop: $(anchor).position().top }, duration, function() {
|
||
window.history.replaceState(null, '', window.location.href.split('#')[0] + anchor);
|
||
callback && callback();
|
||
});
|
||
}
|
||
$.fn.scrollToAnchor = scrollToAnchor;
|
||
});
|
||
})();
|
||
(function() {
|
||
var SOURCES = window.TEXT_VARIABLES.sources;
|
||
window.Lazyload.js(SOURCES.jquery, function() {
|
||
function affix(options) {
|
||
var $root = this, $window = $(window), $scrollTarget, $scroll,
|
||
offsetBottom = 0, scrollTarget = window, scroll = window.document, disabled = false, isOverallScroller = true,
|
||
rootTop, rootLeft, rootHeight, scrollBottom, rootBottomTop,
|
||
hasInit = false, curState;
|
||
|
||
function setOptions(options) {
|
||
var _options = options || {};
|
||
_options.offsetBottom && (offsetBottom = _options.offsetBottom);
|
||
_options.scrollTarget && (scrollTarget = _options.scrollTarget);
|
||
_options.scroll && (scroll = _options.scroll);
|
||
_options.disabled !== undefined && (disabled = _options.disabled);
|
||
$scrollTarget = $(scrollTarget);
|
||
isOverallScroller = window.isOverallScroller($scrollTarget[0]);
|
||
$scroll = $(scroll);
|
||
}
|
||
function preCalc() {
|
||
top();
|
||
rootHeight = $root.outerHeight();
|
||
rootTop = $root.offset().top + (isOverallScroller ? 0 : $scrollTarget.scrollTop());
|
||
rootLeft = $root.offset().left;
|
||
}
|
||
function calc(needPreCalc) {
|
||
needPreCalc && preCalc();
|
||
scrollBottom = $scroll.outerHeight() - offsetBottom - rootHeight;
|
||
rootBottomTop = scrollBottom - rootTop;
|
||
}
|
||
function top() {
|
||
if (curState !== 'top') {
|
||
$root.removeClass('fixed').css({
|
||
left: 0,
|
||
top: 0
|
||
});
|
||
curState = 'top';
|
||
}
|
||
}
|
||
function fixed() {
|
||
if (curState !== 'fixed') {
|
||
$root.addClass('fixed').css({
|
||
left: rootLeft + 'px',
|
||
top: 0
|
||
});
|
||
curState = 'fixed';
|
||
}
|
||
}
|
||
function bottom() {
|
||
if (curState !== 'bottom') {
|
||
$root.removeClass('fixed').css({
|
||
left: 0,
|
||
top: rootBottomTop + 'px'
|
||
});
|
||
curState = 'bottom';
|
||
}
|
||
}
|
||
function setState() {
|
||
var scrollTop = $scrollTarget.scrollTop();
|
||
if (scrollTop >= rootTop && scrollTop <= scrollBottom) {
|
||
fixed();
|
||
} else if (scrollTop < rootTop) {
|
||
top();
|
||
} else {
|
||
bottom();
|
||
}
|
||
}
|
||
function init() {
|
||
if(!hasInit) {
|
||
var interval, timeout;
|
||
calc(true); setState();
|
||
// run calc every 100 millisecond
|
||
interval = setInterval(function() {
|
||
calc();
|
||
}, 100);
|
||
timeout = setTimeout(function() {
|
||
clearInterval(interval);
|
||
}, 45000);
|
||
window.pageLoad.then(function() {
|
||
setTimeout(function() {
|
||
clearInterval(interval);
|
||
clearTimeout(timeout);
|
||
}, 3000);
|
||
});
|
||
$scrollTarget.on('scroll', function() {
|
||
disabled || setState();
|
||
});
|
||
$window.on('resize', function() {
|
||
disabled || (calc(true), setState());
|
||
});
|
||
hasInit = true;
|
||
}
|
||
}
|
||
|
||
setOptions(options);
|
||
if (!disabled) {
|
||
init();
|
||
}
|
||
$window.on('resize', window.throttle(function() {
|
||
init();
|
||
}, 200));
|
||
return {
|
||
setOptions: setOptions,
|
||
refresh: function() {
|
||
calc(true, { animation: false }); setState();
|
||
}
|
||
};
|
||
}
|
||
$.fn.affix = affix;
|
||
});
|
||
})();
|
||
(function() {
|
||
var SOURCES = window.TEXT_VARIABLES.sources;
|
||
window.Lazyload.js(SOURCES.jquery, function() {
|
||
function toc(options) {
|
||
var $root = this, $window = $(window), $scrollTarget, $scroller, $tocUl = $('<ul class="toc toc--ellipsis"></ul>'), $tocLi, $headings, $activeLast, $activeCur,
|
||
selectors = 'h1,h2,h3', container = 'body', scrollTarget = window, scroller = 'html, body', disabled = false,
|
||
headingsPos, scrolling = false, hasRendered = false, hasInit = false;
|
||
|
||
function setOptions(options) {
|
||
var _options = options || {};
|
||
_options.selectors && (selectors = _options.selectors);
|
||
_options.container && (container = _options.container);
|
||
_options.scrollTarget && (scrollTarget = _options.scrollTarget);
|
||
_options.scroller && (scroller = _options.scroller);
|
||
_options.disabled !== undefined && (disabled = _options.disabled);
|
||
$headings = $(container).find(selectors).filter('[id]');
|
||
$scrollTarget = $(scrollTarget);
|
||
$scroller = $(scroller);
|
||
}
|
||
function calc() {
|
||
headingsPos = [];
|
||
$headings.each(function() {
|
||
headingsPos.push(Math.floor($(this).position().top));
|
||
});
|
||
}
|
||
function setState(element, disabled) {
|
||
var scrollTop = $scrollTarget.scrollTop(), i;
|
||
if (disabled || !headingsPos || headingsPos.length < 1) { return; }
|
||
if (element) {
|
||
$activeCur = element;
|
||
} else {
|
||
for (i = 0; i < headingsPos.length; i++) {
|
||
if (scrollTop >= headingsPos[i]) {
|
||
$activeCur = $tocLi.eq(i);
|
||
} else {
|
||
$activeCur || ($activeCur = $tocLi.eq(i));
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
$activeLast && $activeLast.removeClass('active');
|
||
($activeLast = $activeCur).addClass('active');
|
||
}
|
||
function render() {
|
||
if(!hasRendered) {
|
||
$root.append($tocUl);
|
||
$headings.each(function() {
|
||
var $this = $(this);
|
||
$tocUl.append($('<li></li>').addClass('toc-' + $this.prop('tagName').toLowerCase())
|
||
.append($('<a></a>').text($this.text()).attr('href', '#' + $this.prop('id'))));
|
||
});
|
||
$tocLi = $tocUl.children('li');
|
||
$tocUl.on('click', 'a', function(e) {
|
||
e.preventDefault();
|
||
var $this = $(this);
|
||
scrolling = true;
|
||
setState($this.parent());
|
||
$scroller.scrollToAnchor($this.attr('href'), 400, function() {
|
||
scrolling = false;
|
||
});
|
||
});
|
||
}
|
||
hasRendered = true;
|
||
}
|
||
function init() {
|
||
var interval, timeout;
|
||
if(!hasInit) {
|
||
render(); calc(); setState(null, scrolling);
|
||
// run calc every 100 millisecond
|
||
interval = setInterval(function() {
|
||
calc();
|
||
}, 100);
|
||
timeout = setTimeout(function() {
|
||
clearInterval(interval);
|
||
}, 45000);
|
||
window.pageLoad.then(function() {
|
||
setTimeout(function() {
|
||
clearInterval(interval);
|
||
clearTimeout(timeout);
|
||
}, 3000);
|
||
});
|
||
$scrollTarget.on('scroll', function() {
|
||
disabled || setState(null, scrolling);
|
||
});
|
||
$window.on('resize', window.throttle(function() {
|
||
if (!disabled) {
|
||
render(); calc(); setState(null, scrolling);
|
||
}
|
||
}, 100));
|
||
}
|
||
hasInit = true;
|
||
}
|
||
|
||
setOptions(options);
|
||
if (!disabled) {
|
||
init();
|
||
}
|
||
$window.on('resize', window.throttle(function() {
|
||
init();
|
||
}, 200));
|
||
return {
|
||
setOptions: setOptions
|
||
};
|
||
}
|
||
$.fn.toc = toc;
|
||
});
|
||
})();
|
||
/*(function () {
|
||
|
||
})();*/
|
||
</script><script>
|
||
/* toc must before affix, since affix need to konw toc' height. */(function() {
|
||
var SOURCES = window.TEXT_VARIABLES.sources;
|
||
var TOC_SELECTOR = window.TEXT_VARIABLES.site.toc.selectors;
|
||
window.Lazyload.js(SOURCES.jquery, function() {
|
||
var $window = $(window);
|
||
var $articleContent = $('.js-article-content');
|
||
var $tocRoot = $('.js-toc-root'), $col2 = $('.js-col-aside');
|
||
var toc;
|
||
var tocDisabled = false;
|
||
var hasSidebar = $('.js-page-root').hasClass('layout--page--sidebar');
|
||
var hasToc = $articleContent.find(TOC_SELECTOR).length > 0;
|
||
|
||
function disabled() {
|
||
return $col2.css('display') === 'none' || !hasToc;
|
||
}
|
||
|
||
tocDisabled = disabled();
|
||
|
||
toc = $tocRoot.toc({
|
||
selectors: TOC_SELECTOR,
|
||
container: $articleContent,
|
||
scrollTarget: hasSidebar ? '.js-page-main' : null,
|
||
scroller: hasSidebar ? '.js-page-main' : null,
|
||
disabled: tocDisabled
|
||
});
|
||
|
||
$window.on('resize', window.throttle(function() {
|
||
tocDisabled = disabled();
|
||
toc && toc.setOptions({
|
||
disabled: tocDisabled
|
||
});
|
||
}, 100));
|
||
|
||
});
|
||
})();
|
||
(function() {
|
||
var SOURCES = window.TEXT_VARIABLES.sources;
|
||
window.Lazyload.js(SOURCES.jquery, function() {
|
||
var $window = $(window), $pageFooter = $('.js-page-footer');
|
||
var $pageAside = $('.js-page-aside');
|
||
var affix;
|
||
var tocDisabled = false;
|
||
var hasSidebar = $('.js-page-root').hasClass('layout--page--sidebar');
|
||
|
||
affix = $pageAside.affix({
|
||
offsetBottom: $pageFooter.outerHeight(),
|
||
scrollTarget: hasSidebar ? '.js-page-main' : null,
|
||
scroller: hasSidebar ? '.js-page-main' : null,
|
||
scroll: hasSidebar ? $('.js-page-main').children() : null,
|
||
disabled: tocDisabled
|
||
});
|
||
|
||
$window.on('resize', window.throttle(function() {
|
||
affix && affix.setOptions({
|
||
disabled: tocDisabled
|
||
});
|
||
}, 100));
|
||
|
||
window.pageAsideAffix = affix;
|
||
});
|
||
})();
|
||
</script><!---->
|
||
|
||
</div>
|
||
<script>(function () {
|
||
var $root = document.getElementsByClassName('root')[0];
|
||
if (window.hasEvent('touchstart')) {
|
||
$root.dataset.isTouch = true;
|
||
document.addEventListener('touchstart', function(){}, false);
|
||
}
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|
||
|