Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
81d17e08
Commit
81d17e08
authored
Jan 12, 2015
by
Matt Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/ipfs: gatewayHandler: Fixed directory listing getting appended to index.html pages
parent
926b9646
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
21 deletions
+25
-21
core/corehttp/gateway_handler.go
core/corehttp/gateway_handler.go
+25
-21
No files found.
core/corehttp/gateway_handler.go
View file @
81d17e08
...
...
@@ -130,33 +130,37 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// storage for directory listing
var
dirListing
[]
directoryItem
// loop through files
foundIndex
:=
false
for
_
,
link
:=
range
nd
.
Links
{
if
link
.
Name
!=
"index.html"
{
dirListing
=
append
(
dirListing
,
directoryItem
{
link
.
Size
,
link
.
Name
})
continue
if
link
.
Name
==
"index.html"
{
log
.
Debug
(
"found index"
)
foundIndex
=
true
// return index page instead.
nd
,
err
:=
i
.
ResolvePath
(
path
+
"/index.html"
)
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
}
dr
,
err
:=
i
.
NewDagReader
(
nd
)
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
}
// write to request
io
.
Copy
(
w
,
dr
)
break
}
log
.
Debug
(
"found index"
)
// return index page instead.
nd
,
err
:=
i
.
ResolvePath
(
path
+
"/index.html"
)
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
}
dr
,
err
:=
i
.
NewDagReader
(
nd
)
if
err
!=
nil
{
dirListing
=
append
(
dirListing
,
directoryItem
{
link
.
Size
,
link
.
Name
})
}
if
!
foundIndex
{
// template and return directory listing
hndlr
:=
webHandler
{
"listing"
:
dirListing
,
"path"
:
path
}
if
err
:=
i
.
dirList
.
Execute
(
w
,
hndlr
);
err
!=
nil
{
internalWebError
(
w
,
err
)
return
}
// write to request
io
.
Copy
(
w
,
dr
)
}
// template and return directory listing
hndlr
:=
webHandler
{
"listing"
:
dirListing
,
"path"
:
path
}
if
err
:=
i
.
dirList
.
Execute
(
w
,
hndlr
);
err
!=
nil
{
internalWebError
(
w
,
err
)
return
}
}
...
...
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