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
6241a211
Commit
6241a211
authored
Feb 24, 2015
by
Daniel Smith
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4768 from nikhiljindal/fixPrefix
APIServer: Updating special verb handlers to accept full request path rather than a trimmed one
parents
76926ec3
905a3f79
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
11 deletions
+9
-11
api_installer.go
pkg/apiserver/api_installer.go
+7
-8
apiserver.go
pkg/apiserver/apiserver.go
+1
-1
watch.go
pkg/apiserver/watch.go
+1
-2
No files found.
pkg/apiserver/api_installer.go
View file @
6241a211
...
@@ -59,7 +59,6 @@ func (a *APIInstaller) Install() (ws *restful.WebService, errors []error) {
...
@@ -59,7 +59,6 @@ func (a *APIInstaller) Install() (ws *restful.WebService, errors []error) {
watchHandler
:=
(
&
WatchHandler
{
watchHandler
:=
(
&
WatchHandler
{
storage
:
a
.
group
.
storage
,
storage
:
a
.
group
.
storage
,
codec
:
a
.
group
.
codec
,
codec
:
a
.
group
.
codec
,
prefix
:
a
.
group
.
prefix
,
linker
:
a
.
group
.
linker
,
linker
:
a
.
group
.
linker
,
info
:
a
.
group
.
info
,
info
:
a
.
group
.
info
,
})
})
...
@@ -274,7 +273,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage RESTStorage
...
@@ -274,7 +273,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage RESTStorage
addParams
(
route
,
action
.
Params
)
addParams
(
route
,
action
.
Params
)
ws
.
Route
(
route
)
ws
.
Route
(
route
)
case
"WATCH"
:
// Watch a resource.
case
"WATCH"
:
// Watch a resource.
route
:=
ws
.
GET
(
action
.
Path
)
.
To
(
r
estfulStripPrefix
(
a
.
prefix
+
"/watch"
,
watchHandler
))
.
route
:=
ws
.
GET
(
action
.
Path
)
.
To
(
r
outeFunction
(
watchHandler
))
.
Filter
(
m
)
.
Filter
(
m
)
.
Doc
(
"watch a particular "
+
kind
)
.
Doc
(
"watch a particular "
+
kind
)
.
Operation
(
"watch"
+
kind
)
.
Operation
(
"watch"
+
kind
)
.
...
@@ -282,7 +281,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage RESTStorage
...
@@ -282,7 +281,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage RESTStorage
addParams
(
route
,
action
.
Params
)
addParams
(
route
,
action
.
Params
)
ws
.
Route
(
route
)
ws
.
Route
(
route
)
case
"WATCHLIST"
:
// Watch all resources of a kind.
case
"WATCHLIST"
:
// Watch all resources of a kind.
route
:=
ws
.
GET
(
action
.
Path
)
.
To
(
r
estfulStripPrefix
(
a
.
prefix
+
"/watch"
,
watchHandler
))
.
route
:=
ws
.
GET
(
action
.
Path
)
.
To
(
r
outeFunction
(
watchHandler
))
.
Filter
(
m
)
.
Filter
(
m
)
.
Doc
(
"watch a list of "
+
kind
)
.
Doc
(
"watch a list of "
+
kind
)
.
Operation
(
"watch"
+
kind
+
"list"
)
.
Operation
(
"watch"
+
kind
+
"list"
)
.
...
@@ -290,7 +289,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage RESTStorage
...
@@ -290,7 +289,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage RESTStorage
addParams
(
route
,
action
.
Params
)
addParams
(
route
,
action
.
Params
)
ws
.
Route
(
route
)
ws
.
Route
(
route
)
case
"REDIRECT"
:
// Get the redirect URL for a resource.
case
"REDIRECT"
:
// Get the redirect URL for a resource.
route
:=
ws
.
GET
(
action
.
Path
)
.
To
(
r
estfulStripPrefix
(
a
.
prefix
+
"/redirect"
,
redirectHandler
))
.
route
:=
ws
.
GET
(
action
.
Path
)
.
To
(
r
outeFunction
(
redirectHandler
))
.
Filter
(
m
)
.
Filter
(
m
)
.
Doc
(
"redirect GET request to "
+
kind
)
.
Doc
(
"redirect GET request to "
+
kind
)
.
Operation
(
"redirect"
+
kind
)
.
Operation
(
"redirect"
+
kind
)
.
...
@@ -542,15 +541,15 @@ func appendIf(actions []action, a action, shouldAppend bool) []action {
...
@@ -542,15 +541,15 @@ func appendIf(actions []action, a action, shouldAppend bool) []action {
return
actions
return
actions
}
}
//
Returns a restful RouteFunction that calls the given handler after stripping prefix from the request path.
//
Wraps a http.Handler function inside a restful.RouteFunction
func
r
estfulStripPrefix
(
prefix
string
,
handler
http
.
Handler
)
restful
.
RouteFunction
{
func
r
outeFunction
(
handler
http
.
Handler
)
restful
.
RouteFunction
{
return
func
(
restReq
*
restful
.
Request
,
restResp
*
restful
.
Response
)
{
return
func
(
restReq
*
restful
.
Request
,
restResp
*
restful
.
Response
)
{
h
ttp
.
StripPrefix
(
prefix
,
handler
)
.
ServeHTTP
(
restResp
.
ResponseWriter
,
restReq
.
Request
)
h
andler
.
ServeHTTP
(
restResp
.
ResponseWriter
,
restReq
.
Request
)
}
}
}
}
func
addProxyRoute
(
ws
*
restful
.
WebService
,
method
string
,
prefix
string
,
path
string
,
proxyHandler
http
.
Handler
,
kind
,
resource
string
,
params
[]
*
restful
.
Parameter
)
{
func
addProxyRoute
(
ws
*
restful
.
WebService
,
method
string
,
prefix
string
,
path
string
,
proxyHandler
http
.
Handler
,
kind
,
resource
string
,
params
[]
*
restful
.
Parameter
)
{
proxyRoute
:=
ws
.
Method
(
method
)
.
Path
(
path
)
.
To
(
r
estfulStripPrefix
(
prefix
+
"/proxy"
,
proxyHandler
))
.
proxyRoute
:=
ws
.
Method
(
method
)
.
Path
(
path
)
.
To
(
r
outeFunction
(
proxyHandler
))
.
Filter
(
monitorFilter
(
"PROXY"
,
resource
))
.
Filter
(
monitorFilter
(
"PROXY"
,
resource
))
.
Doc
(
"proxy "
+
method
+
" requests to "
+
kind
)
.
Doc
(
"proxy "
+
method
+
" requests to "
+
kind
)
.
Operation
(
"proxy"
+
method
+
kind
)
.
Operation
(
"proxy"
+
method
+
kind
)
.
...
...
pkg/apiserver/apiserver.go
View file @
6241a211
...
@@ -141,7 +141,7 @@ func NewAPIGroupVersion(storage map[string]RESTStorage, codec runtime.Codec, roo
...
@@ -141,7 +141,7 @@ func NewAPIGroupVersion(storage map[string]RESTStorage, codec runtime.Codec, roo
admit
:
admissionControl
,
admit
:
admissionControl
,
context
:
contextMapper
,
context
:
contextMapper
,
mapper
:
mapper
,
mapper
:
mapper
,
info
:
&
APIRequestInfoResolver
{
util
.
NewStringSet
(
root
),
latest
.
RESTMapper
},
info
:
&
APIRequestInfoResolver
{
util
.
NewStringSet
(
strings
.
TrimPrefix
(
root
,
"/"
)
),
latest
.
RESTMapper
},
}
}
}
}
...
...
pkg/apiserver/watch.go
View file @
6241a211
...
@@ -39,7 +39,6 @@ import (
...
@@ -39,7 +39,6 @@ import (
type
WatchHandler
struct
{
type
WatchHandler
struct
{
storage
map
[
string
]
RESTStorage
storage
map
[
string
]
RESTStorage
codec
runtime
.
Codec
codec
runtime
.
Codec
prefix
string
linker
runtime
.
SelfLinker
linker
runtime
.
SelfLinker
info
*
APIRequestInfoResolver
info
*
APIRequestInfoResolver
}
}
...
@@ -51,7 +50,7 @@ func (h *WatchHandler) setSelfLinkAddName(obj runtime.Object, req *http.Request)
...
@@ -51,7 +50,7 @@ func (h *WatchHandler) setSelfLinkAddName(obj runtime.Object, req *http.Request)
return
err
return
err
}
}
newURL
:=
*
req
.
URL
newURL
:=
*
req
.
URL
newURL
.
Path
=
path
.
Join
(
h
.
prefix
,
req
.
URL
.
Path
,
name
)
newURL
.
Path
=
path
.
Join
(
req
.
URL
.
Path
,
name
)
newURL
.
RawQuery
=
""
newURL
.
RawQuery
=
""
newURL
.
Fragment
=
""
newURL
.
Fragment
=
""
return
h
.
linker
.
SetSelfLink
(
obj
,
newURL
.
String
())
return
h
.
linker
.
SetSelfLink
(
obj
,
newURL
.
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