Giter VIP home page Giter VIP logo

extra-http-file-server's Introduction

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

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>|<network/prefix> ...
--ip-allow-file <file> ...
    Only allow client access from specific IP or network.
    Unmatched client IP will be denied.

--ip-deny <IP>|<network/prefix> ...
--ip-deny-file <file> ...
    Only denly client access from specific IP or network.
    Unmatched client IP will be allowed to access.

--rewrite-host <separator><match><separator><replace>
    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 <sep><match><sep><replace>
    Similar to --rewrite-host, but executes after redirects has no match.
--rewrite-host-end <sep><match><sep><replace>
    Similar to --rewrite-host-post, but skip rest process if matched.

--rewrite <separator><match><separator><replace>
    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 <sep><match><sep><replace>
    Similar to --rewrite, but executes after redirects has no match.
--rewrite-end <sep><match><sep><replace>
    Similar to --rewrite-post, but skip rest process if matched.

--redirect <separator><match><separator><replace>[<separator><status-code>]
    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 <separator><match><separator><replace>
    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 <separator><match><separator><status-code>
    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 <separator><match><separator><status-code>
    Similar to --return, but process after ghfs internal process finished.

--status-page <separator><status-code><separator><fs-path>
    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 <separator><match><separator><name><separator><value>
--header-set <separator><match><separator><name><separator><value>
    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:

# 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
ehfs -l 8080 -r /path/to/share --redirect '#(.*)\.html#$1' --rewrite-post '#^.*/[^/.]+$#$0.html'

Specify page for 404 status:

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:

ehfs -l 8080 -r /path/to/share --return '#.git|.htaccess#403'

Compile

Minimal required Go version is 1.18.

go build main.go

Will generate executable file "main" in current directory.

extra-http-file-server's People

Contributors

marjune163 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.