Skip to content

Commit 9d3672c

Browse files
committed
Update Nginx Get_URI feature
1 parent 5454265 commit 9d3672c

9 files changed

+95
-425
lines changed

build_test_resources/linkfuntest.c

+28-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void my_app_simple_get_delay_greeting(ngx_link_func_ctx_t *ctx) {
4040
ngx_link_func_log_info(ctx, "Calling back and log from my_app_simple_get");
4141

4242
char *rep = "2 second delay greeting from ngx_link_func testing";
43-
sleep(2);
43+
sleep(2);
4444
ngx_link_func_write_resp(
4545
ctx,
4646
200,
@@ -51,10 +51,34 @@ void my_app_simple_get_delay_greeting(ngx_link_func_ctx_t *ctx) {
5151
);
5252
}
5353

54+
void my_app_simple_get_uri(ngx_link_func_ctx_t *ctx) {
55+
ngx_link_func_log_info(ctx, "log from my_app_simple_get_uri");
56+
ngx_link_func_str_t uri;
57+
if (ngx_link_func_get_uri(ctx, &uri) == 0) {
58+
ngx_link_func_write_resp(
59+
ctx,
60+
200,
61+
"200 OK",
62+
"text/plain",
63+
uri.data,
64+
uri.len
65+
);
66+
} else {
67+
ngx_link_func_write_resp(
68+
ctx,
69+
404,
70+
"404 NOT FOUND",
71+
"text/plain",
72+
NULL,
73+
0
74+
);
75+
}
76+
}
77+
5478
void my_app_simple_get_prop_greeting(ngx_link_func_ctx_t *ctx) {
5579
ngx_link_func_log_info(ctx, "Calling back and log from my_app_simple_get");
5680
u_char *defaultGreeting = ngx_link_func_get_prop(ctx, "defaultGreeting", sizeof("defaultGreeting") - 1);
57-
if(defaultGreeting) {
81+
if (defaultGreeting) {
5882
ngx_link_func_write_resp(
5983
ctx,
6084
200,
@@ -147,7 +171,7 @@ void my_simple_authentication(ngx_link_func_ctx_t *ctx) {
147171
userName = login(userId, userPass);
148172
/** Add input header for downstream response **/
149173
if (userName) {
150-
ngx_link_func_add_header_in(ctx, "userName", sizeof("userName")-1, userName, strlen(userName));
174+
ngx_link_func_add_header_in(ctx, "userName", sizeof("userName") - 1, userName, strlen(userName));
151175
} else {
152176
goto AUTH_FAILED;
153177
}
@@ -158,7 +182,7 @@ void my_simple_authentication(ngx_link_func_ctx_t *ctx) {
158182
"200 OK",
159183
"text/plain",
160184
"OK",
161-
sizeof("OK")-1
185+
sizeof("OK") - 1
162186
);
163187
}
164188
}

build_test_resources/sanity_test_aio_parse.t

+16
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,19 @@ GET /ext_header_foo
150150
foo: foovalue
151151

152152

153+
=== TEST 60: aio threads Get Uri correct
154+
--- main_config eval: $::main_conf
155+
--- config
156+
aio threads=my_thread_pool;
157+
ngx_link_func_lib "NGINX_HTTP_LINK_FUNC_TEST_LIB_PATH";
158+
location = /testLinkFunUri {
159+
ngx_link_func_call "my_app_simple_get_uri";
160+
}
161+
--- request
162+
GET /testLinkFunUri
163+
--- error_code: 200
164+
--- response_headers
165+
Content-Type: text/plain
166+
--- response_body_like eval
167+
qr/testLinkFunUri$/
168+

build_test_resources/sanity_test_raw_parse.t

+14
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,17 @@ GET /ext_header_foo
150150
foo: foovalue
151151
152152
153+
=== TEST 10: Get Uri correct
154+
--- config
155+
ngx_link_func_lib "NGINX_HTTP_LINK_FUNC_TEST_LIB_PATH";
156+
location = /testLinkFunUri {
157+
ngx_link_func_call "my_app_simple_get_uri";
158+
}
159+
--- request
160+
GET /testLinkFunUri
161+
--- error_code: 200
162+
--- response_headers
163+
Content-Type: text/plain
164+
--- response_body_like eval
165+
qr/testLinkFunUri$/
166+

config

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ ngx_feature_incs="#include <ngx_link_func_module.h>"
2424
ngx_feature_path=
2525
ngx_feature_libs=
2626
# ngx_feature_exit_if_not_found=yes
27-
ngx_feature_test="int ngx_link_func_module_current_version_=ngx_link_func_module_version_33;"
27+
ngx_feature_test="int ngx_link_func_module_current_version_=ngx_link_func_module_version_34;"
2828
. auto/feature
2929

3030
if [ $ngx_found != yes ]; then
31-
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."
31+
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."
3232
echo "e.g install -m 644 ../nginx-link-function/src/ngx_link_func_module.h /usr/local/include/"
3333
echo
3434
exit 1

freebsd_test/nginx_link_function_module.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ ngx_http_link_func_pre_configuration(ngx_conf_t *cf) {
745745
return NGX_ERROR;
746746
#endif
747747

748-
#ifndef ngx_link_func_module_version_33
748+
#ifndef ngx_link_func_module_version_34
749749
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, \
750750
please copy latest ngx_http_link_func_module.h to your /usr/include or /usr/local/include or relavent header search path \
751751
with read and write permission.");

src/ngx_link_func_module.c

+22-9
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ void ngx_link_func_log_info(ngx_link_func_ctx_t *ctx, const char* msg);
216216
void ngx_link_func_log_warn(ngx_link_func_ctx_t *ctx, const char* msg);
217217
void ngx_link_func_log_err(ngx_link_func_ctx_t *ctx, const char* msg);
218218
char *ngx_link_func_strdup(ngx_link_func_ctx_t *ctx, const char *src);
219+
int ngx_link_func_get_uri(ngx_link_func_ctx_t *ctx, ngx_link_func_str_t *str);
219220
u_char* ngx_link_func_get_header(ngx_link_func_ctx_t *ctx, const char *key, size_t keylen);
220221
u_char* ngx_link_func_get_prop(ngx_link_func_ctx_t *ctx, const char *key, size_t keylen);
221222
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
641642
ngx_http_link_func_app_cycle_handler func;
642643

643644
#if __FreeBSD__
644-
(void) dlerror();
645+
(void) dlerror();
645646
#endif
646647

647648
*(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) {
745746
return NGX_ERROR;
746747
#endif
747748

748-
#ifndef ngx_link_func_module_version_33
749+
#ifndef ngx_link_func_module_version_34
749750
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, \
750751
please copy latest ngx_http_link_func_module.h to your /usr/include or /usr/local/include or relavent header search path \
751752
with read and write permission.");
@@ -813,7 +814,7 @@ ngx_http_link_func_application_compatibility_check(ngx_conf_t *cf, ngx_http_core
813814
}
814815

815816
#if __FreeBSD__
816-
(void) dlerror();
817+
(void) dlerror();
817818
#endif
818819
/* * check init function block, this version has to be at least init with empty function * */
819820
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
826827
}
827828

828829
#if __FreeBSD__
829-
(void) dlerror();
830+
(void) dlerror();
830831
#endif
831832

832833
*(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
846847

847848
ngx_http_link_func_loc_conf_t *lcf = cflq->_loc_conf;
848849
if ( lcf && lcf->_method_name.len > 0 ) {
849-
850+
850851
#if __FreeBSD__
851-
(void) dlerror();
852+
(void) dlerror();
852853
#endif
853854

854855
*(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) {
924925
if ( ( lcf->_handler = ngx_http_link_func_get_duplicate_handler(scf, &lcf->_method_name) ) == NULL ) {
925926

926927
#if __FreeBSD__
927-
(void) dlerror();
928+
(void) dlerror();
928929
#endif
929-
930+
930931
*(void**)(&lcf->_handler) = dlsym(scf->_app, (const char*)lcf->_method_name.data);
931932
if ((error = dlerror()) != NULL) {
932933
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) {
10261027
ngx_http_link_func_app_cycle_handler func;
10271028

10281029
#if __FreeBSD__
1029-
(void) dlerror();
1030+
(void) dlerror();
10301031
#endif
10311032

10321033
*(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) {
18481849
return dst;
18491850
}
18501851

1852+
int
1853+
ngx_link_func_get_uri(ngx_link_func_ctx_t *ctx, ngx_link_func_str_t *str) {
1854+
ngx_http_request_t *r = (ngx_http_request_t*)ctx->__r__;
1855+
size_t len = r->uri.len;
1856+
if (len > 0) {
1857+
str->len = len;
1858+
str->data = r->uri.data;
1859+
return 0; // NGX_OK
1860+
}
1861+
return -1; // NGX_ERROR
1862+
}
1863+
18511864
static u_char*
18521865
ngx_http_link_func_strdup_with_p(ngx_pool_t *pool, const char *src, size_t len) {
18531866
u_char *dst;

src/ngx_link_func_module.h

+12-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include <stdlib.h>
4141
#include <stdint.h>
4242

43-
#define ngx_link_func_module_version_33 33
43+
#define ngx_link_func_module_version_34 34
4444

4545

4646
#define ngx_link_func_content_type_plaintext "text/plain"
@@ -53,6 +53,11 @@
5353
typedef unsigned char u_char;
5454
#endif
5555

56+
typedef struct {
57+
size_t len;
58+
u_char *data;
59+
} ngx_link_func_str_t;
60+
5661
typedef struct {
5762
char *req_args; // Uri Args
5863
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);
9297
extern void ngx_link_func_log_warn(ngx_link_func_ctx_t *ctx, const char* msg);
9398
extern void ngx_link_func_log_err(ngx_link_func_ctx_t *ctx, const char* msg);
9499

100+
/**
101+
* example: ngx_link_func_str_t uri;
102+
* if(ngx_link_func_get_uri(ctx, &uri) == 0) { TODO success }
103+
*
104+
*/
105+
extern int ngx_link_func_get_uri(ngx_link_func_ctx_t *ctx, ngx_link_func_str_t *str);
95106
extern u_char* ngx_link_func_get_header(ngx_link_func_ctx_t *ctx, const char *key, size_t keylen);
96107
extern u_char* ngx_link_func_get_prop(ngx_link_func_ctx_t *ctx, const char *key, size_t keylen);
97108
extern void* ngx_link_func_get_query_param(ngx_link_func_ctx_t *ctx, const char *key);

t/liblinkfuntest.so

-13.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)