项目作者: schmich

项目描述 :
HTTP Static File Server and Proxy
高级语言: Go
项目地址: git://github.com/schmich/sfs.git
创建时间: 2016-06-27T05:29:45Z
项目社区:https://github.com/schmich/sfs

开源协议:MIT License

下载


sfs

An HTTP static file web server and proxy for serving files from a directory on macOS, Windows, or Linux.

Intended as a lightweight development tool for viewing static sites, e.g. documentation, blogs, diagnostic reports, HTML mockups, and prototypes.

Install

Download the zero-install binary to a directory on your PATH.

Usage

  1. Usage: sfs [-l=<ip:port>] [-s] [-a [USER] PASS] [-d=<dir>] [-b] [-f=<format>] [-q] [-c] [-x=<url>]
  2. Static File Server - https://github.com/schmich/sfs
  3. Arguments:
  4. USER Username for digest authentication
  5. PASS Password for digest authentication
  6. Options:
  7. -l, --listen IP and port to listen on (default "127.0.0.1:8080")
  8. -s, --secure Enable HTTPS with self-signed TLS certificate
  9. -a, --auth Enable digest authentication
  10. -d, --dir Directory to serve
  11. -b, --browser Open web browser after server starts
  12. -f, --format Log format: %i %t %m %u %s %b %a (default "%i - %m %u %s")
  13. -q, --quiet Disable request logging
  14. -c, --cache Allow cached responses
  15. -x, --proxy Proxy requests to upstream server (implies -c)
  16. -v, --version Show the version and exit

Examples

Start a web server for files in the current directory and launch the default browser:

  1. sfs -b

Specify a port:

  1. sfs -p 777

Allow external connections:

  1. sfs -l 0.0.0.0

Serve files from another directory:

  1. sfs -d ../bloop

Advanced

HTTPS with SSL/TLS

Serve content via HTTPS with a self-signed TLS certificate:

  1. sfs -s

The TLS certificate is randomly generated at startup. Browsers will warn you about an insecure connection since the certificate is self-signed.

Digest Authentication

Enable HTTP digest authentication with a username and password:

  1. sfs -a gordon p4ssw0rd

Username is optional. Password is required. If a username is not specified, any non-empty username will work. A password of - will prompt you for the password via stdin:

  1. sfs -a -

Proxying Requests

sfs can act as an HTTP proxy. This is an altogether separate mode of operation from serving static files. This enables you to use sfs as a TLS-secured, digest-authenticated, logging frontend for another development server.

  1. sfs -x localhost:4567

Logging

Change request logging format with -f:

  1. sfs -f "%i - [%t] %m %u %s %b - %a"
  2. # 127.0.0.1 - [21/Jul/2016:21:07:51 -0500] GET / 200 273 - Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36

Log format:

  • %i Remote IP address
  • %t Request timestamp
  • %m Request HTTP method
  • %u Request URL
  • %s Response status code
  • %b Response length (bytes)
  • %a Request user agent (User-Agent HTTP header)

Caching

By default, sfs modifies incoming and outgoing cache headers (Cache-Control, If-None-Match, If-Modified-Since, Last-Modified, ETag) to ensure no caching occurs. To allow caching, this can be disabled with:

  1. sfs -c

License

Copyright © 2016 Chris Schmich \
MIT License. See LICENSE for details.