MCPcopy Index your code
hub / github.com/php/frankenphp / writeHeader

Method writeHeader

recorder_test.go:89–109  ·  view source on GitHub ↗

writeHeader writes a header if it was not written yet and detects Content-Type if needed. bytes or str are the beginning of the response body. We pass both to avoid unnecessarily generate garbage in rw.WriteString which was created for performance reasons. Non-nil bytes win.

(b []byte, str string)

Source from the content-addressed store, hash-verified

87// in rw.WriteString which was created for performance reasons.
88// Non-nil bytes win.
89func (rw *ResponseRecorder) writeHeader(b []byte, str string) {
90 if rw.wroteHeader {
91 return
92 }
93 if len(str) > 512 {
94 str = str[:512]
95 }
96
97 m := rw.Header()
98
99 _, hasType := m["Content-Type"]
100 hasTE := m.Get("Transfer-Encoding") != ""
101 if !hasType && !hasTE {
102 if b == nil {
103 b = []byte(str)
104 }
105 m.Set("Content-Type", http.DetectContentType(b))
106 }
107
108 rw.WriteHeader(200)
109}
110
111// Write implements http.ResponseWriter. The data in buf is written to
112// rw.Body, if not nil.

Callers 2

WriteMethod · 0.95
WriteStringMethod · 0.95

Calls 4

HeaderMethod · 0.95
WriteHeaderMethod · 0.95
GetMethod · 0.80
SetMethod · 0.80

Tested by

no test coverage detected