Commit 7443fd09 authored by Abiola Ibrahim's avatar Abiola Ibrahim

Merge remote-tracking branch 'upstream/master'

parents ba613a15 a5f20829
## Contributing to Caddy ## 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. 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. 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.
......
[![Caddy](https://caddyserver.com/resources/images/caddy-boxed.png)](https://caddyserver.com) [![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). 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. ...@@ -31,7 +31,7 @@ Caddy binaries have no dependencies and are available for nearly every platform.
## Running from Source ## 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` 1. `$ go get github.com/mholt/caddy`
2. `cd` into your website's directory 2. `cd` into your website's directory
...@@ -41,7 +41,7 @@ If you're tinkering, you can also use `go run main.go`. ...@@ -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. 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). ...@@ -114,6 +114,8 @@ For more documentation, please view [the website](https://caddyserver.com/docs).
## Contributing ## 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. 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. 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.
......
...@@ -51,6 +51,12 @@ func (p *parser) begin() error { ...@@ -51,6 +51,12 @@ func (p *parser) begin() error {
return err 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() err = p.blockContents()
if err != nil { if err != nil {
return err return err
...@@ -113,12 +119,6 @@ func (p *parser) blockContents() error { ...@@ -113,12 +119,6 @@ func (p *parser) blockContents() error {
p.cursor-- 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() err := p.directives()
if err != nil { if err != nil {
return err return err
......
...@@ -34,13 +34,14 @@ func init() { ...@@ -34,13 +34,14 @@ func init() {
flag.StringVar(&config.Root, "root", config.DefaultRoot, "Root path to default site") flag.StringVar(&config.Root, "root", config.DefaultRoot, "Root path to default site")
flag.StringVar(&config.Host, "host", config.DefaultHost, "Default host") flag.StringVar(&config.Host, "host", config.DefaultHost, "Default host")
flag.StringVar(&config.Port, "port", config.DefaultPort, "Default port") flag.StringVar(&config.Port, "port", config.DefaultPort, "Default port")
flag.Parse()
config.AppName = "Caddy" config.AppName = "Caddy"
config.AppVersion = "0.6.0" config.AppVersion = "0.6.0"
} }
func main() { func main() {
flag.Parse()
var wg sync.WaitGroup var wg sync.WaitGroup
// Set CPU cap // Set CPU cap
...@@ -104,12 +105,13 @@ func loadConfigs() ([]server.Config, error) { ...@@ -104,12 +105,13 @@ func loadConfigs() ([]server.Config, error) {
} }
// stdin // stdin
// Load piped configuration data, if any
fi, err := os.Stdin.Stat() fi, err := os.Stdin.Stat()
if err != nil {
log.Fatal(err)
}
if err == nil && fi.Mode()&os.ModeCharDevice == 0 { 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) confBody, err := ioutil.ReadAll(os.Stdin)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
...@@ -128,6 +130,7 @@ func loadConfigs() ([]server.Config, error) { ...@@ -128,6 +130,7 @@ func loadConfigs() ([]server.Config, error) {
return []server.Config{}, err return []server.Config{}, err
} }
defer file.Close() defer file.Close()
return config.Load(config.DefaultConfigFile, file) return config.Load(config.DefaultConfigFile, file)
} }
...@@ -143,7 +146,7 @@ func arrangeBindings(allConfigs []server.Config) (map[string][]server.Config, er ...@@ -143,7 +146,7 @@ func arrangeBindings(allConfigs []server.Config) (map[string][]server.Config, er
for _, conf := range allConfigs { for _, conf := range allConfigs {
addr, err := net.ResolveTCPAddr("tcp", conf.Address()) addr, err := net.ResolveTCPAddr("tcp", conf.Address())
if err != nil { 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) addresses[addr.String()] = append(addresses[addr.String()], conf)
} }
......
...@@ -70,6 +70,8 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) ...@@ -70,6 +70,8 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
resp, err = fcgi.Head(env) resp, err = fcgi.Head(env)
case "GET": case "GET":
resp, err = fcgi.Get(env) resp, err = fcgi.Get(env)
case "OPTIONS":
resp, err = fcgi.Options(env)
case "POST": case "POST":
resp, err = fcgi.Post(env, r.Header.Get("Content-Type"), r.Body, contentLength) resp, err = fcgi.Post(env, r.Header.Get("Content-Type"), r.Body, contentLength)
case "PUT": case "PUT":
......
...@@ -416,7 +416,16 @@ func (this *FCGIClient) Head(p map[string]string) (resp *http.Response, err erro ...@@ -416,7 +416,16 @@ func (this *FCGIClient) Head(p map[string]string) (resp *http.Response, err erro
return this.Request(p, nil) 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 // 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) { func (this *FCGIClient) Post(p map[string]string, bodyType string, body io.Reader, l int) (resp *http.Response, err error) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment