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
f9f680a9
Unverified
Commit
f9f680a9
authored
Oct 11, 2016
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify RESTHander getter and remove specialized serializers
parent
96a26d93
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
57 deletions
+32
-57
apiserver.go
pkg/apiserver/apiserver.go
+32
-30
codec_factory.go
pkg/runtime/serializer/codec_factory.go
+0
-27
No files found.
pkg/apiserver/apiserver.go
View file @
f9f680a9
...
@@ -367,40 +367,42 @@ func SupportedResourcesHandler(s runtime.NegotiatedSerializer, groupVersion unve
...
@@ -367,40 +367,42 @@ func SupportedResourcesHandler(s runtime.NegotiatedSerializer, groupVersion unve
// directly to the response body. If content type is returned it is used, otherwise the content type will
// directly to the response body. If content type is returned it is used, otherwise the content type will
// be "application/octet-stream". All other objects are sent to standard JSON serialization.
// be "application/octet-stream". All other objects are sent to standard JSON serialization.
func
write
(
statusCode
int
,
gv
unversioned
.
GroupVersion
,
s
runtime
.
NegotiatedSerializer
,
object
runtime
.
Object
,
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
func
write
(
statusCode
int
,
gv
unversioned
.
GroupVersion
,
s
runtime
.
NegotiatedSerializer
,
object
runtime
.
Object
,
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
if
stream
,
ok
:=
object
.
(
rest
.
ResourceStreamer
);
ok
{
stream
,
ok
:=
object
.
(
rest
.
ResourceStreamer
)
out
,
flush
,
contentType
,
err
:=
stream
.
InputStream
(
gv
.
String
(),
req
.
Header
.
Get
(
"Accept"
))
if
!
ok
{
if
err
!=
nil
{
writeNegotiated
(
s
,
gv
,
w
,
req
,
statusCode
,
object
)
errorNegotiated
(
err
,
s
,
gv
,
w
,
req
)
return
return
}
}
if
out
==
nil
{
// No output provided - return StatusNoContent
w
.
WriteHeader
(
http
.
StatusNoContent
)
return
}
defer
out
.
Close
()
if
wsstream
.
IsWebSocketRequest
(
req
)
{
r
:=
wsstream
.
NewReader
(
out
,
true
,
wsstream
.
NewDefaultReaderProtocols
())
if
err
:=
r
.
Copy
(
w
,
req
);
err
!=
nil
{
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"error encountered while streaming results via websocket: %v"
,
err
))
}
return
}
if
len
(
contentType
)
==
0
{
out
,
flush
,
contentType
,
err
:=
stream
.
InputStream
(
gv
.
String
(),
req
.
Header
.
Get
(
"Accept"
))
contentType
=
"application/octet-stream"
if
err
!=
nil
{
}
errorNegotiated
(
err
,
s
,
gv
,
w
,
req
)
w
.
Header
()
.
Set
(
"Content-Type"
,
contentType
)
return
w
.
WriteHeader
(
statusCode
)
}
writer
:=
w
.
(
io
.
Writer
)
if
out
==
nil
{
if
flush
{
// No output provided - return StatusNoContent
writer
=
flushwriter
.
Wrap
(
w
)
w
.
WriteHeader
(
http
.
StatusNoContent
)
return
}
defer
out
.
Close
()
if
wsstream
.
IsWebSocketRequest
(
req
)
{
r
:=
wsstream
.
NewReader
(
out
,
true
,
wsstream
.
NewDefaultReaderProtocols
())
if
err
:=
r
.
Copy
(
w
,
req
);
err
!=
nil
{
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"error encountered while streaming results via websocket: %v"
,
err
))
}
}
io
.
Copy
(
writer
,
out
)
return
return
}
}
writeNegotiated
(
s
,
gv
,
w
,
req
,
statusCode
,
object
)
if
len
(
contentType
)
==
0
{
contentType
=
"application/octet-stream"
}
w
.
Header
()
.
Set
(
"Content-Type"
,
contentType
)
w
.
WriteHeader
(
statusCode
)
writer
:=
w
.
(
io
.
Writer
)
if
flush
{
writer
=
flushwriter
.
Wrap
(
w
)
}
io
.
Copy
(
writer
,
out
)
}
}
// writeNegotiated renders an object in the content type negotiated by the client
// writeNegotiated renders an object in the content type negotiated by the client
...
...
pkg/runtime/serializer/codec_factory.go
View file @
f9f680a9
...
@@ -43,18 +43,12 @@ type serializerType struct {
...
@@ -43,18 +43,12 @@ type serializerType struct {
// be expected to pass into or a gvk to Decode, since no type information will be available on
// be expected to pass into or a gvk to Decode, since no type information will be available on
// the object itself.
// the object itself.
RawSerializer
runtime
.
Serializer
RawSerializer
runtime
.
Serializer
// Specialize gives the type the opportunity to return a different serializer implementation if
// the content type contains alternate operations. Here it is used to implement "pretty" as an
// option to application/json, but could also be used to allow serializers to perform type
// defaulting or alter output.
Specialize
func
(
map
[
string
]
string
)
(
runtime
.
Serializer
,
bool
)
AcceptStreamContentTypes
[]
string
AcceptStreamContentTypes
[]
string
StreamContentType
string
StreamContentType
string
Framer
runtime
.
Framer
Framer
runtime
.
Framer
StreamSerializer
runtime
.
Serializer
StreamSerializer
runtime
.
Serializer
StreamSpecialize
func
(
map
[
string
]
string
)
(
runtime
.
Serializer
,
bool
)
}
}
func
newSerializersForScheme
(
scheme
*
runtime
.
Scheme
,
mf
json
.
MetaFactory
)
[]
serializerType
{
func
newSerializersForScheme
(
scheme
*
runtime
.
Scheme
,
mf
json
.
MetaFactory
)
[]
serializerType
{
...
@@ -254,13 +248,6 @@ func (f CodecFactory) SerializerForMediaType(mediaType string, params map[string
...
@@ -254,13 +248,6 @@ func (f CodecFactory) SerializerForMediaType(mediaType string, params map[string
for
_
,
s
:=
range
f
.
serializers
{
for
_
,
s
:=
range
f
.
serializers
{
for
_
,
accepted
:=
range
s
.
AcceptContentTypes
{
for
_
,
accepted
:=
range
s
.
AcceptContentTypes
{
if
accepted
==
mediaType
{
if
accepted
==
mediaType
{
// specialization abstracts variants to the content type
if
s
.
Specialize
!=
nil
&&
len
(
params
)
>
0
{
serializer
,
ok
:=
s
.
Specialize
(
params
)
// TODO: return formatted mediaType+params
return
runtime
.
SerializerInfo
{
Serializer
:
serializer
,
MediaType
:
s
.
ContentType
,
EncodesAsText
:
s
.
EncodesAsText
},
ok
}
// legacy support for ?pretty=1 continues, but this is more formally defined
// legacy support for ?pretty=1 continues, but this is more formally defined
if
v
,
ok
:=
params
[
"pretty"
];
ok
&&
v
==
"1"
&&
s
.
PrettySerializer
!=
nil
{
if
v
,
ok
:=
params
[
"pretty"
];
ok
&&
v
==
"1"
&&
s
.
PrettySerializer
!=
nil
{
return
runtime
.
SerializerInfo
{
Serializer
:
s
.
PrettySerializer
,
MediaType
:
s
.
ContentType
,
EncodesAsText
:
s
.
EncodesAsText
},
true
return
runtime
.
SerializerInfo
{
Serializer
:
s
.
PrettySerializer
,
MediaType
:
s
.
ContentType
,
EncodesAsText
:
s
.
EncodesAsText
},
true
...
@@ -286,20 +273,6 @@ func (f CodecFactory) StreamingSerializerForMediaType(mediaType string, params m
...
@@ -286,20 +273,6 @@ func (f CodecFactory) StreamingSerializerForMediaType(mediaType string, params m
panic
(
"no serializer defined for internal content type"
)
panic
(
"no serializer defined for internal content type"
)
}
}
if
s
.
StreamSpecialize
!=
nil
&&
len
(
params
)
>
0
{
serializer
,
ok
:=
s
.
StreamSpecialize
(
params
)
// TODO: return formatted mediaType+params
return
runtime
.
StreamSerializerInfo
{
SerializerInfo
:
runtime
.
SerializerInfo
{
Serializer
:
serializer
,
MediaType
:
s
.
StreamContentType
,
EncodesAsText
:
s
.
EncodesAsText
,
},
Framer
:
s
.
Framer
,
Embedded
:
nested
,
},
ok
}
return
runtime
.
StreamSerializerInfo
{
return
runtime
.
StreamSerializerInfo
{
SerializerInfo
:
runtime
.
SerializerInfo
{
SerializerInfo
:
runtime
.
SerializerInfo
{
Serializer
:
s
.
StreamSerializer
,
Serializer
:
s
.
StreamSerializer
,
...
...
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