Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
45f85dbf
Commit
45f85dbf
authored
Apr 28, 2015
by
Fabio Yeon
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7404 from nikhiljindal/handleIndex
Updating handleIndex to return 404 for invalid server URL
parents
44e71093
f864195a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
1 deletion
+8
-1
index.go
pkg/apiserver/index.go
+7
-1
auth_test.go
test/integration/auth_test.go
+1
-0
No files found.
pkg/apiserver/index.go
View file @
45f85dbf
...
@@ -27,6 +27,12 @@ import (
...
@@ -27,6 +27,12 @@ import (
func
IndexHandler
(
container
*
restful
.
Container
,
muxHelper
*
MuxHelper
)
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{
func
IndexHandler
(
container
*
restful
.
Container
,
muxHelper
*
MuxHelper
)
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
status
:=
http
.
StatusOK
if
r
.
URL
.
Path
!=
"/"
&&
r
.
URL
.
Path
!=
"/index.html"
{
// Since "/" matches all paths, handleIndex is called for all paths for which there is no handler registered.
// We want to to return a 404 status with a list of all valid paths, incase of an invalid URL request.
status
=
http
.
StatusNotFound
}
var
handledPaths
[]
string
var
handledPaths
[]
string
// Extract the paths handled using restful.WebService
// Extract the paths handled using restful.WebService
for
_
,
ws
:=
range
container
.
RegisteredWebServices
()
{
for
_
,
ws
:=
range
container
.
RegisteredWebServices
()
{
...
@@ -35,6 +41,6 @@ func IndexHandler(container *restful.Container, muxHelper *MuxHelper) func(http.
...
@@ -35,6 +41,6 @@ func IndexHandler(container *restful.Container, muxHelper *MuxHelper) func(http.
// Extract the paths handled using mux handler.
// Extract the paths handled using mux handler.
handledPaths
=
append
(
handledPaths
,
muxHelper
.
RegisteredPaths
...
)
handledPaths
=
append
(
handledPaths
,
muxHelper
.
RegisteredPaths
...
)
sort
.
Strings
(
handledPaths
)
sort
.
Strings
(
handledPaths
)
writeRawJSON
(
http
.
StatusOK
,
api
.
RootPaths
{
Paths
:
handledPaths
},
w
)
writeRawJSON
(
status
,
api
.
RootPaths
{
Paths
:
handledPaths
},
w
)
}
}
}
}
test/integration/auth_test.go
View file @
45f85dbf
...
@@ -363,6 +363,7 @@ func getTestRequests() []struct {
...
@@ -363,6 +363,7 @@ func getTestRequests() []struct {
{
"GET"
,
"/api"
,
""
,
code200
},
{
"GET"
,
"/api"
,
""
,
code200
},
{
"GET"
,
"/healthz"
,
""
,
code200
},
{
"GET"
,
"/healthz"
,
""
,
code200
},
{
"GET"
,
"/version"
,
""
,
code200
},
{
"GET"
,
"/version"
,
""
,
code200
},
{
"GET"
,
"/invalidURL"
,
""
,
code404
},
}
}
return
requests
return
requests
}
}
...
...
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