xref: /unit/src/nxt_http_variables.c (revision 2124:6e74a08303ad)
11563Svbart@nginx.com 
21563Svbart@nginx.com /*
31563Svbart@nginx.com  * Copyright (C) NGINX, Inc.
41563Svbart@nginx.com  */
51563Svbart@nginx.com 
61563Svbart@nginx.com #include <nxt_router.h>
71563Svbart@nginx.com #include <nxt_http.h>
81563Svbart@nginx.com 
91563Svbart@nginx.com 
10*2124Sz.hong@f5.com static nxt_int_t nxt_http_var_method(nxt_task_t *task, nxt_str_t *str,
11*2124Sz.hong@f5.com     void *ctx);
12*2124Sz.hong@f5.com static nxt_int_t nxt_http_var_request_uri(nxt_task_t *task, nxt_str_t *str,
13*2124Sz.hong@f5.com     void *ctx);
14*2124Sz.hong@f5.com static nxt_int_t nxt_http_var_uri(nxt_task_t *task, nxt_str_t *str, void *ctx);
15*2124Sz.hong@f5.com static nxt_int_t nxt_http_var_host(nxt_task_t *task, nxt_str_t *str, void *ctx);
161563Svbart@nginx.com 
171563Svbart@nginx.com 
181563Svbart@nginx.com static nxt_var_decl_t  nxt_http_vars[] = {
191563Svbart@nginx.com     { nxt_string("method"),
201563Svbart@nginx.com       &nxt_http_var_method,
211563Svbart@nginx.com       0 },
221563Svbart@nginx.com 
232110Salx.manpages@gmail.com     { nxt_string("request_uri"),
242110Salx.manpages@gmail.com       &nxt_http_var_request_uri,
252110Salx.manpages@gmail.com       0 },
262110Salx.manpages@gmail.com 
271563Svbart@nginx.com     { nxt_string("uri"),
281563Svbart@nginx.com       &nxt_http_var_uri,
291563Svbart@nginx.com       0 },
301587Svbart@nginx.com 
311587Svbart@nginx.com     { nxt_string("host"),
321587Svbart@nginx.com       &nxt_http_var_host,
331587Svbart@nginx.com       0 },
341563Svbart@nginx.com };
351563Svbart@nginx.com 
361563Svbart@nginx.com 
371563Svbart@nginx.com nxt_int_t
381563Svbart@nginx.com nxt_http_register_variables(void)
391563Svbart@nginx.com {
401563Svbart@nginx.com     return nxt_var_register(nxt_http_vars, nxt_nitems(nxt_http_vars));
411563Svbart@nginx.com }
421563Svbart@nginx.com 
431563Svbart@nginx.com 
441563Svbart@nginx.com static nxt_int_t
45*2124Sz.hong@f5.com nxt_http_var_method(nxt_task_t *task, nxt_str_t *str, void *ctx)
461563Svbart@nginx.com {
471563Svbart@nginx.com     nxt_http_request_t  *r;
481563Svbart@nginx.com 
491563Svbart@nginx.com     r = ctx;
501563Svbart@nginx.com 
511563Svbart@nginx.com     *str = *r->method;
521563Svbart@nginx.com 
531563Svbart@nginx.com     return NXT_OK;
541563Svbart@nginx.com }
551563Svbart@nginx.com 
561563Svbart@nginx.com 
571563Svbart@nginx.com static nxt_int_t
58*2124Sz.hong@f5.com nxt_http_var_request_uri(nxt_task_t *task, nxt_str_t *str, void *ctx)
592110Salx.manpages@gmail.com {
602110Salx.manpages@gmail.com     nxt_http_request_t  *r;
612110Salx.manpages@gmail.com 
622110Salx.manpages@gmail.com     r = ctx;
632110Salx.manpages@gmail.com 
642110Salx.manpages@gmail.com     *str = r->target;
652110Salx.manpages@gmail.com 
662110Salx.manpages@gmail.com     return NXT_OK;
672110Salx.manpages@gmail.com }
682110Salx.manpages@gmail.com 
692110Salx.manpages@gmail.com 
702110Salx.manpages@gmail.com static nxt_int_t
71*2124Sz.hong@f5.com nxt_http_var_uri(nxt_task_t *task, nxt_str_t *str, void *ctx)
721563Svbart@nginx.com {
731563Svbart@nginx.com     nxt_http_request_t  *r;
741563Svbart@nginx.com 
751563Svbart@nginx.com     r = ctx;
761563Svbart@nginx.com 
771563Svbart@nginx.com     *str = *r->path;
781563Svbart@nginx.com 
791563Svbart@nginx.com     return NXT_OK;
801563Svbart@nginx.com }
811587Svbart@nginx.com 
821587Svbart@nginx.com 
831587Svbart@nginx.com static nxt_int_t
84*2124Sz.hong@f5.com nxt_http_var_host(nxt_task_t *task, nxt_str_t *str, void *ctx)
851587Svbart@nginx.com {
861587Svbart@nginx.com     nxt_http_request_t  *r;
871587Svbart@nginx.com 
881587Svbart@nginx.com     r = ctx;
891587Svbart@nginx.com 
901587Svbart@nginx.com     *str = r->host;
911587Svbart@nginx.com 
921587Svbart@nginx.com     return NXT_OK;
931587Svbart@nginx.com }
94