mirror of https://github.com/k3s-io/k3s
Merge pull request #61883 from CaoShuFeng/configz
Automatic merge from submit-queue (batch tested with PRs 63297, 61883). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. set right Content-Type for configz **What this PR does / why we need it**: **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```pull/8/head
commit
b733342f3c
|
@ -19,7 +19,6 @@ package configz
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
@ -74,7 +73,7 @@ func handle(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func write(w io.Writer) error {
|
func write(w http.ResponseWriter) error {
|
||||||
var b []byte
|
var b []byte
|
||||||
var err error
|
var err error
|
||||||
func() {
|
func() {
|
||||||
|
@ -85,6 +84,7 @@ func write(w io.Writer) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error marshaling json: %v", err)
|
return fmt.Errorf("error marshaling json: %v", err)
|
||||||
}
|
}
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
_, err = w.Write(b)
|
_, err = w.Write(b)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ func TestConfigz(t *testing.T) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if string(body) != `{"testing":"blah"}` {
|
if string(body) != `{"testing":"blah"}` {
|
||||||
t.Fatalf("unexpected output: %v", err)
|
t.Fatalf("unexpected output: %s", body)
|
||||||
}
|
}
|
||||||
|
|
||||||
v.Set("bing")
|
v.Set("bing")
|
||||||
|
@ -58,7 +58,7 @@ func TestConfigz(t *testing.T) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if string(body) != `{"testing":"bing"}` {
|
if string(body) != `{"testing":"bing"}` {
|
||||||
t.Fatalf("unexpected output: %v", err)
|
t.Fatalf("unexpected output: %s", body)
|
||||||
}
|
}
|
||||||
|
|
||||||
Delete("testing")
|
Delete("testing")
|
||||||
|
@ -72,6 +72,9 @@ func TestConfigz(t *testing.T) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if string(body) != `{}` {
|
if string(body) != `{}` {
|
||||||
t.Fatalf("unexpected output: %v", err)
|
t.Fatalf("unexpected output: %s", body)
|
||||||
|
}
|
||||||
|
if resp.Header.Get("Content-Type") != "application/json" {
|
||||||
|
t.Fatalf("unexpected Content-Type: %s", resp.Header.Get("Content-Type"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue