unit icon indicating copy to clipboard operation
unit copied to clipboard

Supporting new "index" option.

Open alejandro-colomar opened this issue 3 years ago • 6 comments

This contains several patch sets in itself, but it's too complex for github pull requests. The breakdown is:

Arrays: ``` 0f184fe (HEAD -> index-arr, gh/index-arr, alx/index-arr) Static: optimized "index" iteration. e145bb3 Tests: added tests for "index" (array) option. 825982f Static: supporting multiple paths in the "index" option. 304a838 Simplified branching. ```

Variables:

93371e9 (gh/index-var, alx/index-var, index-var) Tests: added tests for "index" (var) option.
a3532c9 Static: supporting variables in the "index" option.
5642e81 Generalized code.

Simple string:

2506eba (gh/index-str, alx/index-str, index-str) Tests: added tests for "index" (string) option.
53e4662 Static: supporting new "index" option.

Some cleanup and minor fixes before the patch set itself (already merged):

bc4990a (gh/ret404, alx/ret404, ret404) Static: returning 404 when "index" is a non-regular file.
1b5ce9c (gh/rename, alx/rename, rename) Renamed nxt_http_static_ctx_t field 'index' to 'share_idx'.

alejandro-colomar avatar Apr 26 '22 23:04 alejandro-colomar

I removed the implementation of index as an array. As suggested by @hongzhidao, I'm not sure we need it. https://github.com/nginx/unit/pull/684#discussion_r872368368

I'll keep the code in a branch in my personal repository, in case we need it in the future.

If someone requests the feature in the future, we can always reconsider it; but let's keep it simple while we're unsure.

alejandro-colomar avatar May 13 '22 14:05 alejandro-colomar

I removed the implementation of index as an array. As suggested by @hongzhidao, I'm not sure we need it. #684 (comment)

I'll keep the code in a branch in my personal repository, in case we need it in the future.

If someone requests the feature in the future, we can always reconsider it; but let's keep it simple while we're unsure.

Makes sense.

hongzhidao avatar May 13 '22 16:05 hongzhidao

I removed the implementation of index as an array. As suggested by @hongzhidao, I'm not sure we need it. #684 (comment)

I'll keep the code in a branch in my personal repository, in case we need it in the future.

If someone requests the feature in the future, we can always reconsider it; but let's keep it simple while we're unsure.

Note that if there is only one single index, it should be resolved only once if it's a variable string.

hongzhidao avatar May 13 '22 16:05 hongzhidao

For the first patch set (index-str; constant index string), I tested the following config, which works both with and without --debug:

{
  "listeners": {
    "*:80": { "pass": "routes/idx-html"        },
    "*:81": { "pass": "routes/idx"             },
    "*:82": { "pass": "routes/empty"           },
    "*:83": { "pass": "routes/no-idx"          },
    "*:84": { "pass": "routes/dir"             },
    "*:85": { "pass": "routes/dir-slash"       },
    "*:86": { "pass": "routes/no-slash-share"  },
    "*:87": { "pass": "routes/share"           },
    "*:88": { "pass": "routes/uri"             }
  },

  "routes": {
    "idx-html": [{
      "action": {"share": "/home/alx/srv/www/", "index": "readme.html"}
    }],
    "idx": [{
      "action": {"share": "/home/alx/srv/www/", "index": "readme"}
    }],
    "empty": [{
      "action": {"share": "/home/alx/srv/www/", "index": ""}
    }],
    "no-idx": [{
      "action": {"share": "/home/alx/srv/www/"}
    }],
    "dir": [{
      "action": {"share": "/home/alx/srv/www/", "index": "dir"}
    }],
    "dir-slash": [{
      "action": {"share": "/home/alx/srv/www/", "index": "dir/"}
    }],
    "no-slash-share": [{
      "action": {"share": "/home/alx/srv/www", "index": "readme.html"}
    }],
    "share": [{
      "action": {"share": "/home/alx/srv/www/readme"}
    }],
    "uri": [{
      "action": {"share": "/home/alx/srv/www$uri", "index": "readme.html"}
    }]
  }
}

With the following results:

$ seq 80 88 \
  | while read p; do
          url="localhost:$p";

          echo "URL: $url";
          curl $url;
          echo;
  done;
URL: localhost:80
rdmh

URL: localhost:81
rdm

URL: localhost:82
<!DOCTYPE html><title>Error 404</title><p>Error 404.

URL: localhost:83
idx

URL: localhost:84
<!DOCTYPE html><title>Error 404</title><p>Error 404.

URL: localhost:85
<!DOCTYPE html><title>Error 404</title><p>Error 404.

URL: localhost:86

URL: localhost:87
rdm

URL: localhost:88
rdmh

$ curl -i localhost:86
HTTP/1.1 301 Moved Permanently
Location: //
Server: Unit/1.27.0
Date: Thu, 26 May 2022 17:08:30 GMT
Content-Length: 0

alejandro-colomar avatar May 26 '22 16:05 alejandro-colomar

I already merged the following:

(ret404) Static: returning 404 when "index" is a non-regular file.
(rename) Renamed nxt_http_static_ctx_t field 'index' to 'share_idx'.

alejandro-colomar avatar May 26 '22 18:05 alejandro-colomar

Also merged:

(index-str) Tests: added tests for "index" (string) option.
            Static: supporting new "index" option.

alejandro-colomar avatar May 30 '22 19:05 alejandro-colomar

We don't intend to add more of this feature for now. I'm closing this. If we ever want it, let's reopen it then.

alejandro-colomar avatar Oct 14 '22 12:10 alejandro-colomar