summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorAlejandro Colomar <alx.manpages@gmail.com>2022-05-26 14:38:42 +0200
committerAlejandro Colomar <alx.manpages@gmail.com>2022-05-31 12:40:02 +0200
commit9bf614cd0874e0ef9fda3145faacd3ef3a5fb0ed (patch)
treea0c96d103fede547a0e5baf8e88a7c2e3053d3e9 /src
parent8027e7ce0f3c7558647661864fd742d9afb33374 (diff)
downloadunit-9bf614cd0874e0ef9fda3145faacd3ef3a5fb0ed.tar.gz
unit-9bf614cd0874e0ef9fda3145faacd3ef3a5fb0ed.tar.bz2
Var: Added $request_uri (as in NGINX).
This supports a new variable $request_uri that contains the path and the query (See RFC 3986, section 3). Its contents are percent encoded. This is useful for example to redirect HTTP to HTTPS: { "return": "301", "location": "https://$host$request_uri" } When <http://example.com/foo%23bar?baz> is requested, the server redirects to <https://example.com/foo%23bar?baz>. === Testing: //diff --git a/src/nxt_http_return.c b/src/nxt_http_return.c //index 82c9156..adeb3a1 100644 //--- a/src/nxt_http_return.c //+++ b/src/nxt_http_return.c //@@ -196,6 +196,7 @@ nxt_http_return_send_ready(nxt_task_t *task, void *obj, void *data) // field->value = ctx->encoded.start; // field->value_length = ctx->encoded.length; // } //+ fprintf(stderr, "ALX: target[%1$i]: <%2$.*1$s>\n", (int)r->target.length, r->target.start); // // r->state = &nxt_http_return_send_state; // { "listeners": { "*:81": { "pass": "routes/ru" } }, "routes": { "ru": [{ "action": { "return": 301, "location": "$request_uri" } }] } } $ curl -i http://localhost:81/*foo%2Abar?baz#arg HTTP/1.1 301 Moved Permanently Location: /*foo%2Abar?baz Server: Unit/1.27.0 Date: Mon, 30 May 2022 16:04:30 GMT Content-Length: 0 $ sudo cat /usr/local/unit.log | grep ALX ALX: target[15]: </*foo%2Abar?baz>
Diffstat (limited to 'src')
-rw-r--r--src/nxt_http_variables.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/nxt_http_variables.c b/src/nxt_http_variables.c
index 1c0b561d..b765e177 100644
--- a/src/nxt_http_variables.c
+++ b/src/nxt_http_variables.c
@@ -9,6 +9,8 @@
static nxt_int_t nxt_http_var_method(nxt_task_t *task, nxt_var_query_t *query,
nxt_str_t *str, void *ctx);
+static nxt_int_t nxt_http_var_request_uri(nxt_task_t *task,
+ nxt_var_query_t *query, nxt_str_t *str, void *ctx);
static nxt_int_t nxt_http_var_uri(nxt_task_t *task, nxt_var_query_t *query,
nxt_str_t *str, void *ctx);
static nxt_int_t nxt_http_var_host(nxt_task_t *task, nxt_var_query_t *query,
@@ -20,6 +22,10 @@ static nxt_var_decl_t nxt_http_vars[] = {
&nxt_http_var_method,
0 },
+ { nxt_string("request_uri"),
+ &nxt_http_var_request_uri,
+ 0 },
+
{ nxt_string("uri"),
&nxt_http_var_uri,
0 },
@@ -52,6 +58,20 @@ nxt_http_var_method(nxt_task_t *task, nxt_var_query_t *query, nxt_str_t *str,
static nxt_int_t
+nxt_http_var_request_uri(nxt_task_t *task, nxt_var_query_t *query,
+ nxt_str_t *str, void *ctx)
+{
+ nxt_http_request_t *r;
+
+ r = ctx;
+
+ *str = r->target;
+
+ return NXT_OK;
+}
+
+
+static nxt_int_t
nxt_http_var_uri(nxt_task_t *task, nxt_var_query_t *query, nxt_str_t *str,
void *ctx)
{