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
b1b255f9
Commit
b1b255f9
authored
Dec 11, 2014
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent infinite loop in apiserver errorJSON
parent
7d2a64b2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
4 deletions
+17
-4
apiserver.go
pkg/apiserver/apiserver.go
+17
-4
No files found.
pkg/apiserver/apiserver.go
View file @
b1b255f9
...
...
@@ -19,6 +19,7 @@ package apiserver
import
(
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"path"
...
...
@@ -283,16 +284,14 @@ func APIVersionHandler(versions ...string) restful.RouteFunction {
func
writeJSON
(
statusCode
int
,
codec
runtime
.
Codec
,
object
runtime
.
Object
,
w
http
.
ResponseWriter
)
{
output
,
err
:=
codec
.
Encode
(
object
)
if
err
!=
nil
{
// Note: If codec is broken, this results in an infinite recursion
errorJSON
(
err
,
codec
,
w
)
errorJSONFatal
(
err
,
codec
,
w
)
return
}
// PR #2243: Pretty-print JSON by default.
formatted
:=
&
bytes
.
Buffer
{}
err
=
json
.
Indent
(
formatted
,
output
,
""
,
" "
)
if
err
!=
nil
{
// Note: If codec is broken, this results in an infinite recursion
errorJSON
(
err
,
codec
,
w
)
errorJSONFatal
(
err
,
codec
,
w
)
return
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
...
...
@@ -306,6 +305,20 @@ func errorJSON(err error, codec runtime.Codec, w http.ResponseWriter) {
writeJSON
(
status
.
Code
,
codec
,
status
,
w
)
}
// errorJSONFatal renders an error to the response, and if codec fails will render plaintext
func
errorJSONFatal
(
err
error
,
codec
runtime
.
Codec
,
w
http
.
ResponseWriter
)
{
status
:=
errToAPIStatus
(
err
)
output
,
err
:=
codec
.
Encode
(
status
)
if
err
!=
nil
{
w
.
WriteHeader
(
status
.
Code
)
fmt
.
Fprintf
(
w
,
"%s: %s"
,
status
.
Reason
,
status
.
Message
)
return
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
w
.
WriteHeader
(
status
.
Code
)
w
.
Write
(
output
)
}
// writeRawJSON writes a non-API object in JSON.
func
writeRawJSON
(
statusCode
int
,
object
interface
{},
w
http
.
ResponseWriter
)
{
// PR #2243: Pretty-print JSON by default.
...
...
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