From 63ccc626f9c292f5cea395645fea3376da58866b Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 6 May 2015 08:58:15 -0600 Subject: [PATCH 1/6] Fix parsing bug for one-line Caddyfiles --- config/parse/parsing.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 From 898896f9e0a91b5c6c4d6e9457e1be207e7ab264 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 6 May 2015 09:16:10 -0600 Subject: [PATCH 2/6] Fix for stdin on Windows --- main.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index d503ed14..f478826e 100644 --- a/main.go +++ b/main.go @@ -104,12 +104,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 +129,7 @@ func loadConfigs() ([]server.Config, error) { return []server.Config{}, err } defer file.Close() + return config.Load(config.DefaultConfigFile, file) } @@ -143,7 +145,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) } From 7c844909b98dc441726160c5e6b505a646e8fd5d Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 6 May 2015 11:14:02 -0600 Subject: [PATCH 3/6] fastcgi: Add support for OPTIONS requests --- middleware/fastcgi/fastcgi.go | 2 ++ middleware/fastcgi/fcgiclient.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) 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) { From e12428efb9654a39078a49a6d67f9e4f85e96c69 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 6 May 2015 14:49:24 -0600 Subject: [PATCH 4/6] Add build status --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4414d379..5b684b1a 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. From abe3e5f5976e278521c6526ce3dd223c5898a0ad Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 6 May 2015 14:57:32 -0600 Subject: [PATCH 5/6] Move flag.Parse() to main() in case other packages use flags --- main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index f478826e..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 From a5f20829cb87c3474b68e7af4def46e71b8864e0 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 6 May 2015 16:39:58 -0600 Subject: [PATCH 6/6] Added link to Slack channel --- CONTRIBUTING.md | 2 ++ README.md | 2 ++ 2 files changed, 4 insertions(+) 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 5b684b1a..87340acf 100644 --- a/README.md +++ b/README.md @@ -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.