Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mjpclab/extra-http-file-server
Simple static web server. Based on Go HTTP File Server(https://github.com/mjpclab/go-http-file-server).
https://github.com/mjpclab/extra-http-file-server
cli go http-server static-server
Last synced: 21 days ago
JSON representation
Simple static web server. Based on Go HTTP File Server(https://github.com/mjpclab/go-http-file-server).
- Host: GitHub
- URL: https://github.com/mjpclab/extra-http-file-server
- Owner: mjpclab
- License: mit
- Created: 2022-09-03T15:07:43.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-06T13:47:35.000Z (10 months ago)
- Last Synced: 2024-03-06T14:49:56.331Z (10 months ago)
- Topics: cli, go, http-server, static-server
- Language: Go
- Homepage:
- Size: 172 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Extra HTTP File Server
Extra HTTP File Server is based on Go HTTP File Server, with extra features.
It provides frequently used features for a simple static website.![Extra HTTP File Server pages](doc/ehfs.gif)
# Different to Go HTTP File Server
## Code base
Based on Go HTTP File Server's main branch, dropped support for legacy Go version.
This means it is impossible to use legacy Go version to compile binaries for legacy systems, e.g. Windows XP.## Changed behavior
For PKI validation URL `/.well-known/`,
will skip redirecting from http: to https: even `--to-https` is specified.## New options
```
--ip-allow | ...
--ip-allow-file ...
Only allow client access from specific IP or network.
Unmatched client IP will be denied.--ip-deny | ...
--ip-deny-file ...
Only denly client access from specific IP or network.
Unmatched client IP will be allowed to access.--rewrite-host
Transform a request host+URL (in the form of "host[:port]/request/path?param=value")
into another URL if it is matched by regular expression `match`.The rewrite target is specified by `replace`.
Use `$0` to represent the whole match in `match`.
use `$1` - `$9` to represent sub matches in `match`.
--rewrite-host-post
Similar to --rewrite-host, but executes after redirects has no match.
--rewrite-host-end
Similar to --rewrite-host-post, but skip rest process if matched.--rewrite
Transform a request URL (in the form of "/request/path?param=value")
into another one if it is matched by regular expression `match`.The rewrite target is specified by `replace`.
Use `$0` to represent the whole match in `match`.
use `$1` - `$9` to represent sub matches in `match`.
--rewrite-post
Similar to --rewrite, but executes after redirects has no match.
--rewrite-end
Similar to --rewrite-post, but skip rest process if matched.--redirect []
Perform an HTTP redirect when request URL (in the form of "/request/path?param=value")
is matched by regular expression `match`.The redirect target is specified by `replace`.
Use `$0` to represent the whole match in `match`.
use `$1` - `$9` to represent sub matches in `match`.Optional `status_code` specifies HTTP redirect code. defaults to 301.
--proxy
Proxy a request URL (in the form of "/request/path?param=value")
to target if it is matched by regular expression `match`.The proxy target is specified by `replace`.
Use `$0` to represent the whole match in `match`.
use `$1` - `$9` to represent sub matches in `match`.--return
When request URL (in the form of "/request/path?param=value")
is matched by `match`, return the status code `status-code`
immediately and stop processing.
--to-status
Similar to --return, but process after ghfs internal process finished.--status-page
When response status is `status-code`, respond with the file content from `fs-path`.--gzip-static
When requesting for FILE, if client supports gzip decoding, try looking for and
outputing FILE.gz as gzip compressed content.--header-add
--header-set
Add or set response header if URL(in the form of "/request/path?param=value")
matches `match`.
```## Processing order
- if client IP not match `--ip-allow` or `--ip-allow-file`, return status 403, and stop processing
- `--status-page` executed if status code matched, and stop processing.
- if client IP match `--ip-deny` or `--ip-deny-file`, return status 403, and stop processing
- `--status-page` executed if status code matched, and stop processing.
- `--rewrite-host` and `--rewrite` executed to transform the URL if matched.
- `--redirect` executed if URL matched, and stop processing.
- `--rewrite-host-post` and `--rewrite-post` executed to transform the URL if matched.
- `--rewrite-host-end` and `--rewrite-end` executed to transform the URL if matched, and skip rest processes like `--rewrite[-host]-end`, `--proxy` `--return`, etc.
- `--proxy` executed if URL matched, and stop processing.
- `--header-add` and `--header-set` executed if URL matched, and stop processing.
- `--return` executed if URL matched, and stop processing.
- `--header-add` and `--header-set` executed if URL matched, and stop processing.
- `--status-page` executed if status code matched, and stop processing.
- ghfs internal process
- `--header-add` and `--header-set` executed if URL matched.
- `--to-status` executed if URL matched, and stop processing.
- `--status-page` executed if status code matched, and stop processing.
- `--status-page` executed if status code matched, and stop processing.## Examples
Perform redirect according to `redirect` param:
```sh
# when requesting http://localhost:8080/redirect/www.example.com, redirect to https://www.example.com
ehfs -l 8080 -r /path/to/share --redirect '#/redirect/(.*)#https://$1'
```Serve static page without `.html` suffix in URL:
- redirect URL contains `.html` suffix to no suffix
- rewrite URL without suffix to with `.html` suffix```sh
ehfs -l 8080 -r /path/to/share --redirect '#(.*)\.html#$1' --rewrite-post '#^.*/[^/.]+$#$0.html'
```Specify page for 404 status:
```sh
ehfs -l 8080 -r /path/to/share --status-page '#404#/path/to/404/file'
```Refuse to serve for critical files or directories, returns 403 status:
```sh
ehfs -l 8080 -r /path/to/share --return '#.git|.htaccess#403'
```## Compile
Minimal required Go version is 1.20.
```sh
go build main.go
```
Will generate executable file "main" in current directory.