diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e9680be9..469a3d12 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,7 @@ ## Contributing to Caddy +**[Join us on Slack](https://gophers.slack.com/messages/caddy/)** to chat with other Caddy developers! ([Request an invite](http://bit.ly/go-slack-signup), then join the #caddy channel.) + This project gladly accepts contributions. Interested users are encouraged to get involved by [opening issues](https://github.com/mholt/caddy/issues) with their ideas, questions, and bug reports. Bug reports should contain clear instructions to reproduce the problem and state expected behavior. For small tweaks and bug fixes, feel free to submit [pull requests](https://github.com/mholt/caddy/pulls) at any time. For new features or to change existing behavior, please open an issue first to discuss it and claim it. This prevents overlapping efforts and also keeps the project in-line with its goals. diff --git a/README.md b/README.md index 4414d379..87340acf 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ [![Caddy](https://caddyserver.com/resources/images/caddy-boxed.png)](https://caddyserver.com) -[![Documentation](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/mholt/caddy) +[![Documentation](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/mholt/caddy) [![Build Status](https://img.shields.io/travis/mholt/caddy.svg?style=flat-square)](https://travis-ci.org/mholt/caddy) -Caddy is a lightweight, general-purpose web server for Windows, Mac, Linux, BSD, and [Android](https://github.com/mholt/caddy/wiki/Running-Caddy-on-Android). It is a capable alternative to other popular web servers. +Caddy is a lightweight, general-purpose web server for Windows, Mac, Linux, BSD, and [Android](https://github.com/mholt/caddy/wiki/Running-Caddy-on-Android). It is a capable alternative to other popular web servers that is easy to use. The most notable features are HTTP/2, Virtual Hosts, TLS + SNI, and easy configuration with a [Caddyfile](https://caddyserver.com/docs/caddyfile). Usually, you have one Caddyfile per site. Most directives for the Caddyfile invoke a layer of middleware which can be [used in your own Go programs](https://github.com/mholt/caddy/wiki/Using-Caddy-Middleware-in-Your-Own-Programs). @@ -31,7 +31,7 @@ Caddy binaries have no dependencies and are available for nearly every platform. ## Running from Source -NOTE: You will need Go **version 1.4** or greater +Note: You will need **[Go 1.4](https://golang.org/dl)** or newer 1. `$ go get github.com/mholt/caddy` 2. `cd` into your website's directory @@ -41,7 +41,7 @@ If you're tinkering, you can also use `go run main.go`. By default, Caddy serves the current directory at [localhost:2015](http://localhost:2015). You can place a Caddyfile to configure Caddy for serving your site. -Caddy accepts some flags from the command line. Run `caddy -h` to view the help for flags. +Caddy accepts some flags from the command line. Run `caddy -h` to view the help for flags. You can also pipe a Caddyfile into the caddy command. @@ -114,6 +114,8 @@ For more documentation, please view [the website](https://caddyserver.com/docs). ## Contributing +**[Join us on Slack](https://gophers.slack.com/messages/caddy/)** to chat with other Caddy developers! ([Request an invite](http://bit.ly/go-slack-signup), then join the #caddy channel.) + This project gladly accepts contributions. Interested users are encouraged to get involved by opening issues with their ideas, questions, and bug reports. Bug reports should contain clear instructions to reproduce the problem and state expected behavior. For small tweaks and bug fixes, feel free to submit pull requests at any time. For new features or to change existing behavior, please open an issue first to discuss it and claim it. This prevents overlapping efforts and also keeps the project in-line with its goals. diff --git a/config/parse/parsing.go b/config/parse/parsing.go index 43075110..8eb2c12c 100644 --- a/config/parse/parsing.go +++ b/config/parse/parsing.go @@ -51,6 +51,12 @@ func (p *parser) begin() error { return err } + if p.eof { + // this happens if the Caddyfile consists of only + // a line of addresses and nothing else + return nil + } + err = p.blockContents() if err != nil { return err @@ -113,12 +119,6 @@ func (p *parser) blockContents() error { p.cursor-- } - if p.eof { - // this happens if the Caddyfile consists of only - // a line of addresses and nothing else - return nil - } - err := p.directives() if err != nil { return err diff --git a/main.go b/main.go index d503ed14..f9dbb489 100644 --- a/main.go +++ b/main.go @@ -34,13 +34,14 @@ func init() { flag.StringVar(&config.Root, "root", config.DefaultRoot, "Root path to default site") flag.StringVar(&config.Host, "host", config.DefaultHost, "Default host") flag.StringVar(&config.Port, "port", config.DefaultPort, "Default port") - flag.Parse() config.AppName = "Caddy" config.AppVersion = "0.6.0" } func main() { + flag.Parse() + var wg sync.WaitGroup // Set CPU cap @@ -104,12 +105,13 @@ func loadConfigs() ([]server.Config, error) { } // stdin - // Load piped configuration data, if any fi, err := os.Stdin.Stat() - if err != nil { - log.Fatal(err) - } if err == nil && fi.Mode()&os.ModeCharDevice == 0 { + // Note that a non-nil error is not a problem. Windows + // will not create a stdin if there is no pipe, which + // produces an error when calling Stat(). But Unix will + // make one either way, which is why we also check that + // bitmask. confBody, err := ioutil.ReadAll(os.Stdin) if err != nil { log.Fatal(err) @@ -128,6 +130,7 @@ func loadConfigs() ([]server.Config, error) { return []server.Config{}, err } defer file.Close() + return config.Load(config.DefaultConfigFile, file) } @@ -143,7 +146,7 @@ func arrangeBindings(allConfigs []server.Config) (map[string][]server.Config, er for _, conf := range allConfigs { addr, err := net.ResolveTCPAddr("tcp", conf.Address()) if err != nil { - return addresses, err + return addresses, errors.New("Could not serve " + conf.Address() + " - " + err.Error()) } addresses[addr.String()] = append(addresses[addr.String()], conf) } diff --git a/middleware/fastcgi/fastcgi.go b/middleware/fastcgi/fastcgi.go index e797f43d..6d7fd1f8 100644 --- a/middleware/fastcgi/fastcgi.go +++ b/middleware/fastcgi/fastcgi.go @@ -70,6 +70,8 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) resp, err = fcgi.Head(env) case "GET": resp, err = fcgi.Get(env) + case "OPTIONS": + resp, err = fcgi.Options(env) case "POST": resp, err = fcgi.Post(env, r.Header.Get("Content-Type"), r.Body, contentLength) case "PUT": diff --git a/middleware/fastcgi/fcgiclient.go b/middleware/fastcgi/fcgiclient.go index a1cd35e5..3e223d87 100644 --- a/middleware/fastcgi/fcgiclient.go +++ b/middleware/fastcgi/fcgiclient.go @@ -416,7 +416,16 @@ func (this *FCGIClient) Head(p map[string]string) (resp *http.Response, err erro return this.Request(p, nil) } -// Get issues a Post request to the fcgi responder. with request body +// Options issues an OPTIONS request to the fcgi responder. +func (this *FCGIClient) Options(p map[string]string) (resp *http.Response, err error) { + + p["REQUEST_METHOD"] = "OPTIONS" + p["CONTENT_LENGTH"] = "0" + + return this.Request(p, nil) +} + +// Post issues a POST request to the fcgi responder. with request body // in the format that bodyType specified func (this *FCGIClient) Post(p map[string]string, bodyType string, body io.Reader, l int) (resp *http.Response, err error) {