You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* [enhancement] open branch for static file server
* [enhancement] import lru v2 version
* add basic filter framework for fileserver
* [enhancement] support get file with ttl
* [enhancement] support mmap
* [enhancement] add ttl for mmap
* update filehandler
* [enhancement] add prometheus metrics for cache pool
* [enhancement] support etag
* [enhancement] support Last-Modified
* [enhancement] support set root dir, support hidden files, add tests
* [enhancement] add index file
* [enhancement] support try files
* [enhancement] support rewrite path logic
* [enhancement] support precompressed
* [enhancement] support compress for small file
* [enhancement] support compress for large files
* [enhancement] support cache path parser
* [test] add test to serve files and fix bugs
* [bugfix] registry missing filters
* [doc] add doc for fileserver
* [testing] fix windows path
* [testing] only support extension filter
* [testing] fix test
* add log to test windows path
* [testing] fix test on windows
* log windows path
* [testing] fix test on windows
* log for windows path
* [testing] clean log
---------
Co-authored-by: chen <chen.su1994@outlook.com>
bufferPoolMaxFileSize: 10 * 1024 * 1024 # default is 10MB
1861
+
bufferPoolTTL: 600 # default is 600 seconds
1862
+
cacheFileExtensionFilters:
1863
+
- pattern: ["*.html", "*.css"]
1864
+
etagMaxAge: 3600 # default is 3600
1865
+
- pattern: ["/usr/*.js"]
1866
+
```
1867
+
1868
+
1869
+
### Configuration
1870
+
1871
+
1872
+
| Name | Type | Description | Required |
1873
+
| --- | --- | --- | --- |
1874
+
| root | string | The root directory path from which to serve files. | Yes |
1875
+
| index | []string | A list of filenames to look for, in order, when a directory is requested. Defaults to `["index.html", "index.txt"]`. | No |
1876
+
| hidden | []string | A list of glob patterns for files or directories to hide. Requests for these files will be treated as if they do not exist (404 Not Found). | No |
1877
+
| tryFiles | []string | A sequence of files to try serving in order. If the previous file is not found, the next one is tried. Useful for Single-Page Applications (SPAs) or front-controller patterns. Supports placeholders like `{path}` and can end with an error code like `=404`. | No |
1878
+
| rewrite | string | A rewrite rule used to internally modify the request URI before file lookups. It uses regular expression matching and capture groups (e.g., `$1`). | No |
1879
+
| precompressed | string | A space-separated list of precompressed formats (e.g., `gzip br`). For a request to `/file`, it will check for the existence of `/file.gz`, `/file.br`, etc. | No |
1880
+
| compress | string | The compression method (e.g., `gzip`) to use for on-the-fly compression of responses that are not precompressed. | No |
1881
+
| cache | [CacheSpec](#fileservercachespec) | A container for configuring caching-related settings. | No |
1882
+
1883
+
#### More about hidden rules
1884
+
##### 1. Component Patterns (rules without a path separator)
1885
+
These patterns (e.g., ".git", "*.log") are matched against each individual name component of the relative path.
##### 2. Path Patterns (rules with a path separator):
1896
+
These patterns are matched against the full absolute path. This matching is done in two ways:
1897
+
1898
+
```
1899
+
a) As a prefix: If the rule is a prefix of the path, followed by a path separator, it's a match.
1900
+
- Rule: "/build"
1901
+
- Hides: "/build/app.js", "/build/"
1902
+
- Does NOT hide: "/builder/app.js"
1903
+
1904
+
b) As a glob pattern: The rule is treated as a glob pattern to be matched against the entire absolute path.
1905
+
- Rule: "/*/*/*.conf"
1906
+
- Hides: "/etc/nginx/nginx.conf"
1907
+
- Does NOT hide: "/etc/nginx.conf"
1908
+
```
1909
+
1910
+
### Results
1911
+
1912
+
| Value | Description |
1913
+
| --- | --- |
1914
+
| internalError | An internal error occurred within the FileServer system |
1915
+
| serverError | A server-side error occurred |
1916
+
| clientError | The client's request was blocked |
1917
+
| notFound | A required resource could not be found |
1830
1918
1831
1919
## Common Types
1832
1920
@@ -2324,3 +2412,25 @@ template: |
2324
2412
|------|------|-------------|----------|
2325
2413
| header |[httpheader.AdaptSpec](#httpheaderadaptspec)| Rules to revise request header | No |
2326
2414
| body | string | If provided the body of the original request is replaced by the value of this option. | No |
2415
+
2416
+
2417
+
2418
+
### fileserver.CacheSpec
2419
+
2420
+
This configuration is nested under the `cache` field.
2421
+
2422
+
| Name | Type | Description | Required |
2423
+
| --- | --- | --- | --- |
2424
+
| bufferPoolSize | integer | The maximum size of the in-memory cache pool in bytes. Defaults to `2147483648` (2 GB). | No |
2425
+
| bufferPoolMaxFileSize | integer | The maximum size in bytes that a single file can be to be cached in the buffer pool. Defaults to `10485760` (10 MB). | No |
2426
+
| bufferPoolTTL | integer | The time-to-live (TTL) for items in the cache pool, in seconds. Defaults to `600`. | No |
2427
+
| cacheFileExtensionFilters |[][FileExtensionFilter](#fileserverfileextensionfilter) | A list of rules to control `ETag` cache headers based on file patterns. | No |
2428
+
2429
+
### fileserver.FileExtensionFilter
2430
+
2431
+
This configuration is for each object within the `cacheFileExtensionFilters` array.
2432
+
2433
+
| Name | Type | Description | Required |
2434
+
| --- | --- | --- | --- |
2435
+
| pattern |[]string | A list of glob patterns to match files against (e.g., `["*.html", "*.css"]`). | Yes |
2436
+
| etagMaxAge | integer | The `max-age` value, in seconds, to set for the `ETag` response header for files matching this pattern. Defaults to `3600`. | No |
0 commit comments