MCPcopy
hub / github.com/pallets/werkzeug / close

Method close

src/werkzeug/middleware/lint.py:166–213  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

164 return rv
165
166 def close(self) -> None:
167 self.closed = True
168
169 if hasattr(self._iterator, "close"):
170 self._iterator.close()
171
172 if self.headers_set:
173 status_code, headers = self.headers_set
174 bytes_sent = sum(self.chunks)
175 content_length = headers.get("content-length", type=int)
176
177 if status_code == 304:
178 for key, _value in headers:
179 key = key.lower()
180 if key not in ("expires", "content-location") and is_entity_header(
181 key
182 ):
183 warn(
184 f"Entity header {key!r} found in 304 response.",
185 HTTPWarning,
186 stacklevel=2,
187 )
188 if bytes_sent:
189 warn(
190 "304 responses must not have a body.",
191 HTTPWarning,
192 stacklevel=2,
193 )
194 elif 100 <= status_code < 200 or status_code == 204:
195 if content_length != 0:
196 warn(
197 f"{status_code} responses must have an empty content length.",
198 HTTPWarning,
199 stacklevel=2,
200 )
201 if bytes_sent:
202 warn(
203 f"{status_code} responses must not have a body.",
204 HTTPWarning,
205 stacklevel=2,
206 )
207 elif content_length is not None and content_length != bytes_sent:
208 warn(
209 "Content-Length and the number of bytes sent to the"
210 " client do not match.",
211 WSGIWarning,
212 stacklevel=2,
213 )
214
215 def __del__(self) -> None:
216 if not self.closed:

Callers

nothing calls this directly

Calls 3

is_entity_headerFunction · 0.85
closeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected