Commit Graph

36 Commits

Author SHA1 Message Date
Axel Duch
e3af18834d Router: matching regular expressions support. 2020-11-17 15:03:30 +00:00
Valentin Bartenev
3f513f434f Router: fixed "not empty" pattern matching.
The "!" pattern should be opposite to "", i.e. match only non-empty values.
But after 3c00af54b937 it was equal to "!*", which is wrong.
2020-10-07 20:06:30 +03:00
hongzhidao
806135f1c9 Router: fixed "pass" to upstreams.
Messed up return values in nxt_upstream_find() caused error in applying any
configuration with a valid "pass" value in router configuration pointing to
upstream.  That wasn't the case in "listeners" objects, where the return value
wasn't checked.

Also, it caused segfault in cases where the "pass" option was configured with
variables and resulting value was pointing to a non-existent upstream.

Added missing return checks as well to catch possible memory allocation errors.

The bug was introduced in d32bc428f46b.

This closes #472 issue on GitHub.
2020-08-28 00:53:36 -04:00
Valentin Bartenev
a58f224e26 Fixed typo in return value check.
Found by Coverity (CID 361277).
2020-08-13 03:45:54 +03:00
Valentin Bartenev
93146616cf Basic variables support. 2020-08-13 02:46:54 +03:00
Axel Duch
85a1e083af Minor changes and renaming an NJS artifact to NXT.
This is partially related to #434 issue on Github.
Thanks to 洪志道 (Hong Zhi Dao).
2020-07-24 13:10:24 +01:00
Axel Duch
b6792b00ae Router: route patterns multi wildcards fix.
Matching 'start' and 'end' position now adjusted to avoid false matching.

This is related to #434 issue on Github.
Thanks to 洪志道 (Hong Zhi Dao).
2020-07-10 10:28:53 +01:00
Axel Duch
a9a21f6fe4 Router: route patterns multi wildcards support. 2020-07-04 03:24:07 +01:00
Valentin Bartenev
79f5e531fe Router: removed two unused assignments.
This should resolve some static analyzers warnings.
2020-05-15 17:08:37 +03:00
Axel Duch
ee1e248f4b Router: decode uri and args. 2020-05-14 12:29:06 +02:00
Valentin Bartenev
376d758dd7 PHP: implemented "targets" option.
This allows to specify multiple subsequent targets inside PHP applications.
For example:

  {
      "listeners": {
          "*:80": {
              "pass": "routes"
          }
      },

      "routes": [
          {
              "match": {
                  "uri": "/info"
              },

              "action": {
                  "pass": "applications/my_app/phpinfo"
              }
          },
          {
              "match": {
                  "uri": "/hello"
              },

              "action": {
                  "pass": "applications/my_app/hello"
              }
          },
          {
              "action": {
                  "pass": "applications/my_app/rest"
              }
          }
      ],

      "applications": {
          "my_app": {
              "type": "php",
              "targets": {
                  "phpinfo": {
                      "script": "phpinfo.php",
                      "root": "/www/data/admin",
                  },

                  "hello": {
                      "script": "hello.php",
                      "root": "/www/data/test",
                  },

                  "rest": {
                      "root": "/www/data/example.com",
                      "index": "index.php"
                  },
              }
          }
      }
  }
2020-05-14 13:15:01 +03:00
Valentin Bartenev
0174c971b5 Configuration: URI encoding in the "pass" option.
This is useful to escape "/" in path fragments.  For example, in order
to reference the application named "foo/bar":

  {
      "pass": "applications/foo%2Fbar"
  }
2020-05-14 13:15:00 +03:00
Valentin Bartenev
68c6b67ffc Configuration: support for rational numbers. 2020-03-30 19:37:58 +03:00
Valentin Bartenev
c63b498f94 Implemented "location" option for "return" action.
This allows to specify redirects:

  {
      "action": {
          "return": 301,
          "location": "https://www.example.com/"
      }
  }
2020-03-21 01:39:00 +03:00
Valentin Bartenev
8d727774e3 Implemented "return" action.
The "return" action can be used to immediately generate a simple HTTP response
with an arbitrary status:

  {
      "action": {
          "return": 404
      }
  }

This is especially useful for denying access to specific resources.
2020-03-27 17:22:52 +03:00
Valentin Bartenev
5f9c4754cb Initialization of the action object made more consistent. 2020-03-27 17:22:52 +03:00
Igor Sysoev
7935ea4543 Round robin upstream added. 2020-03-06 18:28:54 +03:00
Igor Sysoev
643d4383fa Refactored nxt_http_action. 2020-03-04 14:03:32 +03:00
Axel Duch
f302ed0670 Fixed negative patterns combined with address rules. 2020-03-11 14:18:39 +00:00
Valentin Bartenev
a98de7f705 Added a "fallback" option to be used with the "share" action.
It allows proceeding to another action if a file isn't available.

An example:

    {
        "share": "/data/www/",

        "fallback": {
            "pass": "applications/php"
        }
    }

In the example above, an attempt is made first to serve a request with
a file from the "/data/www/" directory.  If there's no such file, the
request is passed to the "php" application.

Fallback actions may be nested:

    {
        "share": "/data/www/",

        "fallback": {
            "share": "/data/cache/",

            "fallback": {
                "proxy": "http://127.0.0.1:9000"
            }
        }
    }
2020-03-03 20:37:47 +03:00
Axel Duch
1a76371499 Router: introducing routing on listener address. 2019-12-24 13:59:58 +00:00
Axel Duch
8677bf8d41 Router: introducing routing on client address. 2019-12-24 13:58:10 +00:00
Igor Sysoev
ddde9c23cf Initial proxy support. 2019-11-14 16:39:54 +03:00
Igor Sysoev
14e56fe8c8 Replacing pass with action. 2019-11-14 16:39:48 +03:00
Valentin Bartenev
08a8d1510d Basic support for serving static files. 2019-09-19 02:47:09 +03:00
Axel Duch
7785c96c1a Added routing based on request scheme.
Scheme matches exact string “http” or “https”.
2019-07-24 13:47:35 +03:00
Igor Sysoev
1f8c395fc0 Cookie-based routing should be case-sensitive. 2019-06-10 18:47:35 +03:00
Igor Sysoev
6a775f58af Added routing based on cookies. 2019-05-30 15:33:51 +03:00
Igor Sysoev
5fb3daa5af Added routing based on arguments. 2019-05-30 15:33:51 +03:00
Igor Sysoev
16273cf1c6 Handling routing errors. 2019-05-30 15:33:51 +03:00
Igor Sysoev
0ba7cfce75 Added routing based on header fields. 2019-05-30 15:33:51 +03:00
Igor Sysoev
3aaebe4169 Fixed segfault with empty routes array. 2019-05-30 15:33:51 +03:00
Igor Sysoev
f2aa190f60 Fixed segfault with empty rule array. 2019-05-30 15:33:51 +03:00
Valentin Bartenev
f0cc14d394 Simplified cycles in nxt_http_route_rule(). 2019-04-12 17:44:54 +03:00
Igor Sysoev
8339b15158 Added support for wildcards in the middle of match patterns. 2019-04-10 13:47:34 +03:00
Igor Sysoev
d4ccaae900 Initial routing implementation. 2019-02-27 16:41:11 +03:00