MCPcopy
hub / github.com/caddyserver/caddy / WriteHeader

Method WriteHeader

modules/caddyhttp/responsewriter.go:148–173  ·  view source on GitHub ↗

WriteHeader writes the headers with statusCode to the wrapped ResponseWriter unless the response is to be buffered instead. 1xx responses are never buffered.

(statusCode int)

Source from the content-addressed store, hash-verified

146// ResponseWriter unless the response is to be buffered instead.
147// 1xx responses are never buffered.
148func (rr *responseRecorder) WriteHeader(statusCode int) {
149 if rr.wroteHeader {
150 return
151 }
152
153 // save statusCode always, in case HTTP middleware upgrades websocket
154 // connections by manually setting headers and writing status 101
155 rr.statusCode = statusCode
156
157 // decide whether we should buffer the response
158 if rr.shouldBuffer == nil {
159 rr.stream = true
160 } else {
161 rr.stream = !rr.shouldBuffer(rr.statusCode, rr.ResponseWriterWrapper.Header())
162 }
163
164 // 1xx responses aren't final; just informational
165 if statusCode < 100 || statusCode > 199 {
166 rr.wroteHeader = true
167 }
168
169 // if informational or not buffered, immediately write header
170 if rr.stream || (100 <= statusCode && statusCode <= 199) {
171 rr.ResponseWriterWrapper.WriteHeader(statusCode)
172 }
173}
174
175func (rr *responseRecorder) Write(data []byte) (int, error) {
176 rr.WriteHeader(http.StatusOK)

Callers 3

WriteMethod · 0.95
ReadFromMethod · 0.95
WriteResponseMethod · 0.95

Calls 1

HeaderMethod · 0.45

Tested by

no test coverage detected