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
Łukasz Nowak
caddy
Commits
32bb6a4c
Commit
32bb6a4c
authored
Sep 06, 2017
by
Matt Holt
Committed by
GitHub
Sep 06, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1856 from twdkeule/fix-index-push
Do not push index file when not in a rule
parents
a59bdd08
b324a32b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
2 deletions
+53
-2
caddyhttp/push/handler.go
caddyhttp/push/handler.go
+4
-2
caddyhttp/push/handler_test.go
caddyhttp/push/handler_test.go
+49
-0
No files found.
caddyhttp/push/handler.go
View file @
32bb6a4c
...
@@ -30,9 +30,11 @@ outer:
...
@@ -30,9 +30,11 @@ outer:
matches
:=
httpserver
.
Path
(
urlPath
)
.
Matches
(
rule
.
Path
)
matches
:=
httpserver
.
Path
(
urlPath
)
.
Matches
(
rule
.
Path
)
// Also check IndexPages when requesting a directory
// Also check IndexPages when requesting a directory
if
!
matches
{
if
!
matches
{
_
,
matches
=
httpserver
.
IndexFile
(
h
.
Root
,
urlPath
,
staticfiles
.
IndexPages
)
indexFile
,
isIndexFile
:=
httpserver
.
IndexFile
(
h
.
Root
,
urlPath
,
staticfiles
.
IndexPages
)
if
isIndexFile
{
matches
=
httpserver
.
Path
(
indexFile
)
.
Matches
(
rule
.
Path
)
}
}
}
if
matches
{
if
matches
{
for
_
,
resource
:=
range
rule
.
Resources
{
for
_
,
resource
:=
range
rule
.
Resources
{
pushErr
:=
pusher
.
Push
(
resource
.
Path
,
&
http
.
PushOptions
{
pushErr
:=
pusher
.
Push
(
resource
.
Path
,
&
http
.
PushOptions
{
...
...
caddyhttp/push/handler_test.go
View file @
32bb6a4c
...
@@ -410,7 +410,56 @@ func TestMiddlewareShouldPushIndexFile(t *testing.T) {
...
@@ -410,7 +410,56 @@ func TestMiddlewareShouldPushIndexFile(t *testing.T) {
}
}
comparePushedResources
(
t
,
expectedPushedResources
,
pushingWriter
.
pushed
)
comparePushedResources
(
t
,
expectedPushedResources
,
pushingWriter
.
pushed
)
}
func
TestMiddlewareShouldNotPushIndexFileWhenNotARule
(
t
*
testing
.
T
)
{
// given
indexFile
:=
"/index.html"
request
,
err
:=
http
.
NewRequest
(
http
.
MethodGet
,
"/"
,
nil
)
// Request root directory, not indexfile itself
if
err
!=
nil
{
t
.
Fatalf
(
"Could not create HTTP request: %v"
,
err
)
}
root
,
err
:=
ioutil
.
TempDir
(
""
,
"caddy"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Could not create temporary directory: %v"
,
err
)
}
defer
os
.
Remove
(
root
)
middleware
:=
Middleware
{
Next
:
httpserver
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
return
0
,
nil
}),
Rules
:
[]
Rule
{
{
Path
:
"dummy.html"
,
Resources
:
[]
Resource
{
{
Path
:
"/index.css"
,
Method
:
http
.
MethodGet
},
}}},
Root
:
http
.
Dir
(
root
),
}
indexFilePath
:=
filepath
.
Join
(
root
,
indexFile
)
_
,
err
=
os
.
Create
(
indexFilePath
)
if
err
!=
nil
{
t
.
Fatalf
(
"Could not create index file: %s: %v"
,
indexFile
,
err
)
}
defer
os
.
Remove
(
indexFilePath
)
pushingWriter
:=
&
MockedPusher
{
ResponseWriter
:
httptest
.
NewRecorder
(),
returnedError
:
errors
.
New
(
"Cannot push right now"
),
}
// when
_
,
err2
:=
middleware
.
ServeHTTP
(
pushingWriter
,
request
)
// then
if
err2
!=
nil
{
t
.
Error
(
"Should not return error"
)
}
expectedPushedResources
:=
map
[
string
]
*
http
.
PushOptions
{}
comparePushedResources
(
t
,
expectedPushedResources
,
pushingWriter
.
pushed
)
}
}
func
comparePushedResources
(
t
*
testing
.
T
,
expected
,
actual
map
[
string
]
*
http
.
PushOptions
)
{
func
comparePushedResources
(
t
*
testing
.
T
,
expected
,
actual
map
[
string
]
*
http
.
PushOptions
)
{
...
...
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