summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_http_static.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2023-03-28Convert uint8_t struct boolean members to nxt_bool_t.Andrew Clayton1-2/+2
Replace the usage of uint8_t in structures to represent boolean values with our nxt_bool_t type. This will result in no change in structure layout as the nxt_bool_t is now a uint8_t, same as what it's replacing. Even though it's essentially the same type, it makes it much clearer as to what its purpose is. This was largely done with the following script from Alex, with some manual conversions $ grep -rl 'uint8_t.*1 bit' src/ \ | xargs sed -i '/uint8_t.*1 bit/{s/uint8_t /nxt_bool_t /;s/; *\/\*.*/;/}' This doesn't convert the non-uint8_t booleans, they will be handled separately. Reviewed-by: Alejandro Colomar <alx@nginx.com> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-03-21HTTP: added route logging.Alejandro Colomar1-0/+6
- Configuration: added "/config/settings/http/log_route". Type: bool Default: false This adds configurability to the error log. It allows enabling and disabling logs related to how the router performs selection of the routes. - HTTP: logging request line. Log level: [notice] The request line is essential to understand which logs correspond to which request when reading the logs. - HTTP: logging route that's been discarded. Log level: [info] - HTTP: logging route whose action is selected. Log level: [notice] - HTTP: logging when "fallback" action is taken. Log level: [notice] Closes: <https://github.com/nginx/unit/issues/758> Link: <https://github.com/nginx/unit/pull/824> Link: <https://github.com/nginx/unit/pull/839> Suggested-by: Timo Stark <t.stark@nginx.com> Suggested-by: Mark L Wood-Patrick <mwoodpatrick@gmail.com> Suggested-by: Liam Crilly <liam@nginx.com> Tested-by: Liam Crilly <liam@nginx.com> Acked-by: Artem Konev <a.konev@f5.com> Cc: Andrew Clayton <a.clayton@nginx.com> Cc: Andrei Zeliankou <zelenkov@nginx.com> Reviewed-by: Zhidao Hong <z.hong@f5.com> Signed-off-by: Alejandro Colomar <alx@nginx.com>
2022-11-20Basic njs support.Zhidao HONG1-1/+1
2022-11-20Var: separating nxt_tstr_t from nxt_var_t.Zhidao HONG1-24/+28
It's for the introduction of njs support. For each option that supports native variable and JS template literals introduced next, it's unified as template string. No functional changes.
2022-07-28Log: customizable access log format.Zhidao HONG1-2/+3
2022-07-14Var: dynamic variables support.Zhidao HONG1-3/+5
This commit adds the variables $arg_NAME, $header_NAME, and $cookie_NAME.
2022-06-22Constified numerous function parameters.Andrew Clayton1-2/+2
As was pointed out by the cppcheck[0] static code analysis utility we can mark numerous function parameters as 'const'. This acts as a hint to the compiler about our intentions and the compiler will tell us when we deviate from them. [0]: https://cppcheck.sourceforge.io/
2022-06-21Static: Fixed finding the file extension.Alejandro Colomar1-6/+7
The code for finding the extension made a few assumptions that are no longer true. It didn't account for pathnames that didn't contain '/', including the empty string, or the NULL string. That code was used with "share", which always had a '/', but now it's also used with "index", which should not have a '/' in it. This fix works by limiting the search to the beginning of the string, so that if no '/' is found in it, it doesn't continue searching before the beginning of the string. This also happens to work for NULL. It is technically Undefined Behavior, as we rely on `NULL + 0 == NULL` and `NULL - NULL == 0`. But that is the only sane behavior for an implementation, and all existing POSIX implementations will Just Work for this code. Relying on this UB is useful, because we don't need to add an explicit check for NULL, and therefore we have faster code. Although the current code can't have a NULL, I expect that when we add support for variables in the index, it will be NULL in some cases. Link: <https://stackoverflow.com/q/67291052/6872717> The same code seems to be defined behavior in C++, which normally will share implementation in the compiler for these cases, and therefore it is really unlikely to be in trouble. Link: <https://stackoverflow.com/q/59409034/6872717>
2022-05-30Static: supporting new "index" option.Alejandro Colomar1-10/+24
This supports a new option "index" that configures a custom index file name to be served when a directory is requested. This initial support only allows a single fixed string. An example: { "share": "/www/data/static/$uri", "index": "lookatthis.htm" } When <example.com/foo/bar/> is requested, </www/data/static/foo/bar/lookatthis.html> is served. Default is "index.html". === nxt_conf_validator.c: Accept "index" as a member of "share", and make sure it's a string. === I tried this feature in my own computer, where I tried the following: - Setting "index" to "lookatthis.htm", and check that the correct file is being served (check both a different name and a different extension). - Not setting "index", and check that <index.html> is being served. - Settind "index" to an array of strings, and check that the configuration fails: { "error": "Invalid configuration.", "detail": "The \"index\" value must be a string, but not an array." }
2022-05-26Static: returning 404 when "index" is a non-regular file.Alejandro Colomar1-1/+3
Before this patch, if "index" was a file, but not a regular file nor a directory, so it may have been for example a FIFO, Unit returned 404. But if "index" was a directory, Unit returned 301. For consistency, this patch makes Unit return 404 for every non-regular file, including directories.
2022-05-16Renamed nxt_http_static_ctx_t field 'index' to 'share_idx'.Alejandro Colomar1-7/+7
Having a configurable index filename will require adding an index field to this structure. The most natural name for that field is 'index', so the current index field should be renamed to allow for that. A sensible name is 'share_idx', since it's the index of the shares array in 'nxt_http_static_conf_t'. Instead of 'share_index' I opted for the shorter 'share_idx'. Also, when 'index' allows an array of filenames in a following commit, another similar variable 'index_idx' should be created, and having a different prefix and suffix seems more readable than for example 'index_index'.
2022-04-26Removed special cases for non-NXT_CONF_VALUE_ARRAY.Alejandro Colomar1-22/+6
The previous commit added more generic APIs for handling NXT_CONF_VALUE_ARRAY and non-NXT_CONF_VALUE_ARRAY together. Modify calling code to remove special cases for arrays and non-arrays, taking special care that the path for non arrays is logically equivalent to the previous special cased code. Use the now-generic array code only.
2021-10-04Static: removed surplus assignment.Valentin Bartenev1-1/+0
It's not needed after 69d823e5710a. Found by Clang Static Analyzer.
2021-10-04Static: fixed possible descriptor leak introduced in a946d8cd7f8c.Valentin Bartenev1-0/+1
2021-10-01Static: multiple paths in the "share" option.Zhidao HONG1-70/+147
2021-09-30Static: variables in the "share" option.Zhidao HONG1-47/+73
This commit supports variable in the "share" option, the finding path to file serve is the value from "share". An example: { "share": "/www/data/static$uri" }
2021-09-28Static: variables in the "chroot" option.Zhidao HONG1-75/+224
2021-07-23Router: split nxt_http_static_conf_t from nxt_http_action_t.Zhidao HONG1-62/+157
No functional changes.
2021-05-26Static: handled unknown MIME types when MIME-filtering active.Oisin Canty1-18/+14
2021-05-26MIME: added PHP.Oisin Canty1-0/+2
2021-05-06Static: implemented MIME filteringOisin Canty1-4/+35
2021-05-05Fixed format and arguments mismatches in error log messages.Zhidao HONG1-2/+2
2021-05-05Fixed building without openat2().Zhidao HONG1-1/+3
2021-04-29Static: support for openat2() features.Zhidao HONG1-26/+97
Support for chrooting, rejecting symlinks, and rejecting crossing mounting points on a per-request basis during static file serving.
2021-04-22Router: grouped app and share fields in nxt_http_action_t.Zhidao HONG1-6/+6
This is a prerequisite for further introduction of openat2() features. No functional changes.
2020-12-23Static: fixing request memory pool leakage in router.Max Romanov1-3/+20
When a static file larger than NXT_HTTP_STATIC_BUF_SIZE (128K) is served, two buffers are allocated and chained; each retains the whole request memory pool. Starting from 41331471eee7, the completion handler was called once for a linked buffer chain, but the second buffer got lost. This patch improves the completion handler's treatment of static buffers to handle all linked buffers.
2020-09-29MIME: added AVIF and APNG image formats.Valentin Bartenev1-1/+4
AVIF is a modern image format based on the AV1 video codec. It generally has better compression than other widely used formats (WebP, JPEG, PNG, and GIF) and is designed to supersede them. Support was already added to the latest version of Chrome. APNG extends PNG to permit animated images that work similarly to animated GIF. It's supported by most modern browsers. Also removed duplicated ".svg" entry.
2020-05-20Static: fixed potential undefined behavior in memcpy().Valentin Bartenev1-1/+1
According to the C standard, pointer arguments passed to memcpy() calls shall still have valid values. NULL is considered as invalid. Found with GCC Static Analyzer.
2020-03-03Added a "fallback" option to be used with the "share" action.Valentin Bartenev1-0/+13
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" } } }
2019-11-14Initial proxy support.Igor Sysoev1-1/+1
2019-11-14Replacing pass with action.Igor Sysoev1-4/+4
2019-09-24Static: returning 404 for Unix domain sockets.Valentin Bartenev1-0/+11
It's now similar to how attempts to access other non-regular files are handled.
2019-09-20Fixed segfault if an inappropriate file system object is requested.Valentin Bartenev1-1/+2
Found by Coverity (CID 349483).
2019-09-19Basic support for serving static files.Valentin Bartenev1-0/+599