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
5f187738
Commit
5f187738
authored
Apr 22, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better parse support for files with only an address line
parent
c10d2e0d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
6 deletions
+71
-6
config/parser.go
config/parser.go
+1
-0
config/parser_test.go
config/parser_test.go
+47
-0
config/parsing.go
config/parsing.go
+23
-6
No files found.
config/parser.go
View file @
5f187738
...
...
@@ -19,6 +19,7 @@ type (
other
[]
locationContext
// tokens to be 'parsed' later by middleware generators
scope
*
locationContext
// the current location context (path scope) being populated
unused
*
token
// sometimes a token will be read but not immediately consumed
eof
bool
// if we encounter a valid EOF in a hard place
}
// locationContext represents a location context
...
...
config/parser_test.go
View file @
5f187738
...
...
@@ -211,6 +211,53 @@ func TestParserBasicWithAlternateAddressStyles(t *testing.T) {
t
.
Fatalf
(
"Expected root for conf of %s to be '/test/www', but got: %s"
,
conf
.
Address
(),
conf
.
Root
)
}
}
p
=
&
parser
{
filename
:
"test"
}
input
=
`host:port, http://host:port, http://host, https://host:port, host`
p
.
lexer
.
load
(
strings
.
NewReader
(
input
))
confs
,
err
=
p
.
parse
()
if
err
!=
nil
{
t
.
Fatalf
(
"Expected no errors, but got '%s'"
,
err
)
}
if
len
(
confs
)
!=
5
{
t
.
Fatalf
(
"Expected 5 configurations, but got %d: %#v"
,
len
(
confs
),
confs
)
}
if
confs
[
0
]
.
Host
!=
"host"
{
t
.
Errorf
(
"Expected conf[0] Host='host', got '%#v'"
,
confs
[
0
])
}
if
confs
[
0
]
.
Port
!=
"port"
{
t
.
Errorf
(
"Expected conf[0] Port='port', got '%#v'"
,
confs
[
0
])
}
if
confs
[
1
]
.
Host
!=
"host"
{
t
.
Errorf
(
"Expected conf[1] Host='host', got '%#v'"
,
confs
[
1
])
}
if
confs
[
1
]
.
Port
!=
"port"
{
t
.
Errorf
(
"Expected conf[1] Port='port', got '%#v'"
,
confs
[
1
])
}
if
confs
[
2
]
.
Host
!=
"host"
{
t
.
Errorf
(
"Expected conf[2] Host='host', got '%#v'"
,
confs
[
2
])
}
if
confs
[
2
]
.
Port
!=
"http"
{
t
.
Errorf
(
"Expected conf[2] Port='http', got '%#v'"
,
confs
[
2
])
}
if
confs
[
3
]
.
Host
!=
"host"
{
t
.
Errorf
(
"Expected conf[3] Host='host', got '%#v'"
,
confs
[
3
])
}
if
confs
[
3
]
.
Port
!=
"port"
{
t
.
Errorf
(
"Expected conf[3] Port='port', got '%#v'"
,
confs
[
3
])
}
if
confs
[
4
]
.
Host
!=
"host"
{
t
.
Errorf
(
"Expected conf[4] Host='host', got '%#v'"
,
confs
[
4
])
}
if
confs
[
4
]
.
Port
!=
defaultPort
{
t
.
Errorf
(
"Expected conf[4] Port='%s', got '%#v'"
,
defaultPort
,
confs
[
4
]
.
Port
)
}
}
func
TestParserImport
(
t
*
testing
.
T
)
{
...
...
config/parsing.go
View file @
5f187738
...
...
@@ -38,18 +38,25 @@ func (p *parser) addresses() error {
// address gets host and port in a format accepted by net.Dial
address
:=
func
(
str
string
)
(
host
,
port
string
,
err
error
)
{
var
schemePort
string
if
strings
.
HasPrefix
(
str
,
"https://"
)
{
port
=
"https"
host
=
str
[
8
:
]
return
schemePort
=
"https"
str
=
str
[
8
:
]
}
else
if
strings
.
HasPrefix
(
str
,
"http://"
)
{
port
=
"http"
host
=
str
[
7
:
]
return
schemePort
=
"http"
str
=
str
[
7
:
]
}
else
if
!
strings
.
Contains
(
str
,
":"
)
{
str
+=
":"
+
defaultPort
}
host
,
port
,
err
=
net
.
SplitHostPort
(
str
)
if
err
!=
nil
&&
schemePort
!=
""
{
host
=
str
port
=
schemePort
// assume port from scheme
err
=
nil
}
return
}
...
...
@@ -88,6 +95,10 @@ func (p *parser) addresses() error {
if
!
expectingAnother
&&
p
.
line
()
>
startLine
{
break
}
if
!
hasNext
{
p
.
eof
=
true
break
// EOF
}
}
return
nil
...
...
@@ -115,6 +126,12 @@ func (p *parser) addressBlock() error {
})
p
.
scope
=
&
p
.
other
[
0
]
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
...
...
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