Skip to content

Commit a825581

Browse files
committed
mockkubeapiserver: Always send content-length
This allows for more predictable output, as otherwise the length is only sometimes sent (maybe varying by go version)
1 parent d4569f8 commit a825581

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mockkubeapiserver/request.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"encoding/json"
2222
"fmt"
2323
"net/http"
24+
"strconv"
2425

2526
"k8s.io/klog/v2"
2627
)
@@ -48,6 +49,9 @@ func (r *baseRequest) writeResponse(obj interface{}) error {
4849
}
4950
r.w.Header().Add("Content-Type", "application/json")
5051
r.w.Header().Add("Cache-Control", "no-cache, private")
52+
r.w.Header().Add("Content-Length", strconv.Itoa(len(b)))
53+
54+
r.w.WriteHeader(http.StatusOK)
5155

5256
if _, err := r.w.Write(b); err != nil {
5357
// Too late to send error response

0 commit comments

Comments
 (0)