-
Notifications
You must be signed in to change notification settings - Fork 874
/
Copy pathemmylua_ngx.lua
2608 lines (2451 loc) · 126 KB
/
emmylua_ngx.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[=[
openresty函数提示专用库,不实现功能,仅仅用来做方法提示使用
by:xuzz 20181112
]=]
---@class err @错误信息定义,可为string或者nil
local err = ""
---在5.2中,setfenv遭到了废弃,因为引入了_ENV。 通过在函数定义前覆盖_ENV变量即可为函数定义设置一个全新的环境,比如:
---a = 3
---function echo()
--- local _ENV={print=print, a = 2}
--- function _echo() _ENV.print(a) end
--- return _echo;
---end
---print(a) -> 3
---local newEcho = echo()
---print(newEcho) -> function: 0x7fd1b94065c0
---newEcho() -> 2
_ENV = {}
---设置一个函数的环境
---(1)当第一个参数为一个函数时,表示设置该函数的环境
---(2)当第一个参数为一个数字时,为1代表当前函数,2代表调用自己的函数,3代表调用自己的函数的函数,以此类推
function setfenv(f,table)
end
---功能:与load类似,但装载的内容是一个字串
--如:assert(loadstring(s))()
---@param string string @可选参数
---@return fun() @返回string编译后的方法
function loadstring (string,chunkname)
end
---功能:返回指定表的索引的值,i为起始索引,j为结束索引
---注:本函数只能用于以数字索引访问的表,否则只会返回nil 如:t={"1","cash"}
---@param list table[]
function unpack (list,i,j)
end
---循环table,table不必是数字索引
---table.foreach(table, function(i, v) end)
---
---@param tb1 table @需循环的数据
---@param func fun(k:any,v:any):void @处理每个键值的函数
function table.foreach(tb1,func)
end
---循环table,table必须是数字索引
---table.foreach(table, function(i, v) end)
---
---@param tb1 table @需循环的数据
---@param func fun(k:any,v:any):void @处理每个键值的函数
function table.foreachi(tb1,func)
end
---给 lua table 预分配空间。否则 table
---会在插入新元素时自增长,而自增长是高代价操作( 因为需要重新分配空间、重新 hash,以及拷贝数据)
---narr,nrec两个参数分别代表table里是array还是hash的
---table.new(10, 0) 或者 table.new(0, 10) 这样的,后者是 hash 性质的 table
---@param narr number @预分配多少数组型空间
---@param nrec number @预分配多少hash型空间
function table.new(narr,nrec)
end
---清理一个lua table
---@param tb table @需要清理的table
function table.clear(tb)
end
---@class ngx.pipe.proc @pipe产生的子进程定义
local proc = {}
---获得子进程id
---pid = proc:pid()
function proc:pid()
end
---设置超时时间
---默认10000毫秒
function proc:set_timeouts(write_timeout,stdout_read_timeout,stderr_read_timeout,wait_timeout)
end
---@class reason @pipe退出原因定义,一个字符串,可选值 exit/signal
local reason = "exit" or "signal"
---等待直到当前子进程退出。
---ok, reason, status = proc:wait()
---ok,如果进程退出码为0,则为true
---reason可能值有:
--- exit进程主动退出而结束,status为退出码
--- signal接收了信号而退出 ,status为信号码
---@return boolean,reason,number
function proc:wait()
end
---结束子进程
---ok, err = proc:shutdown(direction)
---'direction'参数应该是以下三个值之一:'stdin`、'stdout`和'stderr`。
function proc:shutdown(direction)
end
---写入内容到输入流
---nbytes, err = proc:write(data)
---@param data string|table @写入的内容,可以是字符串也可以是数组
---@return number,string @写入成功的字节数,第二个为错误信息
function proc:write(data)
end
---从当前子进程的stderr流中读取所有数据,直到其关闭。
---data, err, partial = proc:stderr_read_all()
---这个方法是一个同步的、非阻塞的操作,就像[写](写)方法一样。
---此读取操作的超时阈值可以由[set_timeouts]控制。默认超时为10秒。
---如果成功,它将返回接收到的数据。否则,它返回三个值:“nil”,一个描述错误的字符串,以及迄今为止接收到的部分数据(可选)。
---当在[spawn](spawn)中指定了“merge_stderr”时,调用“stderr_read_all”将返回“nil”,错误字符串“merged to stdout”`。
---一次只允许从子进程的stderr或stdout流读取一个轻线程。如果另一个线程试图从同一个流中读取,此方法将返回“nil”和错误字符串“pipe busy reading”。
---stdout和stderr的流是分开的,因此一次最多可以从子进程读取两个轻线程(每个流一个)。
---同样,当另一个轻线程正在写入子进程stdin流时,轻线程可以从流中读取
---Reading from an exited process's stream will return `nil` and the error string
--`"closed"`.
function proc:stderr_read_all()
end
---读取全部子进程输出流
---data, err, partial = proc:stdout_read_all()
function proc:stdout_read_all()
end
---读取一行错误输出流
---data, err, partial = proc:stderr_read_line()
---该行应以“换行符”(lf)字符(ascii 10)结尾,可选前面加上“回车符”(cr)字符(ascii 13)。CR和LF字符不包括在返回的行数据中。
function proc:stderr_read_line()
end
---读取一行输出流
---data, err, partial = proc:stdout_read_line()
function proc:stdout_read_line()
end
---读取指定数量的错误输出流
---data, err, partial = proc:stderr_read_bytes(len)
---如果数据流被截断(可用数据的字节数少于请求的字节数),则此方法返回3个值:“nil”、错误字符串“closed”和迄今为止接收到的部分数据字符串。
function proc:stderr_read_bytes(len)
end
---读取指定数量的输出流
---data, err, partial = proc:stdout_read_bytes(len)
function proc:stdout_read_bytes(len)
end
---读取错误输出流,读取到指定数量就返回
---data, err = proc:stderr_read_any(max)
---最多接收'max'个字节。
---如果接收到的数据超过了'max'字节,则此方法将返回完全为'max'字节的数据。底层接收缓冲区中的剩余数据可以通过后续的读取操作获取。
function proc:stderr_read_any(max)
end
---读取输出流,读取到指定数量就返回
--data, err = proc:stdout_read_any(max)
function proc:stdout_read_any(max)
end
---@class ngx
ngx = {}
ngx.thread = {}
---语法: co = ngx.thread.spawn(func, arg1, arg2, ...)
---
---环境: rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*
---
---使用 Lua 函数 func 以及其他可选参数 arg1、arg2 等, 产生一个新的用户 "轻线程" 。 返回一个 Lua 线程(或者说是 Lua 协程)对象,这里称之为“轻线程”。
---ngx.thread.spawn 返回后,新创建的“轻线程”将开始异步方式在各个 I/O 事件上执行。
---
---在 rewrite_by_lua、access_by_lua 中的 Lua 代码块是在 ngx_lua 自动创建的“轻线程”样板执行的。这类样板的“轻线程”也被称为“入口线程”。
function ngx.thread.spawn(func,arg1,arg2,...)
end
---语法: ok, res1, res2, ... = ngx.thread.wait(thread1, thread2, ...)
---
---环境: rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*
---
---等待一个或多个子“轻线程”,并等待第一个终止(无论成功或有错误)“轻线程”的返回结果。
---
---参数 thread1、thread2 等都是之前调用 ngx.thread.spawn 返回的 Lua 线程对象。
---
---返回值与 coroutine.resume 是完全一样的,也就是说,第一个返回值是一个布尔值,说明“轻线程”的终止是成功还是异常,随后的返回值是 Lua 函数的返回结果,该 Lua 函数是被用来产生“轻线程”(成功情况下)或错误对象(失败情况下)。
---
---只有直属“父协程”才能等待它的子“轻线程”,否则将会有 Lua 异常抛出。
function ngx.thread.wait(thread1,thread2,...)
end
---语法: ok, err = ngx.thread.kill(thread)
---
---环境: rewrite_by_lua, access_by_lua*, content_by_lua*, ngx.timer.**
---
---杀死一个正在运行的轻线程(通过 ngx.thread.spawn 创建)。成功时返回一个 true ,其他情况则返回一个错误字符描述信息。
---
---根据目前的实现,只有父协程(或“轻线程”)可以终止一个“线程”。同样,正在挂起运行 Nginx 子请求(例如调用 ngx.location.capture)的“轻线程”,是不能被杀死的,这要归咎于 Nginx 内核限制。
function ngx.thread.kill(thread)
end
---环境: init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*,
---header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*
---这个 Lua 表可以用来存储基于请求的 Lua 环境数据,其生存周期与当前请求相同 (类似 Nginx 变量)。
---参考下面例子,
--- location /test {
--- rewrite_by_lua_block {
--- ngx.ctx.foo = 76
--- }
--- access_by_lua_block {
--- ngx.ctx.foo = ngx.ctx.foo + 3
--- }
--- content_by_lua_block {
--- ngx.say(ngx.ctx.foo)
--- }
--- }
---访问 GET /test 输出
--- 79
---内部重定向将摧毁原始请求中的 ngx.ctx 数据 (如果有),新请求将会有一个空白的 ngx.ctx 表。例如,
---
--- location /new {
--- content_by_lua_block {
--- ngx.say(ngx.ctx.foo)
--- }
--- }
---
--- location /orig {
--- content_by_lua_block {
--- ngx.ctx.foo = "hello"
--- ngx.exec("/new")
--- }
--- }
---访问 GET /orig 将输出
---
--- nil
---任意数据值,包括 Lua 闭包与嵌套表,都可以被插入这个“魔法”表,也允许注册自定义元方法。
---也可以将 ngx.ctx 覆盖为一个新 Lua 表,例如,
ngx.ctx = {}
ngx.HTTP_OK = 200
ngx.HTTP_CREATED = 201
ngx.HTTP_SPECIAL_RESPONSE = 300
ngx.HTTP_MOVED_PERMANENTLY = 301
ngx.HTTP_MOVED_TEMPORARILY = 302
ngx.HTTP_SEE_OTHER = 303
ngx.HTTP_NOT_MODIFIED = 304
ngx.HTTP_BAD_REQUEST = 400
ngx.HTTP_UNAUTHORIZED = 401
ngx.HTTP_FORBIDDEN = 403
ngx.HTTP_NOT_FOUND = 404
ngx.HTTP_NOT_ALLOWED = 405
ngx.HTTP_GONE = 410
ngx.HTTP_INTERNAL_SERVER_ERROR = 500
ngx.HTTP_METHOD_NOT_IMPLEMENTED = 501
ngx.HTTP_SERVICE_UNAVAILABLE = 503
ngx.HTTP_GATEWAY_TIMEOUT = 504
---ngx.status
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*
---读写当前请求的响应状态码。这个方法需要在发送响应头前调用。
--- ngx.status = ngx.HTTP_CREATED
--- status = ngx.status
---在发送响应头之后设置 ngx.status 不会生效,且 nginx 的错误日志中会有下面一条记录:
---attempt to set ngx.status after sending out response headers
--[[
自定义错误内容页面的返回
syntax: ngx.status = ngx.HTTP_GONE
ngx.say("This is our own content")
ngx.exit(ngx.HTTP_OK)
]]
---@type number @读写当前请求的响应状态码。这个方法需要在发送响应头前调用。
ngx.status = 200
---语法: ngx.header.HEADER = VALUE
---语法: value = ngx.header.HEADER
---环境: rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*
---修改、添加、或清除当前请求待发送的 HEADER 响应头信息。
---头名称中的下划线 (_) 将被默认替换为连字符 (-)。可以通过 lua_transform_underscores_in_response_headers 指令关闭这个替换。
---多值头信息可以按以下方法设置:
---
--- ngx.header['Set-Cookie'] = {'a=32; path=/', 'b=4; path=/'}
---在响应头中将输出:
---
--- Set-Cookie: a=32; path=/
--- Set-Cookie: b=4; path=/
---将一个头信息的值设为 nil 将从响应头中移除该输出
---ngx.header["X-My-Header"] = nil;
ngx.header = {}
---设置响应文件类型
ngx.header["Content-Type"] = 'text/html'
ngx.header.content_type = 'text/plain'
---设置一个客户端cookie
ngx.header['Set-Cookie'] = { 'a=32; path=/','b=4; path=/' }
ngx.resp = {}
---语法: headers = ngx.resp.get_headers(max_headers?, raw?)
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, balancer_by_lua*
---
---返回一个 Lua 表,包含当前请求的所有响应头信息。
---
--- local h = ngx.resp.get_headers()
--- for k, v in pairs(h) do
--- ...
--- end
---此函数与 ngx.req.get_headers 有相似之处,唯一区别是获取的是响应头信息而不是请求头信息。
---@return table<string,string>
function ngx.resp.get_headers(max_headers,raw)
end
ngx.req = {}
---语法: is_internal = ngx.req.is_internal()
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*
---
---返回一个布尔值,说明当前请求是否是一个“内部请求”,既:一个请求的初始化是在当前 nginx 服务端完成初始化,不是在客户端。
---
---子请求都是内部请求,并且都是内部重定向后的请求。
function ngx.req.is_internal()
end
---语法: secs = ngx.req.start_time()
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*
---
---返回当前请求创建时的时间戳,格式为浮点数,其中小数部分代表毫秒值。
---
---以下用 Lua 代码模拟计算了 $request_time 变量值 (由 ngx_http_log_module 模块生成)
---
--- local request_time = ngx.now() - ngx.req.start_time()
function ngx.req.start_time()
end
---语法: num = ngx.req.http_version()
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*
---
---返回一个 Lua 数字代表当前请求的 HTTP 版本号。
---
---当前的可能结果值为 2.0, 1.0, 1.1 和 0.9。无法识别时值时返回 nil。
function ngx.req.http_version()
end
---语法: str = ngx.req.raw_header(no_request_line?)
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*
---
---返回 Nginx 服务器接收到的原始 HTTP 协议头。
---
---默认时,请求行和末尾的 CR LF 结束符也被包括在内。例如,
---
--- ngx.print(ngx.req.raw_header())
---输出结果类似:
---
---GET /t HTTP/1.1
---Host: localhost
---Connection: close
---Foo: bar
---可以通过指定可选的 no_request_line 参数为 true 来去除结果中的请求行。例如,
---
--- ngx.print(ngx.req.raw_header(true))
---输出结果类似:
---
---Host: localhost
---Connection: close
---Foo: bar
---@param no_request_line boolean
---@return string
function ngx.req.raw_header(no_request_line)
end
---语法: method_name = ngx.req.get_method()
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, balancer_by_lua*
---
---获取当前请求的 HTTP 请求方法名称。结果为类似 "GET" 和 "POST" 的字符串,而不是 HTTP 方法常量 中定义的数值。
---
---如果当前请求为 Nginx 子请求,将返回子请求的 HTTP 请求方法名称。
---
---这个方法在 v0.5.6 版本中首次引入。
---
---更多用法请参考 ngx.req.set_method。
function ngx.req.get_method()
end
ngx.HTTP_GET = 1
ngx.HTTP_HEAD = 2
ngx.HTTP_PUT = 2
ngx.HTTP_POST = 2
ngx.HTTP_DELETE = 2
ngx.HTTP_OPTIONS = 2
ngx.HTTP_MKCOL = 2
ngx.HTTP_COPY = 2
ngx.HTTP_MOVE = 2
ngx.HTTP_PROPFIND = 2
ngx.HTTP_PROPPATCH = 2
ngx.HTTP_LOCK = 2
ngx.HTTP_UNLOCK = 2
ngx.HTTP_PATCH = 2
ngx.HTTP_TRACE = 2
---语法: ngx.req.set_method(method_id)
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*
---用 method_id 参数的值改写当前请求的 HTTP 请求方法。当前仅支持 HTTP 请求方法 中定义的数值常量,例如 ngx.HTTP_POST 和 ngx.HTTP_GET。
---如果当前请求是 Nginx 子请求,子请求的 HTTP 请求方法将被改写。
---这个方法在 v0.5.6 版本中首次引入。
---更多用法请参考 ngx.req.get_method。
function ngx.req.set_method(method_id)
end
---语法: ngx.req.set_uri(uri, jump?)
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*
---用 uri 参数重写当前请求 (已解析过的) URI。该 uri 参数必须是 Lua 字符串,并且长度不能是 0,否则将抛出 Lua 异常。
---可选的布尔值参数 jump 会触发类似 ngx_http_rewrite_module 中 rewrite 指令的 location 重匹配 (或 location 跳转)。
---换句话说,当 jump 参数是 true (默认值 false) 时,此函数将不会返回,它会让 Nginx 在之后的 post-rewrite 执行阶段,
---根据新的 URI 重新搜索 location,并跳转到新 location。
---默认值时,location 跳转不会被触发,只有当前请求的 URI 被改写。当 jump 参数值为 false 或不存在时,此函数将正常返回,但没有返回值。
function ngx.req.set_uri(uri,jump)
end
---语法: ngx.req.set_uri_args(args)
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*
---
---用 args 参数重写当前请求的 URI 请求参数。args 参数可以是一个 Lua 字符串,比如
---
--- ngx.req.set_uri_args("a=3&b=hello%20world")
---或一个包含请求参数 key-value 对的 Lua table,例如
---
--- ngx.req.set_uri_args({ a = 3, b = "hello world" })
---在第二种情况下,本方法将根据 URI 转义规则转义参数的 key 和 value。
---
---本方法也支持多值参数:
---
--- ngx.req.set_uri_args({ a = 3, b = {5, 6} })
---此时请求参数字符串为 a=3&b=5&b=6。
function ngx.req.set_uri_args(args)
end
---语法: args = ngx.req.get_uri_args(max_args?)
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*
---
---返回一个 Lua table,包含当前请求的所有 URL 查询参数。
---
--- location = /test {
--- content_by_lua_block {
--- local args = ngx.req.get_uri_args()
--- for key, val in pairs(args) do
--- if type(val) == "table" then
--- ngx.say(key, ": ", table.concat(val, ", "))
--- else
--- ngx.say(key, ": ", val)
--- end
--- end
--- }
--- }
---访问 GET /test?foo=bar&bar=baz&bar=blah 将输出:
---
--- foo: bar
--- bar: baz, blah
---@return table<string,string>
function ngx.req.get_uri_args(max_args)
end
---语法: args, err = ngx.req.get_post_args(max_args?)
---
---环境: rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*
---
---返回一个 Lua table,包含当前请求的所有 POST 查询参数 (MIME type 是 application/x-www-form-urlencoded)。
---使用前需要调 用 ngx.req.read_body 读取完整请求体,或通过设置 lua_need_request_body 指令为 on 以避免报错。
---请求
--- $ curl ---data 'foo=bar&bar=baz&bar=blah' localhost/test
---将输出:
--- foo: bar
--- bar: baz, blah
---@param max_args number|void
---@return table<string,string>
function ngx.req.get_post_args(max_args)
end
---语法: headers = ngx.req.get_headers(max_headers?, raw?)
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*
---返回一个 Lua table,包含当前请求的所有请求头信息。
---请注意,ngx.var.HEADER API 使用 nginx 内核 $http_HEADER 变量,在读取单个请求头信息时更加适用。
---@return table<string,string>
function ngx.req.get_headers(max_headers,raw)
end
---语法: ngx.req.set_header(header_name, header_value)
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*
---将当前请求的名为 header_name 的头信息值设置为 header_value,如果此头信息名称已经存在,修改其值。
---默认时,之后通过 ngx.location.capture 和 ngx.location.capture_multi 发起的所有子请求都将继承新的头信息。
---下面的例子中将设置 Content-Type 头信息:
--- ngx.req.set_header("Content-Type", "text/css")
---header_value 可以是一个值数组,例如:
--- ngx.req.set_header("Foo", {"a", "abc"})
---将生成两个新的请求头信息:
--- Foo: a
--- Foo: abc
function ngx.req.set_header(header_name,header_value)
end
---语法: ngx.req.read_body()
---
---环境: rewrite_by_lua*, access_by_lua*, content_by_lua*
---
---同步读取客户端请求体,不阻塞 Nginx 事件循环。
---
--- ngx.req.read_body()
--- local args = ngx.req.get_post_args()
---如果已经通过打开 lua_need_request_body 选项或其他模块读取请求体,此函数将不会执行,立即返回。
---
---如果已经通过 ngx.req.discard_body 函数或其他模块明确丢弃请求体,此函数将不会执行,立即返回。
---
---当出错时,例如读取数据时连接出错,此方法将立即抛出 Lua 异常 或 以 500 状态码中断当前请求。
---
---通过此函数读取的请求体,之后可以通过 ngx.req.get_body_data 获得,或者,通过 ngx.req.get_body_file
---得到请求体数据缓存在磁盘上的临时文件名。这取决于:
---
---是否当前读求体已经大于 client_body_buffer_size,
---是否 client_body_in_file_only 选项被打开。
---在当前请求中包含请求体,但不需要时,必须使用 ngx.req.discard_body 明确丢弃请求体,以避免影响 HTTP 1.1 长连接或 HTTP 1.1 流水线 (pipelining)。
function ngx.req.read_body()
end
---语法: data = ngx.req.get_body_data()
---
---环境: rewrite_by_lua*, access_by_lua*, content_by_lua*, log_by_lua*
---
---取回内存中的请求体数据。本函数返回 Lua 字符串而不是包含解析过参数的 Lua table。如果想要返回 Lua table,请使用 ngx.req.get_post_args 函数。
---
---当以下情况时,此函数返回 nil,
---
---请求体尚未被读取,
---请求体已经被存入磁盘上的临时文件,
---或请求体大小是 0。
---如果请求体尚未被读取,请先调用 ngx.req.read_body (或打开 lua_need_request_body 选项强制本模块读取请求体,此方法不推荐)。
---
---如果请求体已经被存入临时文件,请使用 ngx.req.get_body_file 函数代替。
---
---如需要强制在内存中保存请求体,请设置 client_body_buffer_size 和 client_max_body_size 为同样大小。
---
---请注意,调用此函数比使用 ngx.var.request_body 或 ngx.var.echo_request_body 更有效率,因为本函数能够节省一次内存分配与数据复制。
---
---这个函数在 v0.3.1rc17 版本中首次引入。
---
---更多用法请参考 ngx.req.get_body_file。
---@return string @请求的body字符串
function ngx.req.get_body_data()
end
---语法: file_name = ngx.req.get_body_file()
---
---环境: rewrite_by_lua*, access_by_lua*, content_by_lua*
---
---获取存储请求体数据的临时文件名。如果请求体尚未被读取或已被读取到内存中,此函数将返回 nil。
---
---本函数返回的文件是只读的,通常情况下会被 Nginx 的内存池清理机制清理。不应该手工修改、更名或删除这个文件。
---
---如果请求体尚未被读取,请先调用 ngx.req.read_body (或打开 lua_need_request_body 选项强制本模块读取请求体。此方法不推荐)。
---
---如果请求体已经被读入内存,请使用 ngx.req.get_body_data 函数代替。
---
---如需要强制在临时文件中保存请求体,请打开 client_body_in_file_only 选项。
---
---这个函数在 v0.3.1rc17 版本中首次引入。
---
---更多用法请参考 ngx.req.get_body_data。
function ngx.req.get_body_file()
end
---语法: ngx.req.set_body_data(data)
---
---环境: rewrite_by_lua*, access_by_lua*, content_by_lua*
---
---使用 data 参数指定的内存数据设置当前请求的请求体。
---
---如果当前请求的请求体尚未被读取,它将被安全地丢弃。当请求体已经被读进内存或缓存在磁盘文件中时,相应的内存或磁盘文件将被立即清理回收。
---
---这个函数在 v0.3.1rc18 版本中首次引入。
---
---更多用法请参考 ngx.req.set_body_file。
function ngx.req.set_body_data(data)
end
---语法: ngx.req.set_body_file(file_name, auto_clean?)
---
---环境: rewrite_by_lua*, access_by_lua*, content_by_lua*
---
---使用 file_name 参数指定的数据文件设置当前请求的请求体。
---
---当可选参数 auto_clean 设置为 true 时,在本次请求完成,或本次请求内再次调用本函数或 ngx.req.set_body_data 时,
---file_name 文件将被删除。auto_clean 默认值是 false。
---
---请确保 file_name 参数指定的文件存在,并设置合适的操作权限对 Nginx worker 可读,以避免抛出 Lua 异常。
---
---如果当前请求的请求体尚未被读取,它将被安全地丢弃。当请求体已经被读进内存或缓存在磁盘文件中时,相应的内存或磁盘文件将被立即清理回收。
---
---这个函数在 v0.3.1rc18 版本中首次引入。
---
---更多用法请参考 ngx.req.set_body_data。
function ngx.req.set_body_file(file_name,auto_clean)
end
---语法: ngx.exec(uri, args?)
---
---环境: rewrite_by_lua, access_by_lua*, content_by_lua**
---
---使用 uri、args 参数执行一个内部跳转,与 echo-nginx-module 的 echo_exec 指令有些相似。
---
--- ngx.exec('/some-location');
--- ngx.exec('/some-location', 'a=3&b=5&c=6');
--- ngx.exec('/some-location?a=3&b=5', 'c=6');
---可选第二个参数 args 可被用来指名额外的 URI 查询参数,例如:
---
--- ngx.exec("/foo", "a=3&b=hello%20world")
---另外,对于 args 参数可使用一个 Lua 表,内部通过 ngx_lua 完成 URI 转义和字符串的连接。
---
--- ngx.exec("/foo", { a = 3, b = "hello world" })
---该结果和上一个示例是一样的。
function ngx.exec(uri,args)
end
---语法: ngx.redirect(uri, status?)
---
---环境: rewrite_by_lua*, access_by_lua*, content_by_lua*
---
---发出一个 HTTP 301 或 302 重定向到 uri。
---
---可选项 status 参数指定使用什么 HTTP 状态码。目前支持下面几个状态码:
---
---301
---302 (默认)
---303
---307
---默认使用 302 (ngx.HTTP_MOVED_TEMPORARILY)。
---
---假设当前服务名是 localhost 并且监听端口是 1984,这里有个例子:
function ngx.redirect(uri,status)
end
---语法: ok, err = ngx.print(...)
---环境: rewrite_by_lua*, access_by_lua*, content_by_lua*
---将输入参数合并发送给 HTTP 客户端 (作为 HTTP 响应体)。如果此时还没有发送响应头信息,本函数将先发送 HTTP 响应头,再输出响应体。
---自版本 v0.8.3 起,本函数当成功时返回 1,失败时返回 nil 以及一个描述错误的字符串。
---Lua 的 nil 值输出 "nil" 字符串,Lua 的布尔值输出 "true" 或 "false" 字符串。
---
---输入允许字符串嵌套数组,数组中所有元素相按顺序输出。
---
--- local table = {
--- "hello, ",
--- {"world: ", true, " or ", false,
--- {": ", nil}}
--- }
--- ngx.print(table)
---将输出
---
--- hello, world: true or false: nil
---非数组表(哈希表)参数将导致抛出 Lua 异常。
---
---ngx.null 常量输出为 "null" 字符串。
---
---本函数为异步调用,将立即返回,不会等待所有数据被写入系统发送缓冲区。要以同步模式运行,请在调用 ngx.print
---之后调用 ngx.flush(true)。这种方式在流式输出时非常有用。更多细节请参考 ngx.flush。
---
---请注意,ngx.print 和 ngx.say 都会调用 Nginx body 输出过滤器,这种操作非常“昂贵”。所以,在“热”循环中使用这两个函数要非常小心;
---可以通过 Lua 进行缓存以节约调用。
---@return boolean,string @ok,err
function ngx.print(...)
end
---语法: ok, err = ngx.say(...)
---
---环境: rewrite_by_lua*, access_by_lua*, content_by_lua*
---
---与 ngx.print 相同,同时末尾添加一个回车符。
function ngx.say(...)
end
---日志类型
ngx.STDERR = 1
ngx.EMERG = 2
ngx.ALERT = 3
ngx.CRIT = 4
ngx.ERR = 5
ngx.WARN = 6
ngx.NOTICE = 7
ngx.INFO = 8
ngx.DEBUG = 9
---语法: ngx.log(log_level, ...)
---环境: init_by_lua*, init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---将参数拼接起来,按照设定的日志级别记入 error.log。
---Lua nil 参数将输出 "nil" 字符串;Lua 布尔参数将输出 "true" 或 "false" 字符串;ngx.null 常量将输出 "null" 字符串。
---log_level 参数可以使用类似 ngx.ERR 和 ngx.WARN 的常量。更多信息请参考 Nginx log level constants。
---在 Nginx 内核中硬编码限制了单条错误信息最长为 2048 字节。这个长度包含了最后的换行符和开始的时间戳。
---如果信息长度超过这个限制,Nginx 将把信息文本截断。这个限制可以通过修改 Nginx 源码中 src/core/ngx_log.h 文件中的 NGX_MAX_ERROR_STR 宏定义调整。
function ngx.log(log_level,...)
end
---语法: ok, err = ngx.flush(wait?)
---
---环境: rewrite_by_lua*, access_by_lua*, content_by_lua*
---
---向客户端刷新响应输出。
---
---自 v0.3.1rc34 版本开始,ngx.flush 接受一个布尔型可选参数 wait (默认值 false)。当通过默认参数调用时,本函数发起一个异步调用
---(将直接返回,不等待输出数据被写入系统发送缓冲区)。当把 wait 参数设置为 true 时,本函数将以同步模式执行。
---
---在同步模式下,本函数不会立即返回,一直到所有输出数据被写入系统输出缓冲区,或者到达发送超时 send_timeout 时间。请注意,
---因为使用了 Lua 协程机制,本函数即使在同步模式下也不会阻塞 Nginx 事件循环。
---
---当 ngx.flush(true) 在 ngx.print 或 ngx.say 之后被立刻调用时,它将使这两个函数以同步模式执行。这在流式输出时非常有用。
---
---请注意,ngx.flush 在 HTTP 1.0 缓冲输出模式下不起作用。详情请参考 HTTP 1.0 support。
function ngx.flush(wait)
end
---语法: ngx.exit(status)
---
---环境: rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---当 status >= 200 (即 ngx.HTTP_OK 及以上) 时,本函数中断当前请求执行并返回状态值给 nginx。
---
---当 status == 0 (即 ngx.OK) 时,本函数退出当前的“处理阶段句柄” (或当使用 content_by_lua* 指令时的“内容句柄”) ,
---继续执行当前请求的下一个阶段 (如果有)。
---
---status 参数可以是 status argument can be ngx.OK, ngx.ERROR, ngx.HTTP_NOT_FOUND, ngx.HTTP_MOVED_TEMPORARILY 或其它 HTTP status constants。
---
---要返回一个自定义内容的错误页,使用类似下面的代码:
---
--- ngx.status = ngx.HTTP_GONE
--- ngx.say("This is our own content")
--- --- 退出整个请求而不是当前处理阶段
--- ngx.exit(ngx.HTTP_OK)
---实际效果:
---
--- $ curl -i 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
function ngx.exit(status)
end
---语法: ok, err = ngx.eof()
---
---环境: rewrite_by_lua*, access_by_lua*, content_by_lua*
---
---明确指定响应输出流的末尾。在 HTTP 1.1 分块编码输出模式下,它会触发 Nginx 内核发送“最后一块”。
---当禁用下游连接的 HTTP 1.1 保持连接功能后,用户程序可以通过调用此方法,使下游 HTTP 客户端主动关闭连接。
---这招可以用来执行后台任务,而无需 HTTP 客户端等待连接关闭,例如:
---
--- location = /async {
--- keepalive_timeout 0;
--- content_by_lua_block {
--- ngx.say("got the task!")
--- ngx.eof() --- 下游 HTTP 客户端将在这里断开连接
--- --- 在这里访问 MySQL, PostgreSQL, Redis, Memcached 等 ...
--- }
--- }
---但是,如果用户程序创建子请求通过 Nginx 上游模块访问其他 location 时,需要配置上游模块忽略客户端连接中断
---(如果不是默认)。例如,默认时,基本模块 ngx_http_proxy_module 在客户端关闭连接后,立刻中断主请求和子请求,
---所以在 ngx_http_proxy_module 配置的 location 块中打开 proxy_ignore_client_abort 开关非常重要:
--- proxy_ignore_client_abort on;
---一个执行后台任务的方法是使用 ngx.timer.at API。
function ngx.eof()
end
---语法: ngx.sleep(seconds)
---
---环境: rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*
---
---无阻塞地休眠特定秒。时间可以精确到 0.001 秒 (毫秒)。
---
---在后台,此方法使用 Nginx 的定时器。
---
---自版本 0.7.20 开始,0 也可以作为时间参数被指定。
function ngx.sleep(seconds)
end
---语法: newstr = ngx.escape_uri(str)
---
---环境: init_by_lua*, init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---对 str 进行 URI 编码。
function ngx.escape_uri(str)
end
---语法: newstr = ngx.unescape_uri(str)
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---将转义过的 URI 内容 str 解码。
---
---例如,
---
--- ngx.say(ngx.unescape_uri("b%20r56+7"))
---输出
---
---b r56 7
function ngx.unescape_uri(str)
end
---语法: str = ngx.encode_args(table)
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*
---
---根据 URI 编码规则,将 Lua 表编码成一个查询参数字符串。
---
---例如,
--- ngx.encode_args({foo = 3, ["b r"] = "hello world"})
---生成
---
---foo=3&b%20r=hello%20world
---Lua 表的 key 必须是 Lua 字符串。
---
---支持多值参数。可以使用 Lua 表存储参数值,例如:
---
--- ngx.encode_args({baz = {32, "hello"}})
---输出
---
---baz=32&baz=hello
---@return string
function ngx.encode_args(table)
end
---语法: table = ngx.decode_args(str, max_args?)
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*
---
---将 URI 编码的查询字符串解码为 Lua 表。本函数是 ngx.encode_args 的逆函数。
---
---可选的参数 max_args 可以用来指定从 str 中最多解析的参数个数。默认时,最多解析 100 个请求参数 (包括同名的)。为避免潜在的拒绝服务式攻击 (denial of services, DOS),超过 max_args 数量上限的 URI 参数被丢弃,
---
---这个参数可以被设成 0 以去掉解析参数数量上限:
---
--- local args = ngx.decode_args(str, 0)
---强烈不推荐移除 max_args 限制。
---@return table
function ngx.decode_args(str,max_args)
end
---语法: newstr = ngx.encode_base64(str, no_padding?)
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---通过 base64 对 str 字符串编码。
---
---自 0.9.16 版本后,引入了一个布尔值参数 no_padding 用来控制是否需要编码数据填充 等号 字符串(默认为 false,代表需要填充)。
---@return string
function ngx.encode_base64(str,no_padding)
end
---语法: newstr = ngx.decode_base64(str)
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---通过 base64 解码 str 字符串得到未编码过的字符串。如果 str 字符串没有被正常解码将会返回 nil。
function ngx.decode_base64(str)
end
---语法: intval = ngx.crc32_short(str)
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---通过一个字符串计算循环冗余校验码。
---
---这个方法最好在字符串较少时调用(比如少于30-60字节),他的结果和 ngx.crc32_long 是一样的。
---
---本质上,它只是 Nginx 内核函数 ngx_crc32_short 的简单封装。
function ngx.crc32_short(str)
end
---语法: intval = ngx.crc32_long(str)
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---通过一个字符串计算循环冗余校验码。
---
---这个方法最好在字符串较多时调用(比如大于30-60字节),他的结果和 ngx.crc32_short 是一样的。
---
---本质上,它只是 Nginx 内核函数 ngx_crc32_long 的简单封装。
function ngx.crc32_long(str)
end
---语法: digest = ngx.hmac_sha1(secret_key, str)
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---通过 str 待运算数据和 secret_key 密钥串生成结果。关于 HMAC-SHA1。
---
---通过 HMAC-SHA1 的运算会得到二进制数据,如果你想要把结果转为文本形式,你可以使用 ngx.encode_base64 函数。
---
---举一个例子,
---
--- local key = "thisisverysecretstuff"
--- local src = "some string we want to sign"
--- local digest = ngx.hmac_sha1(key, src)
--- ngx.say(ngx.encode_base64(digest))
---将会输出
---
---R/pvxzHC4NLtj7S+kXFg/NePTmk=
function ngx.hmac_sha1(secret_key,str)
end
---语法: digest = ngx.md5(str)
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---通过 MD5 计算 str 字符串返回十六进制的数据。
---
---举一个例子,
---
--- location = /md5 {
--- content_by_lua_block { ngx.say(ngx.md5("hello")) }
--- }
---将会输出
---
---5d41402abc4b2a76b9719d911017c592
---如果需要返回二进制数据请看 ngx.md5_bin 方法。
function ngx.md5(str)
end
---语法: digest = ngx.md5_bin(str)
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---通过 MD5 计算 str 字符串返回二进制的数据。
---
---如果需要返回纯文本数据请看 ngx.md5 方法。
function ngx.md5_bin(str)
end
---语法: digest = ngx.sha1_bin(str)
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---通过 SHA-1 计算 str 字符串返回二进制的数据。
---
---在安装 Nginx 时 这个函数需要 SHA-1 的支持。(这通常说明应该在安装 Nginx 时一起安装 OpenSSL 库)。
function ngx.sha1_bin(str)
end
---语法: quoted_value = ngx.quote_sql_str(raw_value)
---
---环境: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---根据 MySQL 转义规则返回一个转义后字符串。
function ngx.quote_sql_str(raw_value)
end
---语法: str = ngx.today()
---
---环境: init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---从 nginx 的时间缓存(不像 Lua 的日期库,该时间不涉及系统调用)返回当前的日期(格式:yyyy-mm-dd)。
---
---这是个本地时间。
function ngx.today()
end
---语法: secs = ngx.time()
---
---环境: init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---返回从新纪元到从 nginx 时间缓存(不像 Lua 的日期库,该时间不涉及系统调用))获取的当前时间戳所经过的秒数。
---
---通过先调用 ngx.update_time 会强制更新 nginx 的时间缓存。
function ngx.time()
end
---返回当前时间戳,带毫秒1290079655.001 但是一次请求内该值不会改变
---语法: secs = ngx.now()
---
---环境: init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---返回一个浮点型的数字,该数字是从新纪元到从 nginx 时间缓存(不像 Lua 的日期库,该时间不涉及系统调用)获取的当前时间戳所经过的时间(以秒为单位,小数部分是毫秒)。
---
---通过先调用 ngx.update_time ,你可以强制更新 nginx 时间缓存。
function ngx.now()
end
---强制更新缓存的时间
---语法: ngx.update_time()
---
---环境: init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---强行更新 Nginx 当前时间缓存。此调用会涉及到一个系统调用,因此会有一些系统开销,所以不要滥用。
---
---这个API最早出现在 v0.3.1rc32 版本中。
function ngx.update_time()
end
---语法: str = ngx.localtime()
---
---环境: init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*
---
---返回 nginx 时间缓存(不像 Lua 的 os.date 函数,该时间不涉及系统调用)的当前时间戳(格式:yyyy-mm-dd hh:MM:ss)。
---