From 9d3672c84d223a93f56a77f30d3b53b4dae101d0 Mon Sep 17 00:00:00 2001 From: taymindis Date: Tue, 13 Oct 2020 10:23:52 +0800 Subject: [PATCH] Update Nginx Get_URI feature --- build_test_resources/linkfuntest.c | 32 +- build_test_resources/sanity_test_aio_parse.t | 16 + build_test_resources/sanity_test_raw_parse.t | 14 + config | 4 +- freebsd_test/nginx_link_function_module.c | 2 +- src/ngx_link_func_module.c | 31 +- src/ngx_link_func_module.h | 13 +- t/liblinkfuntest.so | Bin 13483 -> 0 bytes t/sanity.t | 408 ------------------- 9 files changed, 95 insertions(+), 425 deletions(-) delete mode 100644 t/liblinkfuntest.so delete mode 100644 t/sanity.t diff --git a/build_test_resources/linkfuntest.c b/build_test_resources/linkfuntest.c index ef328d6..f8bf7e6 100644 --- a/build_test_resources/linkfuntest.c +++ b/build_test_resources/linkfuntest.c @@ -40,7 +40,7 @@ void my_app_simple_get_delay_greeting(ngx_link_func_ctx_t *ctx) { ngx_link_func_log_info(ctx, "Calling back and log from my_app_simple_get"); char *rep = "2 second delay greeting from ngx_link_func testing"; - sleep(2); + sleep(2); ngx_link_func_write_resp( ctx, 200, @@ -51,10 +51,34 @@ void my_app_simple_get_delay_greeting(ngx_link_func_ctx_t *ctx) { ); } +void my_app_simple_get_uri(ngx_link_func_ctx_t *ctx) { + ngx_link_func_log_info(ctx, "log from my_app_simple_get_uri"); + ngx_link_func_str_t uri; + if (ngx_link_func_get_uri(ctx, &uri) == 0) { + ngx_link_func_write_resp( + ctx, + 200, + "200 OK", + "text/plain", + uri.data, + uri.len + ); + } else { + ngx_link_func_write_resp( + ctx, + 404, + "404 NOT FOUND", + "text/plain", + NULL, + 0 + ); + } +} + void my_app_simple_get_prop_greeting(ngx_link_func_ctx_t *ctx) { ngx_link_func_log_info(ctx, "Calling back and log from my_app_simple_get"); u_char *defaultGreeting = ngx_link_func_get_prop(ctx, "defaultGreeting", sizeof("defaultGreeting") - 1); - if(defaultGreeting) { + if (defaultGreeting) { ngx_link_func_write_resp( ctx, 200, @@ -147,7 +171,7 @@ void my_simple_authentication(ngx_link_func_ctx_t *ctx) { userName = login(userId, userPass); /** Add input header for downstream response **/ if (userName) { - ngx_link_func_add_header_in(ctx, "userName", sizeof("userName")-1, userName, strlen(userName)); + ngx_link_func_add_header_in(ctx, "userName", sizeof("userName") - 1, userName, strlen(userName)); } else { goto AUTH_FAILED; } @@ -158,7 +182,7 @@ void my_simple_authentication(ngx_link_func_ctx_t *ctx) { "200 OK", "text/plain", "OK", - sizeof("OK")-1 + sizeof("OK") - 1 ); } } diff --git a/build_test_resources/sanity_test_aio_parse.t b/build_test_resources/sanity_test_aio_parse.t index 8de276e..ec46908 100644 --- a/build_test_resources/sanity_test_aio_parse.t +++ b/build_test_resources/sanity_test_aio_parse.t @@ -150,3 +150,19 @@ GET /ext_header_foo foo: foovalue +=== TEST 60: aio threads Get Uri correct +--- main_config eval: $::main_conf +--- config +aio threads=my_thread_pool; +ngx_link_func_lib "NGINX_HTTP_LINK_FUNC_TEST_LIB_PATH"; +location = /testLinkFunUri { + ngx_link_func_call "my_app_simple_get_uri"; +} +--- request +GET /testLinkFunUri +--- error_code: 200 +--- response_headers +Content-Type: text/plain +--- response_body_like eval +qr/testLinkFunUri$/ + diff --git a/build_test_resources/sanity_test_raw_parse.t b/build_test_resources/sanity_test_raw_parse.t index 1dc0c0e..d0984ad 100755 --- a/build_test_resources/sanity_test_raw_parse.t +++ b/build_test_resources/sanity_test_raw_parse.t @@ -150,3 +150,17 @@ GET /ext_header_foo foo: foovalue +=== TEST 10: Get Uri correct +--- config +ngx_link_func_lib "NGINX_HTTP_LINK_FUNC_TEST_LIB_PATH"; +location = /testLinkFunUri { + ngx_link_func_call "my_app_simple_get_uri"; +} +--- request +GET /testLinkFunUri +--- error_code: 200 +--- response_headers +Content-Type: text/plain +--- response_body_like eval +qr/testLinkFunUri$/ + diff --git a/config b/config index 4512afb..d87c0a8 100755 --- a/config +++ b/config @@ -24,11 +24,11 @@ ngx_feature_incs="#include " ngx_feature_path= ngx_feature_libs= # ngx_feature_exit_if_not_found=yes -ngx_feature_test="int ngx_link_func_module_current_version_=ngx_link_func_module_version_33;" +ngx_feature_test="int ngx_link_func_module_current_version_=ngx_link_func_module_version_34;" . auto/feature if [ $ngx_found != yes ]; then -echo "ngx_link_func_module.h not found in your system c header path, please copy latest ngx_link_func_module.h to your /usr/include or /usr/local/include or relavent header search path with read and write permission given." +echo "ngx_link_func_module.h not found or version not aligned in your system c header path, please copy latest ngx_link_func_module.h to your /usr/include or /usr/local/include or relavent header search path with read and write permission given." echo "e.g install -m 644 ../nginx-link-function/src/ngx_link_func_module.h /usr/local/include/" echo exit 1 diff --git a/freebsd_test/nginx_link_function_module.c b/freebsd_test/nginx_link_function_module.c index c6e6b30..4a9cd90 100644 --- a/freebsd_test/nginx_link_function_module.c +++ b/freebsd_test/nginx_link_function_module.c @@ -745,7 +745,7 @@ ngx_http_link_func_pre_configuration(ngx_conf_t *cf) { return NGX_ERROR; #endif -#ifndef ngx_link_func_module_version_33 +#ifndef ngx_link_func_module_version_34 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "the ngx_http_link_func_module.h might not be latest or not found in the c header path, \ please copy latest ngx_http_link_func_module.h to your /usr/include or /usr/local/include or relavent header search path \ with read and write permission."); diff --git a/src/ngx_link_func_module.c b/src/ngx_link_func_module.c index c6e6b30..4d6a6ca 100644 --- a/src/ngx_link_func_module.c +++ b/src/ngx_link_func_module.c @@ -216,6 +216,7 @@ void ngx_link_func_log_info(ngx_link_func_ctx_t *ctx, const char* msg); void ngx_link_func_log_warn(ngx_link_func_ctx_t *ctx, const char* msg); void ngx_link_func_log_err(ngx_link_func_ctx_t *ctx, const char* msg); char *ngx_link_func_strdup(ngx_link_func_ctx_t *ctx, const char *src); +int ngx_link_func_get_uri(ngx_link_func_ctx_t *ctx, ngx_link_func_str_t *str); u_char* ngx_link_func_get_header(ngx_link_func_ctx_t *ctx, const char *key, size_t keylen); u_char* ngx_link_func_get_prop(ngx_link_func_ctx_t *ctx, const char *key, size_t keylen); int ngx_link_func_add_header_in(ngx_link_func_ctx_t *ctx, const char *key, size_t keylen, const char *value, size_t val_len ); @@ -641,7 +642,7 @@ ngx_http_link_func_proceed_init_calls(ngx_cycle_t* cycle, ngx_http_link_func_sr ngx_http_link_func_app_cycle_handler func; #if __FreeBSD__ - (void) dlerror(); + (void) dlerror(); #endif *(void**)(&func) = dlsym(scf->_app, (const char*)"ngx_link_func_init_cycle"); @@ -745,7 +746,7 @@ ngx_http_link_func_pre_configuration(ngx_conf_t *cf) { return NGX_ERROR; #endif -#ifndef ngx_link_func_module_version_33 +#ifndef ngx_link_func_module_version_34 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "the ngx_http_link_func_module.h might not be latest or not found in the c header path, \ please copy latest ngx_http_link_func_module.h to your /usr/include or /usr/local/include or relavent header search path \ with read and write permission."); @@ -813,7 +814,7 @@ ngx_http_link_func_application_compatibility_check(ngx_conf_t *cf, ngx_http_core } #if __FreeBSD__ - (void) dlerror(); + (void) dlerror(); #endif /* * check init function block, this version has to be at least init with empty function * */ ngx_http_link_func_app_cycle_handler func; @@ -826,7 +827,7 @@ ngx_http_link_func_application_compatibility_check(ngx_conf_t *cf, ngx_http_core } #if __FreeBSD__ - (void) dlerror(); + (void) dlerror(); #endif *(void**)(&func) = dlsym(scf->_app, (const char*)"ngx_link_func_exit_cycle"); @@ -846,9 +847,9 @@ ngx_http_link_func_application_compatibility_check(ngx_conf_t *cf, ngx_http_core ngx_http_link_func_loc_conf_t *lcf = cflq->_loc_conf; if ( lcf && lcf->_method_name.len > 0 ) { - + #if __FreeBSD__ - (void) dlerror(); + (void) dlerror(); #endif *(void**)(&lcf->_handler) = dlsym(scf->_app, (const char*)lcf->_method_name.data); @@ -924,9 +925,9 @@ ngx_http_link_func_module_init(ngx_cycle_t *cycle) { if ( ( lcf->_handler = ngx_http_link_func_get_duplicate_handler(scf, &lcf->_method_name) ) == NULL ) { #if __FreeBSD__ - (void) dlerror(); + (void) dlerror(); #endif - + *(void**)(&lcf->_handler) = dlsym(scf->_app, (const char*)lcf->_method_name.data); if ((error = dlerror()) != NULL) { ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "Error function load: %s", error); @@ -1026,7 +1027,7 @@ ngx_http_link_func_process_exit(ngx_cycle_t *cycle) { ngx_http_link_func_app_cycle_handler func; #if __FreeBSD__ - (void) dlerror(); + (void) dlerror(); #endif *(void**)(&func) = dlsym(scf->_app, (const char*)"ngx_link_func_exit_cycle"); @@ -1848,6 +1849,18 @@ ngx_link_func_strdup(ngx_link_func_ctx_t *ctx, const char *src) { return dst; } +int +ngx_link_func_get_uri(ngx_link_func_ctx_t *ctx, ngx_link_func_str_t *str) { + ngx_http_request_t *r = (ngx_http_request_t*)ctx->__r__; + size_t len = r->uri.len; + if (len > 0) { + str->len = len; + str->data = r->uri.data; + return 0; // NGX_OK + } + return -1; // NGX_ERROR +} + static u_char* ngx_http_link_func_strdup_with_p(ngx_pool_t *pool, const char *src, size_t len) { u_char *dst; diff --git a/src/ngx_link_func_module.h b/src/ngx_link_func_module.h index 92a72c9..554c820 100644 --- a/src/ngx_link_func_module.h +++ b/src/ngx_link_func_module.h @@ -40,7 +40,7 @@ #include #include -#define ngx_link_func_module_version_33 33 +#define ngx_link_func_module_version_34 34 #define ngx_link_func_content_type_plaintext "text/plain" @@ -53,6 +53,11 @@ typedef unsigned char u_char; #endif +typedef struct { + size_t len; + u_char *data; +} ngx_link_func_str_t; + typedef struct { char *req_args; // Uri Args u_char *req_body; // Request Body @@ -92,6 +97,12 @@ extern void ngx_link_func_log_info(ngx_link_func_ctx_t *ctx, const char* msg); extern void ngx_link_func_log_warn(ngx_link_func_ctx_t *ctx, const char* msg); extern void ngx_link_func_log_err(ngx_link_func_ctx_t *ctx, const char* msg); +/** + * example: ngx_link_func_str_t uri; + * if(ngx_link_func_get_uri(ctx, &uri) == 0) { TODO success } + * + */ +extern int ngx_link_func_get_uri(ngx_link_func_ctx_t *ctx, ngx_link_func_str_t *str); extern u_char* ngx_link_func_get_header(ngx_link_func_ctx_t *ctx, const char *key, size_t keylen); extern u_char* ngx_link_func_get_prop(ngx_link_func_ctx_t *ctx, const char *key, size_t keylen); extern void* ngx_link_func_get_query_param(ngx_link_func_ctx_t *ctx, const char *key); diff --git a/t/liblinkfuntest.so b/t/liblinkfuntest.so deleted file mode 100644 index bef6f94cb17e2037aeba49838d75f9d20d78bcf1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 13483 zcmeHNdvsORncqo>1cBs=Mk1gb5Fw&oLm&*JGA4xJ;Y}e_rWB7i_nssd?yL6!!Iqgo zz2H6_IGp6 zx%YNC^H2ZjPR{+#{`U9U-+r9^`2MzO&5GipBEhLd{FR_w=VS|0uL}BRsTY8Hu|$l= z?+kI1q%9pQ%6SV-w@?g)&?JI%T!Ux$W|;-l^6kGVC3NjyMiO+M3RqnY(lP?VW zNH7w^GAk>_0n&3$mAl~_MaPh6DQ$Q^8KC#$RWh3c_giSekoi6bKC<((CXXWAsPq-` zi%0o`p{kCo+YOLWg6DyCn?>hqT@&A5d~CPhn?9KS_LsKIIC1gNSMGS>;tPj9eC}&6e0Ap=%bI?C`Qo@|R>f~! z_{9Cg&t94N{W;%wXX3M~dPm-^`06u1*7|?Ged^QSJh`6r6oMsUg3u>9OAjK;KDC$J zh>T`OsP`f`Bp?0W0{G9t@%iY}1@JFJ&y+lRe+v2e@GS-K5TDon{sMYm1${m{w-%7I zsz7~f3((Ifp!aM6Icp$iHXe5(8>fg#;(2NyTZ%#c6fsc*sN*8tfIOurp6kR^@eNI* ztnB{;AICE#Pk(q?`g5YFQ1WLHG1Bj(om0hOCC9>IY+xXHApeL9Ut46^b3r+Emtv?@ z^53GtgLKLQ;uAo!{}x4mLg9ZU_1>7H_a!B#M%npgMgNaVZ-?qEhQj|$;onmDCgdr- zhllhwR>-XQ9}9>*3g2FCA=v)yO3r%aXBz*Mg36vJ6oT#fHp)o;yGl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;IM#4PY&%=o>g`TjsY(6r HFzNpVdDe8I diff --git a/t/sanity.t b/t/sanity.t deleted file mode 100644 index d098926..0000000 --- a/t/sanity.t +++ /dev/null @@ -1,408 +0,0 @@ -# Test Suite to parse the relevant variable the sanity.t once built - -use lib 'inc'; -use lib 'lib'; -use Test::Nginx::Socket 'no_plan'; - -our $main_conf = <<'_EOC_'; - thread_pool my_thread_pool threads=8 max_queue=8; -_EOC_ - -no_long_string(); - -run_tests(); - -#no_diff(); - -__DATA__ - -=== TEST 1: Set LINK_FUNC_TEST_1 ---- config -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /testLinkFunGreeting { - ngx_link_func_call "my_app_simple_get_greeting"; -} ---- request -GET /testLinkFunGreeting ---- error_code: 200 ---- response_headers -Content-Type: text/plain ---- response_body_like eval -qr/greeting from ngx_link_func testing$/ - - -=== TEST 2: Set LINK_FUNC_TEST_ARGS ---- config -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /testLinkFunARGS { - ngx_link_func_call "my_app_simple_get_args"; -} ---- request -GET /testLinkFunARGS?greeting=hello_nginx?id=129310923 ---- error_code: 200 ---- response_headers -Content-Type: text/plain ---- response_body_like eval -qr/greeting=hello_nginx\?id=129310923$/ - - -=== TEST 3: Set LINK_FUNC_TEST_POST_NONE ---- config -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /testLinkFunPOSTBody { - ngx_link_func_call "my_app_simple_post"; -} ---- request -POST /testLinkFunPOSTBody -" " ---- error_code: 202 ---- response_headers -Content-Type: text/plain ---- response_body_like eval -qr/\s/ - - -=== TEST 4: Set LINK_FUNC_TEST_GET_TOKEN ---- config -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /testLinkFunCVerifyToken { - ngx_link_func_call "my_app_simple_get_token_args"; -} ---- request -GET /testLinkFunCVerifyToken?token=QVNKS0pDQVNLTEpDS0xBU0pXbGtlandrbGplIGpka2FqbGthc2tsZGtqbHNrICBrZGpha2xzZGphc2Rhcw== ---- error_code: 401 ---- response_headers -Content-Type: text/plain ---- response_body_like eval -qr/QVNKS0pDQVNLTEpDS0xBU0pXbGtlandrbGplIGpka2FqbGthc2tsZGtqbHNrICBrZGpha2xzZGphc2Rhcw==$/ - - -=== TEST 5: Set LINK_FUNC_TEST_GET_ERROR_RESP ---- config -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /testLinkFuncERRORRESP { - error_log /dev/null; - ngx_link_func_call "my_app_simple_get_no_resp"; -} ---- request -GET /testLinkFuncERRORRESP?token=QVNKS0pDQVNLTEpDS0xBU0pXbGtlandrbGplIGpka2FqbGthc2tsZGtqbHNrICBrZGpha2xzZGphc2Rhcw== ---- error_code: 500 ---- response_headers -Content-Type: text/html - - -=== TEST 6: Set LINK_FUNC_TEST_GET_CALLOC_FROM_POOL ---- config -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /testLinkFuncCallocFromPool { - ngx_link_func_call "my_app_simple_get_calloc_from_pool"; -} ---- request -GET /testLinkFuncCallocFromPool ---- error_code: 200 ---- response_headers -Content-Type: text/plain ---- response_body_like eval -qr/This is the message calloc from pool$/ - - -=== TEST 7: Set LINK_FUNC_TEST_POST_BODY ---- config -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /testLinkFunPOSTBody { - ngx_link_func_call "my_app_simple_post"; -} ---- request -POST /testLinkFunPOSTBody -greeting=enjoy-http-link-function-testing ---- error_code: 202 ---- response_headers -Content-Type: text/plain ---- response_body_like eval -qr/greeting=enjoy-http-link-function-testing$/ - - -=== TEST 8: Set LINK_FUNC_TEST_CACHE ---- config -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /testLinkFunGetCache { - ngx_link_func_call "my_app_simple_get_cache"; -} -location = /testLinkFunSetCache { - ngx_link_func_call "my_app_simple_set_cache"; -} ---- pipelined_requests eval -["POST /testLinkFunSetCache", "GET /testLinkFunGetCache"] ---- response_body eval -["OK", "This is cache value"] - - -=== TEST 9: Test output headers ---- config -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /ext_header_foo { - ngx_link_func_call "my_simple_extra_foo_header_output"; -} ---- request -GET /ext_header_foo ---- error_code: 200 ---- response_headers -foo: foovalue - - - -=== TEST 10: Authentication with nginx link function header ---- config -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location /backend { - return 200 "Welcome ${arg_userName}"; -} -location = /auth { - internal; - ngx_link_func_call "my_simple_authentication"; -} -location = /my_simple_authentication { - ngx_link_func_add_req_header userId $arg_userId; - ngx_link_func_add_req_header userPass $arg_userPass; - auth_request /auth; - proxy_pass http://127.0.0.1:${server_port}/backend?userName=$http_userName; -} ---- request -GET /my_simple_authentication?userId=foo&userPass=xxxx ---- error_code: 200 ---- response_body_like eval -qr/Welcome foo$/ - - - -=== TEST 11: Authentication with nginx link function header ---- config -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location /backend { - return 200 "Welcome ${arg_userName}"; -} -location = /auth { - internal; - ngx_link_func_call "my_simple_authentication"; -} -location = /my_simple_authentication { - auth_request /auth; - proxy_pass http://127.0.0.1:${server_port}/backend?userName=$http_userName; -} ---- request -GET /my_simple_authentication ---- more_headers -userId:foo -userPass:asdasds ---- error_code: 200 ---- response_body_like eval -qr/Welcome foo$/ - - -# Test Suite below is aio threads - - -=== TEST 21: aio threads Set LINK_FUNC_TEST_1 ---- main_config eval: $::main_conf ---- config -aio threads=my_thread_pool; -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /testLinkFunGreeting { - ngx_link_func_call "my_app_simple_get_greeting"; -} ---- request -GET /testLinkFunGreeting ---- error_code: 200 ---- response_headers -Content-Type: text/plain ---- response_body_like eval -qr/greeting from ngx_link_func testing$/ - - -=== TEST 22: aio threads Set LINK_FUNC_TEST_ARGS ---- main_config eval: $::main_conf ---- config -aio threads=my_thread_pool; -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /testLinkFunARGS { - ngx_link_func_call "my_app_simple_get_args"; -} ---- request -GET /testLinkFunARGS?greeting=hello_nginx?id=129310923 ---- error_code: 200 ---- response_headers -Content-Type: text/plain ---- response_body_like eval -qr/greeting=hello_nginx\?id=129310923$/ - - -=== TEST 23: aio threads Set LINK_FUNC_TEST_POST_NONE ---- main_config eval: $::main_conf ---- config -aio threads=my_thread_pool; -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /testLinkFunPOSTBody { - ngx_link_func_call "my_app_simple_post"; -} ---- request -POST /testLinkFunPOSTBody -" " ---- error_code: 202 ---- response_headers -Content-Type: text/plain ---- response_body_like eval -qr/\s/ - - -=== TEST 24: aio threads Set LINK_FUNC_TEST_GET_TOKEN ---- main_config eval: $::main_conf ---- config -aio threads=my_thread_pool; -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /testLinkFunCVerifyToken { - ngx_link_func_call "my_app_simple_get_token_args"; -} ---- request -GET /testLinkFunCVerifyToken?token=QVNKS0pDQVNLTEpDS0xBU0pXbGtlandrbGplIGpka2FqbGthc2tsZGtqbHNrICBrZGpha2xzZGphc2Rhcw== ---- error_code: 401 ---- response_headers -Content-Type: text/plain ---- response_body_like eval -qr/QVNKS0pDQVNLTEpDS0xBU0pXbGtlandrbGplIGpka2FqbGthc2tsZGtqbHNrICBrZGpha2xzZGphc2Rhcw==$/ - - -=== TEST 25: aio threads Set LINK_FUNC_TEST_GET_ERROR_RESP ---- main_config eval: $::main_conf ---- config -aio threads=my_thread_pool; -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /testLinkFuncERRORRESP { - error_log /dev/null; - ngx_link_func_call "my_app_simple_get_no_resp"; -} ---- request -GET /testLinkFuncERRORRESP?token=QVNKS0pDQVNLTEpDS0xBU0pXbGtlandrbGplIGpka2FqbGthc2tsZGtqbHNrICBrZGpha2xzZGphc2Rhcw== ---- error_code: 500 ---- response_headers -Content-Type: text/html - - -=== TEST 26: aio threads Set LINK_FUNC_TEST_GET_CALLOC_FROM_POOL ---- main_config eval: $::main_conf ---- config -aio threads=my_thread_pool; -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /testLinkFuncCallocFromPool { - ngx_link_func_call "my_app_simple_get_calloc_from_pool"; -} ---- request -GET /testLinkFuncCallocFromPool ---- error_code: 200 ---- response_headers -Content-Type: text/plain ---- response_body_like eval -qr/This is the message calloc from pool$/ - - -=== TEST 27: aio threads Set LINK_FUNC_TEST_POST_BODY ---- main_config eval: $::main_conf ---- config -aio threads=my_thread_pool; -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /testLinkFunPOSTBody { - ngx_link_func_call "my_app_simple_post"; -} ---- request -POST /testLinkFunPOSTBody -greeting=enjoy-http-link-function-testing ---- error_code: 202 ---- response_headers -Content-Type: text/plain ---- response_body_like eval -qr/greeting=enjoy-http-link-function-testing$/ - - -=== TEST 28: aio threads Set LINK_FUNC_TEST_CACHE ---- main_config eval: $::main_conf ---- config -aio threads=my_thread_pool; -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /testLinkFunGetCache { - ngx_link_func_call "my_app_simple_get_cache"; -} -location = /testLinkFunSetCache { - ngx_link_func_call "my_app_simple_set_cache"; -} ---- pipelined_requests eval -["POST /testLinkFunSetCache", "GET /testLinkFunGetCache"] ---- response_body eval -["OK", "This is cache value"] - - -=== TEST 29: aio threads output headers ---- main_config eval: $::main_conf ---- config -aio threads=my_thread_pool; -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location = /ext_header_foo { - ngx_link_func_call "my_simple_extra_foo_header_output"; -} ---- request -GET /ext_header_foo ---- error_code: 200 ---- response_headers -foo: foovalue - - - -=== TEST 30: aio threads Authentication with nginx link function header ---- main_config eval: $::main_conf ---- config -aio threads=my_thread_pool; -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location /backend { - return 200 "Welcome ${arg_userName}"; -} -location = /auth { - internal; - ngx_link_func_call "my_simple_authentication"; -} -location = /my_simple_authentication { - ngx_link_func_add_req_header userId $arg_userId; - ngx_link_func_add_req_header userPass $arg_userPass; - auth_request /auth; - proxy_pass http://127.0.0.1:${server_port}/backend?userName=$http_userName; -} ---- request -GET /my_simple_authentication?userId=foo&userPass=xxxx ---- error_code: 200 ---- response_body_like eval -qr/Welcome foo$/ - - - -=== TEST 31: aio threads Authentication with client header ---- main_config eval: $::main_conf ---- config -aio threads=my_thread_pool; -ngx_link_func_lib "/home/foo/nginx_build/nginx-link-function/t/liblinkfuntest.so"; -location /backend { - return 200 "Welcome ${arg_userName}"; -} -location = /auth { - internal; - ngx_link_func_call "my_simple_authentication"; -} -location = /my_simple_authentication { - auth_request /auth; - proxy_pass http://127.0.0.1:${server_port}/backend?userName=$http_userName; -} ---- request -GET /my_simple_authentication ---- more_headers -userId:foo -userPass:asdasds ---- error_code: 200 ---- response_body_like eval -qr/Welcome foo$/ -