Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
2dbd14b6
Commit
2dbd14b6
authored
May 04, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consistent app name/version info; pipe config data through stdin
parent
085f6e95
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
77 additions
and
49 deletions
+77
-49
config/config.go
config/config.go
+14
-7
config/parse/dispenser.go
config/parse/dispenser.go
+1
-1
config/setup/fastcgi.go
config/setup/fastcgi.go
+4
-3
config/setup/websocket.go
config/setup/websocket.go
+2
-7
main.go
main.go
+49
-30
middleware/websockets/websocket.go
middleware/websockets/websocket.go
+1
-1
server/config.go
server/config.go
+6
-0
No files found.
config/config.go
View file @
2dbd14b6
...
...
@@ -19,13 +19,6 @@ const (
DefaultConfigFile
=
"Caddyfile"
)
// These three defaults are configurable through the command line
var
(
Root
=
DefaultRoot
Host
=
DefaultHost
Port
=
DefaultPort
)
func
Load
(
filename
string
,
input
io
.
Reader
)
([]
server
.
Config
,
error
)
{
var
configs
[]
server
.
Config
...
...
@@ -46,6 +39,9 @@ func Load(filename string, input io.Reader) ([]server.Config, error) {
Host
:
sb
.
Host
,
Port
:
sb
.
Port
,
Middleware
:
make
(
map
[
string
][]
middleware
.
Middleware
),
ConfigFile
:
filename
,
AppName
:
AppName
,
AppVersion
:
AppVersion
,
}
// It is crucial that directives are executed in the proper order.
...
...
@@ -105,3 +101,14 @@ func Default() server.Config {
Port
:
Port
,
}
}
// These three defaults are configurable through the command line
var
(
Root
=
DefaultRoot
Host
=
DefaultHost
Port
=
DefaultPort
)
// The application should set these so that various middlewares
// can access the proper information for their own needs.
var
AppName
,
AppVersion
string
config/parse/dispenser.go
View file @
2dbd14b6
...
...
@@ -199,7 +199,7 @@ func (d *Dispenser) Err(msg string) error {
// Errf is like Err, but for formatted error messages
func
(
d
*
Dispenser
)
Errf
(
format
string
,
args
...
interface
{})
error
{
return
d
.
Err
(
fmt
.
Sprintf
(
format
,
args
...
))
// TODO: I think args needs to be args...
return
d
.
Err
(
fmt
.
Sprintf
(
format
,
args
...
))
}
// numLineBreaks counts how many line breaks are in the token
...
...
config/setup/fastcgi.go
View file @
2dbd14b6
...
...
@@ -25,9 +25,10 @@ func FastCGI(c *Controller) (middleware.Middleware, error) {
Next
:
next
,
Rules
:
rules
,
Root
:
root
,
SoftwareName
:
"Caddy"
,
// TODO: Once generators are not in the same pkg as handler, obtain this from some global const
SoftwareVersion
:
""
,
// TODO: Get this from some global const too
// TODO: Set ServerName and ServerPort to correct values... (as user defined in config)
SoftwareName
:
c
.
AppName
,
SoftwareVersion
:
c
.
AppVersion
,
ServerName
:
c
.
Host
,
ServerPort
:
c
.
Port
,
}
},
nil
}
...
...
config/setup/websocket.go
View file @
2dbd14b6
...
...
@@ -68,15 +68,10 @@ func WebSocket(c *Controller) (middleware.Middleware, error) {
})
}
websockets
.
GatewayInterface
=
envGatewayInterface
websockets
.
ServerSoftware
=
envServerSoftware
websockets
.
GatewayInterface
=
c
.
AppName
+
"-CGI/1.1"
websockets
.
ServerSoftware
=
c
.
AppName
+
"/"
+
c
.
AppVersion
return
func
(
next
middleware
.
Handler
)
middleware
.
Handler
{
return
websockets
.
WebSockets
{
Next
:
next
,
Sockets
:
websocks
}
},
nil
}
const
(
envGatewayInterface
=
"caddy-CGI/1.1"
envServerSoftware
=
"caddy/"
// TODO: Version
)
main.go
View file @
2dbd14b6
package
main
import
(
"bytes"
"errors"
"flag"
"fmt"
"io/ioutil"
"log"
"net"
"os"
...
...
@@ -22,10 +24,11 @@ var (
http2
bool
// TODO: temporary flag until http2 is standard
quiet
bool
cpu
string
confBody
[]
byte
// configuration data to use, piped from stdin
)
func
init
()
{
flag
.
StringVar
(
&
conf
,
"conf"
,
config
.
DefaultConfigFile
,
"The c
onfiguration file to use"
)
flag
.
StringVar
(
&
conf
,
"conf"
,
""
,
"C
onfiguration file to use"
)
flag
.
BoolVar
(
&
http2
,
"http2"
,
true
,
"Enable HTTP/2 support"
)
// TODO: temporary flag until http2 merged into std lib
flag
.
BoolVar
(
&
quiet
,
"quiet"
,
false
,
"Quiet mode (no initialization output)"
)
flag
.
StringVar
(
&
cpu
,
"cpu"
,
"100%"
,
"CPU cap"
)
...
...
@@ -33,6 +36,21 @@ func init() {
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"
// Load piped configuration data, if any
fi
,
err
:=
os
.
Stdin
.
Stat
()
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
if
fi
.
Mode
()
&
os
.
ModeCharDevice
==
0
{
confBody
,
err
=
ioutil
.
ReadAll
(
os
.
Stdin
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
}
func
main
()
{
...
...
@@ -45,7 +63,7 @@ func main() {
}
// Load config from file
allConfigs
,
err
:=
loadConfigs
(
conf
)
allConfigs
,
err
:=
loadConfigs
()
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
...
...
@@ -82,36 +100,37 @@ func main() {
wg
.
Wait
()
}
// loadConfigs loads configuration from a file.
func
loadConfigs
(
confPath
string
)
([]
server
.
Config
,
error
)
{
var
allConfigs
[]
server
.
Config
file
,
err
:=
os
.
Open
(
confPath
)
if
err
==
nil
{
defer
file
.
Close
()
allConfigs
,
err
=
config
.
Load
(
path
.
Base
(
confPath
),
file
)
// loadConfigs loads configuration from a file or stdin (piped).
// Configuration is obtained from one of three sources, tried
// in this order: 1. -conf flag, 2. stdin, 3. Caddyfile.
// If none of those are available, a default configuration is
// loaded.
func
loadConfigs
()
([]
server
.
Config
,
error
)
{
// -conf flag
if
conf
!=
""
{
file
,
err
:=
os
.
Open
(
conf
)
if
err
!=
nil
{
return
allConfigs
,
err
}
}
else
{
if
os
.
IsNotExist
(
err
)
{
// This is only a problem if the user
// explicitly specified a config file
if
confPath
!=
config
.
DefaultConfigFile
{
return
allConfigs
,
err
}
}
else
{
// ... but anything else is always a problem
return
allConfigs
,
err
return
[]
server
.
Config
{},
err
}
defer
file
.
Close
()
return
config
.
Load
(
path
.
Base
(
conf
),
file
)
}
//
If config file was empty or didn't exist, use default
if
len
(
allConfigs
)
==
0
{
allConfigs
=
[]
server
.
Config
{
config
.
Default
()}
//
stdin
if
len
(
confBody
)
>
0
{
return
config
.
Load
(
"stdin"
,
bytes
.
NewReader
(
confBody
))
}
return
allConfigs
,
nil
// Caddyfile
file
,
err
:=
os
.
Open
(
config
.
DefaultConfigFile
)
if
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
return
[]
server
.
Config
{
config
.
Default
()},
nil
}
return
[]
server
.
Config
{},
err
}
defer
file
.
Close
()
return
config
.
Load
(
config
.
DefaultConfigFile
,
file
)
}
// arrangeBindings groups configurations by their bind address. For example,
...
...
middleware/websockets/websocket.go
View file @
2dbd14b6
...
...
@@ -63,7 +63,7 @@ func (ws WebSocket) buildEnv(cmdPath string) (metavars []string, err error) {
`PATH_TRANSLATED=`
,
// TODO
`QUERY_STRING=`
+
ws
.
URL
.
RawQuery
,
`REMOTE_ADDR=`
+
remoteHost
,
`REMOTE_HOST=`
+
remoteHost
,
//
TODO (Host lookups are slow; make this configurable)
`REMOTE_HOST=`
+
remoteHost
,
//
Host lookups are slow - don't do them
`REMOTE_IDENT=`
,
// Not used
`REMOTE_PORT=`
+
remotePort
,
`REMOTE_USER=`
,
// Not used,
...
...
server/config.go
View file @
2dbd14b6
...
...
@@ -34,6 +34,12 @@ type Config struct {
// The path to the configuration file from which this was loaded
ConfigFile
string
// The name of the application
AppName
string
// The application's version
AppVersion
string
}
// Address returns the host:port of c as a string.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment