xref: /unit/src/nxt_http_variables.c (revision 2110)
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 
101563Svbart@nginx.com static nxt_int_t nxt_http_var_method(nxt_task_t *task, nxt_var_query_t *query,
111563Svbart@nginx.com     nxt_str_t *str, void *ctx);
12*2110Salx.manpages@gmail.com static nxt_int_t nxt_http_var_request_uri(nxt_task_t *task,
13*2110Salx.manpages@gmail.com     nxt_var_query_t *query, nxt_str_t *str, void *ctx);
141563Svbart@nginx.com static nxt_int_t nxt_http_var_uri(nxt_task_t *task, nxt_var_query_t *query,
151563Svbart@nginx.com     nxt_str_t *str, void *ctx);
161587Svbart@nginx.com static nxt_int_t nxt_http_var_host(nxt_task_t *task, nxt_var_query_t *query,
171587Svbart@nginx.com     nxt_str_t *str, void *ctx);
181563Svbart@nginx.com 
191563Svbart@nginx.com 
201563Svbart@nginx.com static nxt_var_decl_t  nxt_http_vars[] = {
211563Svbart@nginx.com     { nxt_string("method"),
221563Svbart@nginx.com       &nxt_http_var_method,
231563Svbart@nginx.com       0 },
241563Svbart@nginx.com 
25*2110Salx.manpages@gmail.com     { nxt_string("request_uri"),
26*2110Salx.manpages@gmail.com       &nxt_http_var_request_uri,
27*2110Salx.manpages@gmail.com       0 },
28*2110Salx.manpages@gmail.com 
291563Svbart@nginx.com     { nxt_string("uri"),
301563Svbart@nginx.com       &nxt_http_var_uri,
311563Svbart@nginx.com       0 },
321587Svbart@nginx.com 
331587Svbart@nginx.com     { nxt_string("host"),
341587Svbart@nginx.com       &nxt_http_var_host,
351587Svbart@nginx.com       0 },
361563Svbart@nginx.com };
371563Svbart@nginx.com 
381563Svbart@nginx.com 
391563Svbart@nginx.com nxt_int_t
401563Svbart@nginx.com nxt_http_register_variables(void)
411563Svbart@nginx.com {
421563Svbart@nginx.com     return nxt_var_register(nxt_http_vars, nxt_nitems(nxt_http_vars));
431563Svbart@nginx.com }
441563Svbart@nginx.com 
451563Svbart@nginx.com 
461563Svbart@nginx.com static nxt_int_t
471563Svbart@nginx.com nxt_http_var_method(nxt_task_t *task, nxt_var_query_t *query, nxt_str_t *str,
481563Svbart@nginx.com     void *ctx)
491563Svbart@nginx.com {
501563Svbart@nginx.com     nxt_http_request_t  *r;
511563Svbart@nginx.com 
521563Svbart@nginx.com     r = ctx;
531563Svbart@nginx.com 
541563Svbart@nginx.com     *str = *r->method;
551563Svbart@nginx.com 
561563Svbart@nginx.com     return NXT_OK;
571563Svbart@nginx.com }
581563Svbart@nginx.com 
591563Svbart@nginx.com 
601563Svbart@nginx.com static nxt_int_t
61*2110Salx.manpages@gmail.com nxt_http_var_request_uri(nxt_task_t *task, nxt_var_query_t *query,
62*2110Salx.manpages@gmail.com     nxt_str_t *str, void *ctx)
63*2110Salx.manpages@gmail.com {
64*2110Salx.manpages@gmail.com     nxt_http_request_t  *r;
65*2110Salx.manpages@gmail.com 
66*2110Salx.manpages@gmail.com     r = ctx;
67*2110Salx.manpages@gmail.com 
68*2110Salx.manpages@gmail.com     *str = r->target;
69*2110Salx.manpages@gmail.com 
70*2110Salx.manpages@gmail.com     return NXT_OK;
71*2110Salx.manpages@gmail.com }
72*2110Salx.manpages@gmail.com 
73*2110Salx.manpages@gmail.com 
74*2110Salx.manpages@gmail.com static nxt_int_t
751563Svbart@nginx.com nxt_http_var_uri(nxt_task_t *task, nxt_var_query_t *query, nxt_str_t *str,
761563Svbart@nginx.com     void *ctx)
771563Svbart@nginx.com {
781563Svbart@nginx.com     nxt_http_request_t  *r;
791563Svbart@nginx.com 
801563Svbart@nginx.com     r = ctx;
811563Svbart@nginx.com 
821563Svbart@nginx.com     *str = *r->path;
831563Svbart@nginx.com 
841563Svbart@nginx.com     return NXT_OK;
851563Svbart@nginx.com }
861587Svbart@nginx.com 
871587Svbart@nginx.com 
881587Svbart@nginx.com static nxt_int_t
891587Svbart@nginx.com nxt_http_var_host(nxt_task_t *task, nxt_var_query_t *query, nxt_str_t *str,
901587Svbart@nginx.com     void *ctx)
911587Svbart@nginx.com {
921587Svbart@nginx.com     nxt_http_request_t  *r;
931587Svbart@nginx.com 
941587Svbart@nginx.com     r = ctx;
951587Svbart@nginx.com 
961587Svbart@nginx.com     *str = r->host;
971587Svbart@nginx.com 
981587Svbart@nginx.com     return NXT_OK;
991587Svbart@nginx.com }
100